Postgres External Source
Prerequisites
Section titled “Prerequisites”A role with the following attributes and privileges:
- The
LOGINattribute. Allows opening a session in Postgres. - The
REPLICATIONattribute. Allows opening a replication-mode connection to Postgres. - The
CONNECTprivilege on the database being connected to. Allows opening a connection to Postgres. - The
USAGEprivilege on all schemas of tables in the publication. Used during snapshotting. - The
SELECTprivilege on all tables in the publication. Used during snapshotting.
A publication enumerating the tables to sync to XTDB, it’s table set is the only filter on what gets synced.
Configuration
Section titled “Configuration”Configured by attaching a secondary database with the additional externalSource options.
It reads from a Postgres publication via a !Postgres remote, and writes through an indexer:
ATTACH DATABASE my_db WITH $$externalSource: !Postgres # The alias of the !Postgres remote holding the connection details. remote: my_pg_remote
# The Postgres publication to replicate from. publicationName: my_db_to_xtdb
# The replication slot XTDB creates. slotName: my_db_to_xtdb
# The indexer used to index Postgres transactions. indexer: !DirectMirror {}$$Remote
Section titled “Remote”Postgres connection details are stored in a !Postgres remote:
remotes: my_pg_remote: !Postgres # The hostname of the Postgres to connect to. hostname: my.pg.host
# The port of the Postgres to connect to. Defaults to 5432. port: 5433
# The Postgres database to connect to. database: my_upstream_db
# The username of the role to authenticate with Postgres. username: my_role
# The password for the role connecting to Postgres. password: !ENV PG_PASSWORDPhases
Section titled “Phases”This external source works in two phases:
- snapshot
- The initial mode of a Postgres External Source. Scans all rows for tables in the publication into XTDB.
- streaming
- Translates transactions from Postgres into XTDB transactions.
System Time
Section titled “System Time”The system time of rows depends on the phase of the Postgres External Source.
| Phase | System Time |
|---|---|
| Snapshot | XTDB’s internal system time (i.e. it is unrelated to the upstream Postgres’ system clock) |
| Streaming | The timestamp of the Postgres transaction (the timestamp on the commit message) |
Indexers
Section titled “Indexers”The following indexers are built into XTDB:
- DirectMirror
DirectMirror
Section titled “DirectMirror”Mirrors tables & transactions from Postgres directly into XTDB.
Additional properties are required from the tables replicated using this indexer:
_idis a required column, used as the primary key for the row- If set, the
_valid_fromand_valid_tocolumns must be of typeTIMESTAMPTZ- Like in XTDB, it is incorrect to specify a
_valid_towithout a_valid_from
- Like in XTDB, it is incorrect to specify a
No configuration properties are provided.