<@U04S8PLJWMT>, i am replicating data from postgre...
# replication-ask-ai
s
@kapa.ai, i am replicating data from postgres to s3 in cdc but deletes are not being replicated
k
Thinking completed When using Postgres CDC with file-based destinations like AWS S3, deletes are handled differently than in database destinations with hard-delete features. Here is what you need to check and understand regarding how deletes are replicated: 1. How Deletes Are Captured in S3 When syncing CDC records to an S3 destination (e.g., CSV, JSONL, Parquet, Avro), Airbyte does not modify or remove existing rows/files already written to S3. Instead, deletions are emitted as new records containing CDC metadata [S3 Output Schema; CDC Documentation]: •
_ab_cdc_deleted_at
: Populated with the deletion timestamp (it will be
null
for non-deleted records) [CDC Documentation; CDC ELT Tutorial]. • Data fields: For
DELETE
operations, only the primary key column(s) are populated; all other table columns are unset/null [Postgres Troubleshooting]. If you are inspecting raw or appended files in S3, you will see an additional record for each deleted row with the
_ab_cdc_deleted_at
field set [Postgres CDC Tutorial]. 2. Common Reasons Deletes Are Not Captured If the deletion records are completely missing from your S3 files, verify the following: • Primary Key Requirement: Incremental CDC sync only supports tables with primary keys. If a table does not have a primary key, CDC will not capture changes properly [Postgres Troubleshooting]. • Method of Deletion: Airbyte CDC only captures deletions performed via standard SQL
DELETE
statements. Deletions via
TRUNCATE
are not captured in the write-ahead logs (WAL) by CDC [Postgres Troubleshooting]. • Initial Snapshot vs. Incremental Sync: The initial sync takes a table snapshot (effectively a Full Refresh) and does not capture changes. Deletions are only captured from the WAL in subsequent incremental syncs after the initial snapshot completes [CDC Documentation]. • Replica Identity: Ensure your Postgres table has a replica identity configured (usually
DEFAULT
, or
FULL
if you require full row images or handle large/TOAST data) [Cloud SQL Postgres Setup]:ALTER TABLE your_table REPLICA IDENTITY DEFAULT; • Publication Inclusion: Ensure the table is explicitly added to the publication used by Airbyte:ALTER PUBLICATION airbyte_publication ADD TABLE your_table;If a table is selected in the connection but is missing from the publication, changes won't replicate [Cloud SQL Postgres Setup]. • Sync Mode: Ensure the stream's sync mode in your connection is set to use the incremental replication method rather than Full Refresh [CDC Documentation]. 👍 0 button 👎 0 button ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
s
@kapa.ai,a record is deleted in the source but it still has null in deleted_at column
k
Thinking completed Based on how Airbyte handles Change Data Capture (CDC) with PostgreSQL, here is why a record might still show
null
in the
_ab_cdc_deleted_at
column: 1. Existing Rows Are Not Updated in Place (Append-Only) In file-based destinations (such as S3) or raw append streams, Airbyte does not update the previously synced row when a record is deleted. • The original row that was inserted during the initial snapshot or an earlier sync will permanently keep
_ab_cdc_deleted_at: null
[Postgres CDC Tutorial; Postgres CDC ELT Tutorial]. • When a deletion occurs, Airbyte emits a new, separate record in the subsequent sync. In that new record,
_ab_cdc_deleted_at
is populated with the deletion timestamp, and non-primary key columns will be
null
[Postgres Troubleshooting; Postgres CDC ELT Tutorial]. If you are looking at the original row in your destination, it will still have
null
. You need to look for the newly appended record for the same primary key. 2. The Deletion Has Not Been Emitted Yet • Sync Has Not Run: The deletion event will only appear after a subsequent sync runs following the
DELETE
query [Postgres CDC Tutorial]. • Initial Snapshot Phase: Deletions that occurred before or during the initial snapshot phase do not generate delete events—the record is simply omitted from the initial load [Db2 CDC Behavior]. 3. Deletion Method Was Not Supported •
_ab_cdc_deleted_at
is only populated when rows are removed using standard SQL
DELETE
statements [Postgres Troubleshooting]. • If the table or rows were removed using
TRUNCATE
, it is not captured in the PostgreSQL logical replication log, and no deletion event will be generated [Postgres Troubleshooting]. 👍 0 button 👎 0 button ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.