S3 and GCS as destinations are deprecated and no longer actively maintained. They remain fully functional and no code is currently being removed. For new mirrors, we recommend ClickHouse, ClickHouse Cloud, or Postgres as the destination.
PeerDB support Change-Data-Capture (CDC) from PostgreSQL to S3 and GCS buckets in the form of AVRO files in the destination.
We utilise the interoperability between GCS and S3 here.
Suppose you have a banking application running on PostgreSQL. There are two tables: “users” and “transactions.” You want to sync these tables in real-time to AVRO files in your S3 or GCS buckets which other services or clients can pick up.
For the same user, create and attach a policy as below using JSON editor. Sharing AWS docs for reference. PeerDB requires s3:ListAllMyBuckets, s3:GetObject, s3:PutObject, s3:ListBucket and s3:DeleteObject on that bucket.
To facilitate real-time Change Data Capture (CDC) from PostgreSQL to S3 or GCS, set up your peers and then create a mirror using the following SQL syntax:
CREATE MIRROR IF NOT EXISTS <mirror-name>FROM <postgres-peer-name> TO <storage-peer-name>WITH TABLE MAPPING( <source-schema>.<table>:<destination_name>, ... -- Repeat as required for multiple tables)WITH( max_batch_size = <number>, publication_name = '<publication-name>');
Example:
CREATE MIRROR IF NOT EXISTS test_mirror_interopFROM test_pg_peer TO test_gcs_peerWITH TABLE MAPPING( schema1.table1:dest_table1, schema1.table2:dest_table2 -- Add more tables as required)WITH( max_batch_size = 300000, publication_name = 'test_publication');
Parameters:
mirror-name: Desired name for the mirror.
postgres-peer-name: Name of the PostgreSQL peer.
storage-peer-name: Name of the S3/GCS peer.
max_batch_size: Maximum number of records in a batch.
publication_name: Name of the publication.
Remember to adjust placeholder values (<…>) with your specific details and preferences.
The example above has been abbreviated for clarity; ensure you provide all the necessary mappings and configurations in practice.
You can connect to localhost:8085 to get full visibility into the different jobs and steps that PeerDB is taking under the covers to manage the MIRROR.
To make it easy in your development and test environments, PeerDB also introduces the DROP MIRROR command. DROP MIRROR drops all the underlying objects that CREATE MIRROR generates. More details are available in this PR.
-- drop the mirrorDROP MIRROR test_mirror_interop;
Assistant
Responses are generated using AI and may contain mistakes.