<@U04S8PLJWMT> What configurations must be set up...
# replication-troubleshooting
r
@kapa.ai What configurations must be set up in PostgreSQL so that CDC (logical replication) via Airbyte to BigQuery can run?
k
To enable Change Data Capture (CDC) using logical replication from PostgreSQL to BigQuery via Airbyte, you must configure your PostgreSQL instance with the following steps: 1. Create a dedicated read-only user with REPLICATION permissions:
Copy code
sql    CREATE USER airbyte PASSWORD 'your_password';    ALTER USER airbyte REPLICATION LOGIN;
This user will be used by Airbyte to read data and access the replication stream. Also, grant this user SELECT privileges on the relevant schemas and tables:
Copy code
sql    GRANT USAGE ON SCHEMA your_schema TO airbyte;    GRANT SELECT ON ALL TABLES IN SCHEMA your_schema TO airbyte;    ALTER DEFAULT PRIVILEGES IN SCHEMA your_schema GRANT SELECT ON TABLES TO airbyte;
[Build an EL(T) from Postgres CDC (Step 2)](https://airbyte.com/tutorials/postgresql-change-data-capture-elt#step-2) 2. Enable logical replication on your PostgreSQL database: - For managed services (like Cloud SQL or RDS), set the appropriate flag (e.g.,
cloudsql.logical_decoding
for Cloud SQL) to enable logical replication. - For self-hosted PostgreSQL, ensure the
wal_level
is set to
logical
in your
postgresql.conf
file. [Cloud SQL for PostgreSQL CDC Setup](https://docs.airbyte.com/integrations/sources/postgres/cloud-sql-postgres#setup-using-cdc) 3. Create a logical replication slot using the
pgoutput
plugin:
Copy code
sql    SELECT pg_create_logical_replication_slot('airbyte_slot', 'pgoutput');
This slot will be used by Airbyte to stream changes. [Build an EL(T) from Postgres CDC (Step 2)](https://airbyte.com/tutorials/postgresql-change-data-capture-elt#step-2) 4. Set up replication identities for each table you want to replicate:
Copy code
sql    ALTER TABLE your_table REPLICA IDENTITY DEFAULT;
If your tables use large fields or TOASTed columns, consider:
Copy code
sql    ALTER TABLE your_table REPLICA IDENTITY FULL;
[Cloud SQL for PostgreSQL CDC Setup - Step 5](https://docs.airbyte.com/integrations/sources/postgres/cloud-sql-postgres#step-5-create-publication-and-replication-identities-for-each-postgres-table) 5. Create a publication including all tables you want to replicate:
Copy code
sql    CREATE PUBLICATION airbyte_publication FOR TABLE table1, table2;
[Cloud SQL for PostgreSQL CDC Setup - Step 5](https://docs.airbyte.com/integrations/sources/postgres/cloud-sql-postgres#step-5-create-publication-and-replication-identities-for-each-postgres-table) 6. Configure the Airbyte Postgres source connector: - In the Airbyte UI, select "Logical Replication (CDC)" as the replication mode. - Enter the replication slot and publication names you created above. [Cloud SQL for PostgreSQL CDC Setup - Step 6](https://docs.airbyte.com/integrations/sources/postgres/cloud-sql-postgres#step-6-enable-cdc-replication-in-airbyte-ui) Note: If you are using a managed PostgreSQL service (like AWS Aurora, TimescaleDB, or Azure PG Flex), review the [vendor-specific limitations](https://docs.airbyte.com/integrations/sources/postgres/postgres-troubleshooting#vendor-specific-connector-limitations) to ensure compatibility. By following these steps, your PostgreSQL instance will be ready for CDC-based replication to BigQuery via Airbyte.