Skip to content

Connect SPSync to PostgreSQL

This guide covers PostgreSQL you run yourself and the cloud-provided databases built on it: Azure Database for PostgreSQL, Supabase, Neon, Amazon RDS and Aurora, Google Cloud SQL and AlloyDB, and Heroku Postgres. SPSync uses one destination kind, postgres, for all of them. Only the host, the firewall and the TLS settings differ.

  • A PostgreSQL server you can reach. SPSync uses the standard Postgres driver, which needs nothing extra on the machine that runs SPSync.
  • Superuser access, or an admin role on the cloud service, to create a role and a database.

Create the database and a least-privilege user

Section titled “Create the database and a least-privilege user”

The script is from the PostgreSQL documentation and has not been run here against a test server. Run it as a superuser or admin role.

CREATE ROLE spsync_loader LOGIN PASSWORD 'use-a-long-random-password';
CREATE DATABASE spsync OWNER spsync_loader;

spsync_loader owns the database, so it can create the schema SPSync loads into (the dataset_name, for example sync) and the staging schema SPSync uses while it merges a round. If you cannot hand over ownership of a whole database, create the schemas yourself and grant only those. This block is from vendor docs, not run here:

CREATE SCHEMA sync AUTHORIZATION spsync_loader;
CREATE SCHEMA sync_staging AUTHORIZATION spsync_loader;
GRANT CONNECT ON DATABASE spsync TO spsync_loader;

Reporting views are optional. They need CREATE on the schema, which owning it already gives the role. SPSync drops and recreates the views each round.

Postgres listens on TCP 5432 unless the service says otherwise. On the desktop app and a self-hosted server the connection starts from that machine, so allow that machine’s address. For the Azure managed application, allow the address it connects out from, or put the database on the same virtual network, instead of opening it to the internet.

  • Self-hosted: allow the SPSync address in pg_hba.conf with hostssl, and in the host firewall.
  • Azure Database for PostgreSQL (Flexible Server): in the server’s Networking page, add a firewall rule for the address, or use a private endpoint or virtual network access and run SPSync inside it.
  • Amazon RDS and Aurora: add an inbound rule for port 5432 to the instance’s security group, with the source written as /32. For Aurora, use the cluster (writer) endpoint.
  • Google Cloud SQL: under Connections, add the address as an authorized network.
  • Google AlloyDB: connect through the AlloyDB Auth Proxy, or from inside the peered VPC.
  • Supabase: under Settings, Database, Network restrictions, allow the address if restrictions are on. See the Supabase section below for which host to use.
  • Neon: under Settings, IP Allow, add the address if the allow-list is on.
  • Heroku Postgres: there is no firewall rule to add on the standard plans. Use heroku pg:credentials:create to make a dedicated credential for SPSync instead of sharing the default one.

Use sslmode=verify-full with sslrootcert=/path/to/ca.pem for the provider’s CA, or sslrootcert=system when the host already trusts the issuing root. That encrypts the connection and checks the server’s identity. sslmode=require encrypts without checking, so an impostor server would not be noticed; it still works, and spsync doctor says so in its connection check.

A private CA or a client certificate. The sslrootcert path in the string works where the machine has that file, but the Azure edition has no way to upload one. The alternative is to paste the certificate. On the Destination screen, paste the PEM into CA certificate bundle, and for a client certificate paste Client certificate and Client private key (an unencrypted PEM key). SPSync then connects with sslmode=verify-full. SPSync keeps the PEM as a stored secret: in the operating system keychain on the desktop app, as a Key Vault reference in the Azure edition, and it never shows it again after you save. At run time SPSync writes it to an owner-only temporary file because the database driver needs a path, and removes the file when the run ends. Leave sslmode, sslrootcert, sslcert and sslkey out of the string when you use these fields: SPSync refuses a string that sets them as well, rather than guessing which wins. verify-full also checks the host name, so connect by a name the certificate carries. With no CA pasted, SPSync checks the server against the operating system’s trusted roots (sslrootcert=system). The fields also work with the token authentication modes (Entra, AWS IAM, Google Cloud IAM); a client certificate pasted here cannot be combined with the client_certificate authentication mode, which sets its own, so use one or the other.

Clearing Verify the server certificate turns checking off. The connection stays encrypted but SPSync no longer checks who it is talking to. Use it only while you fix the certificate. SPSync logs a destination_tls_verification_disabled warning on every run, Test connection reports “connected (warning: …)” and spsync doctor prints a WARNING. With checking off SPSync uses sslmode=require.

This is a preview. SPSync’s automated tests run a real PostgreSQL 16 container, serving a certificate from a throw-away CA, and check that the connection succeeds with the CA and fails without it. It has not been run against a managed PostgreSQL service. spsync doctor prints a destination-tls line with the trust mode.

