Skip to content

Sources

Postgres

The postgres source: connection settings, choosing tables, how each table is read, TLS modes and SSH tunnels.

A Postgres source loads the tables of one database that match its include patterns, one table each, read with binary COPY into Arrow. To set one up and keep it up to date, see Load Postgres tables.

[connections.app]
kind = "postgres"
host = "db.example.com"
port = 5432
user = "loader"
password = "${ENV:APP_DB_PASSWORD}"
database = "shop"
[sources.app]
kind = "postgres"
connection = "app"
description = "The shop's application database."
include = ["public.*"]
exclude = ["public.audit_*"]
write_strategy = "merge"
unique_key = "{primary_key}"
[sources.app.tables."public.orders"]
description = "Orders, one row per order."
cursor_column = "updated_at"

A postgres connection takes host, port, user, password and database, the TLS settings, and an ssh table for an SSH tunnel. Every key and its default is in sqlload.toml. Postgres targets use the same connection.

include and exclude are schema.table patterns, such as public.*. new_tables, column settings and masks are under Choosing tables and Choosing columns.

where is a condition in Postgres SQL, such as where = "tenant_id = 42 AND status <> 'void'". See Filtering rows.

  • A table whose cursor_column (not a text one) leads an index commits along the way, in cursor order; see Batches.
  • The windows of a batch_size are read in one REPEATABLE READ snapshot, held open for the whole table load. It counts towards idle_in_transaction_session_timeout, and vacuum can’t remove rows it can still see. Use a larger batch_size or a narrower range if either matters.
  • numeric without a precision needs a pinned type, such as columns = { amount = "decimal(38,10)" }, and arrays load as JSON. See Postgres source types.

A Postgres connection takes libpq’s TLS settings, for postgres and postgres_cdc sources and Postgres targets alike. To set them up, see Connect over TLS.

sslmode Encrypts Checks the certificate
disable Never No
prefer (default) When the server offers it No
require Always No, unless sslrootcert is set: then as verify-ca
verify-ca Always Signed by a trusted CA
verify-full Always Signed by a trusted CA, for the host connected to

require and the verify-* modes refuse a server without TLS. prefer falls back to plain text when the server refuses TLS or the handshake fails, and a Unix socket host never uses TLS. Only verify-full, or verify-ca on a private network, keeps out a man in the middle.

sslrootcert names CA certificates (PEM) to trust. sslcert and sslkey give a client certificate and its private key; set both or neither. Where SQLLoad differs from libpq:

  • Without sslrootcert, the verify-* modes trust the public CA roots built into SQLLoad, not the operating system’s store or ~/.postgresql/root.crt. A private CA, such as Amazon RDS and Aurora’s or a company’s, needs sslrootcert: for RDS, the region’s certificate bundle from AWS.
  • verify-full matches the host only against the certificate’s subject alternative names, never its common name.
  • A self-signed server certificate marked as a CA, as openssl req -x509 makes by default, can’t be its own sslrootcert. Sign the server certificate with a separate CA and give that CA.
  • Certificate paths are relative to the directory SQLLoad runs in, not to sqlload.toml.

On Windows, a postgres_cdc source’s replication rows cross the loopback interface in plain text on their way to SQLLoad’s TLS relay, readable by an administrator who captures loopback traffic.

A connection with an ssh table reaches the database through a bastion host, and host and port are the database as the bastion sees it. To set one up, see Connect through an SSH tunnel.

  • SQLLoad opens the tunnel itself, with no ssh program needed: one session to the bastion per run, shared by every table.
  • It signs in with private_key_file when set (and private_key_passphrase if the key has one), else with password when set, else with the keys ssh-agent holds; it doesn’t fall back. On Windows, ssh-agent is the pipe SSH_AUTH_SOCK names, or the OpenSSH agent service’s (\\.\pipe\openssh-ssh-agent); tunnels on Windows aren’t covered by an end-to-end test.
  • The bastion’s host key must be in known_hosts (~/.ssh/known_hosts by default). An unknown or changed key fails with its SHA256 fingerprint and the fix; a key is never accepted on first use.
  • TLS still runs end to end with the database, so verify-full checks the database’s own name.
  • Keepalives every 15 seconds hold idle tunnels open through long reads and load --follow. When the tunnel drops, the table fails with an error that names the tunnel; a postgres_cdc source resumes from its slot on the next run.
  • A Python source that names the connection gets its settings but no tunnel. Copy URIs, jump chains and ~/.ssh/config aren’t supported.