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 = 5432user = "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"Connection
Section titled “Connection”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.
Choosing tables
Section titled “Choosing tables”include and exclude are schema.table patterns, such as public.*. new_tables, column
settings and masks are under Choosing tables and
Choosing columns.
Filtering rows
Section titled “Filtering rows”where is a condition in Postgres SQL, such as where = "tenant_id = 42 AND status <> 'void'".
See Filtering rows.
How Postgres is read
Section titled “How Postgres is read”- 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_sizeare read in oneREPEATABLE READsnapshot, held open for the whole table load. It counts towardsidle_in_transaction_session_timeout, and vacuum can’t remove rows it can still see. Use a largerbatch_sizeor a narrower range if either matters. numericwithout a precision needs a pinned type, such ascolumns = { 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, theverify-*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, needssslrootcert: for RDS, the region’s certificate bundle from AWS. verify-fullmatches 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 -x509makes by default, can’t be its ownsslrootcert. 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.
SSH tunnels
Section titled “SSH tunnels”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
sshprogram needed: one session to the bastion per run, shared by every table. - It signs in with
private_key_filewhen set (andprivate_key_passphraseif the key has one), else withpasswordwhen set, else with the keys ssh-agent holds; it doesn’t fall back. On Windows, ssh-agent is the pipeSSH_AUTH_SOCKnames, 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_hostsby 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-fullchecks 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; apostgres_cdcsource 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/configaren’t supported.