Where the host needs its own CA:

  • Azure Database for PostgreSQL requires TLS and presents a certificate that chains to a public root, so sslmode=verify-full&sslrootcert=system works with no CA file.
  • Amazon RDS and Aurora allow plain connections unless you require TLS. Set sslmode=verify-full and point sslrootcert at the regional RDS CA bundle.
  • Google Cloud SQL needs either the Cloud SQL Auth Proxy (connect to 127.0.0.1:5432 with no sslmode, because the proxy handles TLS) or a direct connection with sslmode=verify-ca and the client certificate files from the instance’s Connections page.
  • AlloyDB through the Auth Proxy also connects to 127.0.0.1:5432 with no sslmode.
  • Heroku Postgres requires TLS and documents sslmode=require. SPSync has not checked verify-full against it.
  • Supabase and Neon: use verify-full. Supabase publishes a project CA in Settings, Database; Neon’s certificate chains to a public root.

If the database is reachable only through a jump host, SPSync can open an SSH tunnel to that host for each run, forward a local port to the database, and close the tunnel when the run ends. This is a preview: it is tested against a real SSH server in the SPSync test suite, but it has not been run against a live PostgreSQL service behind a customer’s jump host. Supabase, Neon and other managed databases that you reach directly do not need it.

  1. On a machine you trust, read the jump host’s host key fingerprint. This prints a line containing SHA256: followed by 43 characters:

    Terminal window
    ssh-keyscan -t ed25519 bastion.example.com | ssh-keygen -lf -

    SPSync asks the server for an ed25519 host key first, then ECDSA, then RSA, so pin the fingerprint of the first of those the server has. If you are unsure, run ssh-keyscan without -t and pin every fingerprint it prints.

  2. In the connection string, give the database’s address as the jump host sees it, for example db.internal:5432. SPSync rewrites the address to the local port while the tunnel is open; the string you save is not changed.

  3. On the Destination screen, tick Reach the database through an SSH bastion and fill in the host, port, user and fingerprint, then paste a private key (and its passphrase) or enter a password. The key is kept in the computer’s keychain and is not shown again.

  4. In the CLI, add an ssh_tunnel block to the destination in the config file, as below. export-config does not write it. With the admin MCP server, the assistant can set the host, port, user and fingerprint, and you enter the key or password on the secure entry page.

destination:
kind: postgres
connection_string_env: SPSYNC_DSN
ssh_tunnel:
host: bastion.example.com
port: 22 # optional, 22 by default
user: spsync
host_key_fingerprints:
- "SHA256:<the fingerprint from step 1>"
private_key_env: keychain:spsync/bastion-key # or file:/path/to/key, or an environment variable name
# passphrase_env: BASTION_KEY_PASSPHRASE # only if the key has one
# password_env: BASTION_PASSWORD # instead of private_key_env

The host key is always checked. If the jump host presents a key that is not in host_key_fingerprints, SPSync stops before it sends any credential, and there is no setting that turns the check off. Keep a second fingerprint in the list while you rotate the host key. SPSync ignores ~/.ssh/config, known_hosts and any SSH agent: it uses exactly what is configured here. The key, its passphrase and the password are never written to the config file or to the control store; they are stored as keychain or Key Vault references, and a plain environment variable name works for the CLI.

Test connection and spsync doctor open the same tunnel as a run and say so in their result: connected through SSH tunnel, then the user, host and port, and host key pinned. The read-only MCP server (spsync mcp serve) opens its own connection to the replica and does not go through the tunnel.

PostgreSQL keeps its certificate check: SPSync gives libpq the loopback address as hostaddr and leaves db.internal as the host, so sslmode=verify-full still checks the certificate against db.internal. Do not set hostaddr yourself.

Which modes work depends on where the database runs. The user name in the connection string is always the database user: the Entra principal, the IAM database user or, for a client certificate, the name on the certificate.

Where the database runs Sign-in options
Self-hosted PostgreSQL Password, or a TLS client certificate
Azure Database for PostgreSQL (Flexible Server) Password, or (preview, not verified live) Microsoft Entra ID: a managed identity, DefaultAzureCredential, or a service principal with a certificate (a client secret also works, as a fallback)
Amazon RDS and Aurora PostgreSQL Password, or (preview, not verified live) IAM database authentication
Google Cloud SQL and AlloyDB Password, a client certificate, or (preview, not verified live) IAM database authentication on a direct connection
Supabase, Neon and Heroku Postgres Password with encrypted, verified TLS. These services offer no IAM sign-in

With Entra, IAM or Google sign-in SPSync asks for a fresh token each time it opens a connection, so no long-lived secret sits on the sync host. These modes have not been run end to end against a live Azure, RDS or Google server. SPSync does not offer the signed-in desktop user for PostgreSQL.

In the CLI configuration, add an auth block next to the destination:

destination:
kind: postgres
connection_string_env: SPSYNC_DSN
dataset_name: sync
auth:
mode: entra_managed_identity # or aws_iam, gcp_iam, client_certificate, ...

