Skip to main content

PostgreSQL CDC with SQL Mapping

Use a streaming INSERT INTO ... SELECT ... FROM cdc_stream(...) to map a single PostgreSQL table to an existing VeloDB Cloud table. The job commits its progress with the warehouse insert to provide exactly-once processing. Use automatic table creation to replicate multiple tables or propagate supported schema changes.

SQL continuous load is experimental. Check Continuous Load Overview for warehouse availability.

Prerequisites​

  • Use a warehouse with PostgreSQL streaming jobs enabled. Core 26.1.1 introduced the cdc_stream function. The example uses the delete-marker fix in Core 26.1.2 or later. For version details, see the Core 26.1 release notes.
  • Enable logical replication on the PostgreSQL source. The source table needs a primary key and a publication that includes it. Grant the source user read access and replication privileges. See the Amazon RDS or Amazon Aurora setup guide for AWS-managed sources.
  • Check network access from the executing warehouse cluster to the PostgreSQL endpoint and driver location. For private sources, see SaaS private connectivity or BYOC connectivity.
  • Use a warehouse SQL user with LOAD_PRIV on the target. The example assumes the target table already exists in analytics and uses a merge-on-write Unique Key on id, corresponding to the source primary key.

Create a streaming job​

In the warehouse SQL Editor or a connected SQL client, select the database that will own the job. This example maps public.orders(id, status) in PostgreSQL to analytics.orders(id, order_status) in VeloDB Cloud. It copies existing rows, then applies new inserts, updates, and deletes. Replace the host, driver package, database and table names, publication, and credentials with your own values.

USE analytics;

CREATE JOB replicate_order_status
ON STREAMING DO
INSERT INTO analytics.orders (id, order_status, __DORIS_DELETE_SIGN__)
SELECT id, status, __DORIS_DELETE_SIGN__
FROM cdc_stream(
"type" = "postgres",
"jdbc_url" = "jdbc:postgresql://<source-host>:5432/sales",
"driver_url" = "<approved-postgresql-driver>.jar",
"driver_class" = "org.postgresql.Driver",
"user" = "<sync-user>",
"password" = "<sync-password>",
"database" = "sales",
"schema" = "public",
"table" = "orders",
"publication_name" = "warehouse_orders",
"ssl_mode" = "require",
"include_delete_sign" = "true",
"offset" = "initial"
);

To propagate source deletes, enable include_delete_sign and include the hidden __DORIS_DELETE_SIGN__ column in both the select list and the target column list. Preserve the source key in the mapping. If you filter rows, check how an update that changes the filter result should affect rows already present in the target.

Check the job​

SELECT Name, Status, ErrorMsg
FROM jobs("type" = "insert") WHERE Name = 'replicate_order_status';

SELECT *
FROM tasks("type" = "insert") WHERE JobName = 'replicate_order_status';

Compare a known source key with analytics.orders after its task succeeds. When verifying deletes, check that the key disappears after the corresponding source delete is processed.

Parameters​

ParameterHow to use it
type, database, schema, tableSet type to postgres and identify one source table.
jdbc_url, user, passwordSupply the reachable PostgreSQL endpoint and sync user's credentials.
driver_url, driver_classUse a package available to your warehouse or an approved HTTPS URL. Use the class org.postgresql.Driver. See JDBC driver requirements.
publication_name, slot_nameSpecify existing resources or allow the job to manage them. Each job needs its own replication slot.
ssl_mode, ssl_rootcertUse require for encryption, or verify-ca with a CA certificate registered in the job database under the streaming_job file catalog, referenced as FILE:<file_name>.
offsetRequired. latest starts with new changes. initial copies existing rows and then streams changes. snapshot copies existing rows once.
snapshot_split_size, snapshot_parallelismControl rows per snapshot split and concurrent splits per task. The SQL mapping path defaults to one concurrent split.
include_delete_signSet to true to expose the delete marker in the function result.
session.*Set supported session variables in the job's PROPERTIES clause. See INSERT INTO SELECT.

Troubleshooting​

If the source schema changes, check the PostgreSQL type mapping, the target schema, and the SQL projection. SQL mapping jobs do not apply source DDL. If source rows are deleted but still appear in the target, verify the warehouse Core version, the target key, and the delete marker in both SQL column lists.

See Continuous Load for job operations and CDC Stream for the table function reference.

Ask AI