ClickHouse Cloud users are recommended to use ClickPipes for PostgreSQL replication to ClickHouse. This natively supports high-performance Change Data Capture (CDC) for PostgreSQL.
This table engine is experimental. To use it, set
allow_experimental_materialized_postgresql_table to 1 in your configuration files or by using the SET command:materialized_postgresql_tables_list setting, which specifies the tables to be replicated (will also be possible to add database schema). It will be much better in terms of CPU, fewer connections and fewer replication slots inside the remote PostgreSQL database.
Creating a table
host:port— PostgreSQL server address.database— Remote database name.table— Remote table name.user— PostgreSQL user.password— User password.
TLS/SSL
TLS/SSL parameters are forwarded tolibpq and can be supplied through a named collection or as trailing key-value arguments of the engine: sslmode (disable, allow, prefer, require, verify-ca or verify-full; when unset, the libpq default of prefer applies), and the certificates and the key in one of two forms. sslrootcert (CA certificate), sslcert (client certificate) and sslkey (client private key) are paths to server-local files, accepted only from a named collection defined in the server configuration file. sslrootcert_pem, sslcert_pem and sslkey_pem accept the literal contents of the corresponding file instead, can be specified from SQL, and are masked in logs and SHOW queries like a password.
Requirements
-
The wal_level setting must have a value
logicalandmax_replication_slotsparameter must have a value at least2in the PostgreSQL config file. -
A table with
MaterializedPostgreSQLengine must have a primary key — the same as a replica identity index (by default: primary key) of a PostgreSQL table (see details on replica identity index). - Only database Atomic is allowed.
-
The
MaterializedPostgreSQLtable engine only works for PostgreSQL versions >= 11 as the implementation requires the pg_replication_slot_advance PostgreSQL function.
Virtual columns
-
_version— Transaction counter. Type: UInt64. -
_sign— Deletion mark. Type: Int8. Possible values:1— Row is not deleted,-1— Row is deleted.
SELECT query.
_version column equals LSN position in WAL, so it might be used to check how up-to-date replication is.
Replication of TOAST values is not supported. The default value for the data type will be used.