Leave the password out of the connection string when you use a token mode. Token modes refuse every sslmode except verify-full and verify-ca (a token must never go to a server that is not verified), and a missing sslmode becomes verify-full using the host’s trusted roots. On the Destination screen, pick the mode under Authentication and give its settings as JSON, for example {"region": "eu-west-1"} for AWS.

spsync postgres-grants prints the SQL, and runs nothing. Give it the role, database and schema, and one of password, azure_entra, aws_iam, gcp_iam or client_certificate. For example:

Terminal window
spsync postgres-grants --auth-mode aws_iam --role spsync_loader --database spsync --schema sync

The script creates the role the way that option needs (pgaadauth_create_principal on Azure, GRANT rds_iam on RDS, a gcloud step on Google Cloud, a pg_hba.conf line for certificates), then grants CONNECT and CREATE on the database and ownership of the sync and sync_staging schemas. It grants no superuser, role-creation or other-schema rights. A run of the password variant under exactly those grants passes in SPSync’s tests; the Azure, AWS and Google role-creation lines are from vendor documentation and have not been run here.

HOST is your server’s name.

postgresql://spsync_loader:PASSWORD@HOST:5432/spsync?sslmode=verify-full&sslrootcert=system
  • Desktop app: open the Destination screen, choose Postgres / Supabase, paste the string into Connection string and choose Test connection.

  • CLI:

    Terminal window
    export SPSYNC_DSN='postgresql://spsync_loader:PASSWORD@HOST:5432/spsync?sslmode=verify-full&sslrootcert=system'
    spsync export-config --output replication.yaml \
    --site-url https://contoso.sharepoint.com/sites/x --list Projects \
    --pipeline-name spsync_dev --prefix dev \
    --destination-kind postgres --connection-string-env SPSYNC_DSN --dataset-name sync \
    --client-id <entra-app-client-id>
  • AI assistant: with the admin MCP server connected, ask for the destination requirements, then let the assistant create the destination. You enter the string on the secure entry page.

Supabase offers three endpoints for the same database: the direct connection, the session pooler and the transaction pooler. The direct connection is IPv6-only unless you buy the IPv4 add-on. The transaction pooler works over IPv4 on every plan and is what the Supabase connection string in Project Settings, Database gives you. SPSync always sets sslmode=require when it builds a Supabase string, but Supabase does not force TLS on its side until you turn on “Enforce SSL on incoming connections”. Switch that on.

No one has run the transaction pooler end to end with SPSync, so it is untested. If a sync fails there, try the session pooler or the direct connection.

Neon suspends idle compute. The first connection after a pause can take a few seconds, so use a connection timeout of ten seconds or more. Paste the connection string from the Neon dashboard as it is; for the pooled string it already carries what the pooler needs.

Heroku gives you a DATABASE_URL that starts postgres://. SPSync accepts that scheme. Add ?sslmode=require. Small plans cap the number of connections low, so a sync alongside your application can hit the limit; use a pooler or a larger plan.

Nothing beyond the firewall and TLS notes above. Use the writer endpoint on Aurora.

Both open a connection and run SELECT 1. A pass means the host is reachable, the firewall and TLS are right and the credential is accepted. spsync doctor also names the sign-in mode and the database user the connection ran as. It does not prove the role can create schemas or tables. spsync doctor reports the same probe as destination-connectivity.

What you see What it means and the fix
connection refused or timeout expired A firewall, security group or allow-list is blocking port 5432, or the host is wrong.
no pg_hba.conf entry for host ... SSL off The server demands TLS. Add sslmode=require.
Authentication failed: password is incorrect for user <user> (spsync doctor), or password authentication failed for user (raw libpq text) The password is wrong. Check the password in the connection string environment variable and run spsync doctor again. On a pooler the user name needs the project suffix the host’s page shows.
permission denied for database or permission denied to create schema The role cannot create schemas. Use the owner setup above, or create sync and sync_staging yourself.
SSL error: certificate verify failed With verify-full, the CA is missing or the host name does not match. Paste the CA into CA certificate bundle, or connect by a name the certificate carries.
the connection string sets sslmode You gave SPSync a CA or client certificate and the string also sets sslmode, sslrootcert, sslcert or sslkey. Remove them from the string.
could not acquire a credential for auth mode ... SPSync could not get a token. The message carries the identity provider’s own code, for example AADSTS700016. Check the identity or role the sync host runs as.
password authentication failed with a token mode The database user is not set up for that sign-in: no pgaadauth_create_principal role on Azure, no rds_iam grant on RDS, or the IAM user is missing on Google Cloud. Run the matching spsync postgres-grants script.
connection requires a valid client certificate The server wants a client certificate. Use client_certificate and check the key file is readable only by the sync user.

| remaining connection slots are reserved | The service’s connection cap is full. Close other clients, or use a pooler. |