Postgres CDC: change data capture from PostgreSQL with logical decoding
Postgres CDC turns every committed insert, update and delete into an event other systems can consume. This guide covers the PostgreSQL settings it needs, how replication slots can fill a disk, what survives a failover, and how Debezium uses it.
45 minutes with an engineer: we review your workload and sketch the design.
- ✓Docs read 19 Nov 2026
- ✓OSStend runs Debezium
Postgres CDC reads committed changes from PostgreSQL's write-ahead log through logical decoding. It needs wal_level set to logical, a replication slot that remembers the consumer's position, and usually a publication naming the tables. The slot holds WAL until the consumer confirms it, so slot lag is the number to watch. Facts read from the PostgreSQL, Debezium and AWS documentation, 19 Nov 2026.
Customers
Partners
What is Postgres CDC?
Postgres CDC (change data capture) is reading the row-level changes PostgreSQL commits and sending them to other systems as they happen. PostgreSQL provides it natively through logical decoding, which turns the write-ahead log into a stream of changes per table.
A Postgres CDC pipeline has three parts: PostgreSQL configured for logical decoding, a reader that holds a replication slot (Debezium, a managed CDC service or PostgreSQL's own logical replication subscriber), and the consumers that apply the changes. For the general picture of CDC methods and tools, read change data capture explained.
Setting up PostgreSQL for CDC: wal_level, slots, publications and privileges
Logical decoding needs wal_level set to logical, room for replication slots and WAL senders, a publication listing the tables, and a database user with replication rights. The slot and WAL sender limits can only be changed at server start, so they are set before the first connector arrives.
| Setting | What it does | What to check |
|---|---|---|
| wal_level | logical makes WAL carry what logical decoding needs (logical decoding, checked 19 Nov 2026). In PostgreSQL 19 decoding also works at wal_level replica once a logical slot exists, shown by effective_wal_level; Debezium's documentation still says to set logical (Debezium PostgreSQL connector, checked 19 Nov 2026). | Set logical explicitly, and plan the restart it needs. |
| max_replication_slots, max_wal_senders | Both default to 10 and can only be set at server start (replication settings, checked 19 Nov 2026). | One slot and one sender per connector, plus headroom for replicas and tooling. |
| Publication | CREATE PUBLICATION names the tables, or FOR ALL TABLES or FOR TABLES IN SCHEMA, with optional row filters and column lists (CREATE PUBLICATION, checked 19 Nov 2026). | FOR ALL TABLES and FOR TABLES IN SCHEMA need a superuser; a column list must include the replica identity columns. |
| Privileges | The Debezium user needs REPLICATION and LOGIN, and SELECT on the captured tables for the snapshot; on Amazon RDS it needs the rds_replication role (Debezium PostgreSQL connector, checked 19 Nov 2026). | A dedicated user per connector, with only those rights. |
PostgreSQL 19 was released on 19 November 2026 (documentation, checked 19 Nov 2026). Debezium 3.7 lists PostgreSQL 14 to 18 as supported sources (Debezium releases, checked 19 Nov 2026), so check support before pointing a connector at a 19 server.
A minimal setup for two tables, run as a superuser:
ALTER SYSTEM SET wal_level = logical; -- takes effect after a restart CREATE ROLE cdc_reader WITH LOGIN REPLICATION PASSWORD '...'; GRANT SELECT ON public.orders, public.order_lines TO cdc_reader; CREATE PUBLICATION cdc_orders FOR TABLE public.orders, public.order_lines; -- only where consumers need full before-images: ALTER TABLE public.orders REPLICA IDENTITY FULL;
REPLICA IDENTITY, before images and TOAST columns
REPLICA IDENTITY decides which old values PostgreSQL writes for updates and deletes. The default logs only the primary key, so update and delete events carry the key but not the rest of the old row, and large TOASTed values that did not change are left out of update events.
- The four settings.
- DEFAULT logs the primary key's old values, and behaves as NOTHING on a table with no primary key; USING INDEX logs a named unique, non-partial index on NOT NULL columns; FULL logs every old column; NOTHING logs no old row (ALTER TABLE, checked 19 Nov 2026).
- Tables without a primary key.
- With DEFAULT and no key, updates and deletes carry no identity at all, and a publication that publishes them needs a replica identity. Give such tables a key or a USING INDEX identity before capture starts.
- TOAST.
- Unchanged TOASTed columns that are not in the replica identity are missing from update events. Debezium emits a placeholder instead, __debezium_unavailable_value by default, and with REPLICA IDENTITY FULL those columns appear normally (Debezium PostgreSQL connector, checked 19 Nov 2026).
- The cost of FULL.
- FULL writes whole old rows to WAL on every update and delete, and on PostgreSQL subscribers it breaks applying changes for column types with no default B-tree or hash operator class, such as point or box (restrictions, checked 19 Nov 2026). Use it per table, where consumers need it.
Replication slots and WAL retention: why Postgres CDC can fill a disk
A replication slot keeps every WAL segment its consumer has not confirmed, and also holds back the cleanup of old catalog rows. A stopped or slow connector therefore makes WAL pile up on the primary until it is fixed, the slot is dropped, or a retention cap invalidates the slot.
- ✓What a slot holds. A slot streams changes from one database, survives crashes and disconnects, and retains WAL and catalog rows; unused slots must be dropped, and in extreme cases the held-back cleanup can lead to transaction ID wraparound shutting the database down (logical decoding, checked 19 Nov 2026).
- ✓One reader, at least once. Only one consumer can read a slot at a time, and its position is saved at checkpoints, so after a crash some changes are sent again. Consumers must apply events idempotently.
- ✓A cap. max_slot_wal_keep_size defaults to -1, unlimited; set it and a slot that falls further behind can lose the WAL it needs (replication settings, checked 19 Nov 2026). The current documentation also has idle_replication_slot_timeout, off at 0, which invalidates slots left inactive too long.
- ✓Seeing it. pg_replication_slots shows wal_status (reserved, extended, unreserved, lost) and an invalidation_reason such as wal_removed or idle_timeout (pg_replication_slots, checked 19 Nov 2026); pg_stat_replication_slots counts transactions spilled to disk against logical_decoding_work_mem (statistics, checked 19 Nov 2026).
- ✓Quiet databases. A connector only confirms positions when it sees changes, so a slot on a quiet database can hold WAL that other databases generate. Debezium's heartbeat.interval.ms (off at 0) and heartbeat.action.query fix that; the heartbeat table must be in the publication (Debezium PostgreSQL connector, checked 19 Nov 2026).
The query on-call engineers run first when a primary's disk is filling:
SELECT slot_name, active, wal_status, invalidation_reason, pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS wal_held FROM pg_replication_slots ORDER BY pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) DESC;
Postgres CDC after a failover: failover slots
A logical slot used to exist only on the primary, so a failover left the connector with nowhere to resume. Failover slots fix that: the slot is created with the failover option and synchronized to a standby, and after promotion a synced slot can carry on.
- On the standby.
- Set sync_replication_slots = on and hot_standby_feedback = on, with a physical slot in primary_slot_name and a primary_conninfo that names the database (logical decoding; replication settings, checked 19 Nov 2026).
- On the primary.
- List the standby's physical slot in synchronized_standby_slots, so logical consumers never get ahead of what the standby has.
- After promotion.
- Only persistent slots marked synced can resume on the new primary; check the synced and failover columns of pg_replication_slots before relying on it.
- In Debezium.
- slot.failover=true creates a failover slot on a PostgreSQL 17 or later primary, with the standby's physical slot listed in synchronized_standby_slots (Debezium PostgreSQL connector, checked 19 Nov 2026).
- Without failover slots.
- The slot has to be recreated on the new primary and the gap covered by a re-snapshot or a replay plan, so that procedure is written down before the first failover.
What Postgres CDC does not capture
Logical decoding carries row changes to tables. It does not carry schema changes, ongoing sequence values, large objects or changes to views, so a CDC design has to handle each of those another way.
- ✕DDL. Schema changes are not replicated, so they are applied to consumers deliberately, and connectors are checked after each one (logical replication restrictions, checked 19 Nov 2026).
- ✕Sequences. Ongoing sequence state is not streamed; PostgreSQL 19 adds ALTER SUBSCRIPTION ... REFRESH SEQUENCES for logical replication subscribers, which other consumers do not get.
- ✕Large objects. Data stored as large objects is not decoded; bytea and TOASTed columns are.
- ✕Views, materialized views and foreign tables. Capture the underlying tables instead.
- ✕TRUNCATE. It is replicated, but can fail on a PostgreSQL subscriber when foreign keys reach tables outside the subscription, and row filters and column lists do not apply to it.
Postgres CDC with
Debezium and Kafka
Debezium's PostgreSQL connector reads a replication slot with the built-in pgoutput plug-in, takes an initial snapshot, then streams each change as an event with before and after values. It can create the slot and the publication itself, or use ones your DBA creates.
| Setting | What it controls | Default and options |
|---|---|---|
| plugin.name | The logical decoding output plug-in. | pgoutput is built into PostgreSQL 10 and later; decoderbufs needs installing. |
| slot.name | The replication slot the connector reads. | debezium; each connector on a server needs its own slot and publication. |
| publication.autocreate.mode | Whether the connector creates its publication. | all_tables (default) creates one FOR ALL TABLES if missing; filtered limits it to the captured tables; disabled fails if it does not exist. |
| snapshot.mode | What happens before streaming starts. | initial (default), always, initial_only, no_data, when_needed, configuration_based, custom. |
| heartbeat.interval.ms | How often the connector confirms its position on quiet databases. | 0 (off). Set it wherever a slot can sit idle. |
From the Debezium PostgreSQL connector documentation for Debezium 3.7, checked 19 Nov 2026. Creating a publication needs replication rights plus CREATE on the database, and adding a table to one needs ownership of the table.
Events usually land in Kafka through Kafka Connect, or go to other systems through Debezium Server. OSStend runs the pipeline as managed Debezium; the database itself is covered on managed PostgreSQL, and keeping embeddings fresh with Kafka CDC shows one use.
Postgres CDC on Amazon RDS and Aurora PostgreSQL
On Amazon RDS and Aurora you cannot set wal_level directly. Logical decoding is switched on with the rds.logical_replication parameter, which is static, so it takes a reboot, and the CDC user gets AWS's rds_replication role.
- RDS for PostgreSQL.
- Set rds.logical_replication to 1 in the parameter group; it also sets wal_level, max_wal_senders, max_replication_slots and max_connections, and needs a reboot. AWS warns that an unread slot can fill storage quickly (RDS documentation, checked 19 Nov 2026).
- Aurora PostgreSQL.
- The parameter lives in a custom DB cluster parameter group, default 0; set it to 1, reboot the writer, and confirm with SHOW rds.logical_replication and SHOW wal_level (Aurora documentation, checked 19 Nov 2026).
- Aurora read replicas.
- Aurora does not support PostgreSQL 16's logical decoding from read replicas, so connectors read the writer (Aurora logical replication, checked 19 Nov 2026).
- Quiet RDS databases.
- Debezium notes that RDS writes to its own system tables about every five minutes, which can leave a slot holding WAL; a heartbeat query keeps it moving.
If the choice is between Debezium and AWS's own service for this, see Debezium vs AWS DMS.
From our on-call engineers: the Postgres CDC checks in our runbook
These come from the PostgreSQL, Debezium and AWS documentation, read on 19 Nov 2026, and are the checks we build a Postgres CDC runbook from. They are documentation, not a record of incidents, and we quote no customer figure.
- ✓Every slot has an owner and an alert on the WAL it holds; a slot nobody reads is dropped, not left.
- ✓max_slot_wal_keep_size is set only together with a re-snapshot runbook, because the cap trades disk safety for an invalidated slot.
- ✓Tables without a primary key are found before capture starts, not after the first update event arrives without one.
- ✓REPLICA IDENTITY FULL is set per table, where a consumer needs before-images, never as a blanket change.
- ✓Failover slots are tested by promoting the standby in a rehearsal, and the synced flag is checked first.
- ✓Heartbeats are on for any connector whose database can go quiet, RDS included.
FAQ
What is Postgres CDC?
Reading each committed insert, update and delete from PostgreSQL's write-ahead log through logical decoding, and sending it to other systems as an event.
Does Postgres CDC need a restart?
Usually once: wal_level, max_replication_slots and max_wal_senders are set at server start. On RDS and Aurora, rds.logical_replication is static and needs a reboot.
Why is my PostgreSQL disk filling up with WAL?
Most often a replication slot whose consumer has stopped or fallen behind: the slot keeps WAL until it is confirmed. Check pg_replication_slots, then fix the consumer, drop the slot or cap retention with max_slot_wal_keep_size.
Do I need REPLICA IDENTITY FULL?
Only if consumers need the old values of every column on updates and deletes, or unchanged TOAST columns in every event. The default logs only the primary key.
Does Postgres CDC survive a failover?
With failover slots it can: the slot is created with the failover option and synchronized to a standby. Without them, the slot is recreated on the new primary and the gap is re-snapshotted.
Can I run Postgres CDC on Amazon RDS?
Yes. Set rds.logical_replication to 1, reboot, and grant the CDC user rds_replication. Aurora needs the writer instance, not a read replica.
Which tool should read the changes?
Debezium is the common open-source choice, through Kafka Connect or Debezium Server. Managed services such as AWS DMS also read logical decoding. See Debezium alternatives for the options.
PostgreSQL is a registered trademark of the PostgreSQL Community Association of Canada. Debezium is a trademark of its respective owner, and Apache Kafka a trademark of The Apache Software Foundation. AWS, Amazon RDS and Aurora are trademarks of Amazon. OSStend is not affiliated with or endorsed by these projects or by Amazon.
Related pages
- GuideChange data capture (CDC): methods and toolsChange data capture explained: log-based vs query-based CDC, the main CDC tools, Postgres CDC and replication slots, and when to pay someone to run it.
- KafkaManaged Kafka in your cloud or data centerManaged Kafka with the broker count, partition plan, KRaft, Connect and an Apicurio or Karapace schema registry designed for your estate, run 24/7 in your cloud or data center.
- Kafka ConnectManaged Kafka Connect: connectors run 24/7Managed Kafka Connect in distributed mode: workers, internal topics, dead letter queues, offsets and upgrades run 24/7, in OSStend's cloud, your cloud account or your data center.
Change data captureManaged Debezium: change data capture run 24/7Managed change data capture with Debezium on Kafka Connect or Debezium Server, run 24/7 in OSStend's cloud, your cloud account or your data center.
- PostgreSQLManaged PostgreSQL service and Postgres hostingManaged PostgreSQL service, compared: how to choose between RDS, Aiven, Crunchy Bridge, Neon and a tailored cluster run 24/7 in your cloud or ours.
- AI data · Fresh contextEmbeddings freshness with Kafka and Postgres CDCPostgres CDC with Debezium and Kafka Connect keeps embeddings current: re-embed on change, handle deletes, and stop agents answering from stale data.
Take your Postgres CDC pipeline to an engineer
45 minutes: your PostgreSQL setup, slots and consumers are reviewed, and an engineer says what to change and what to hand over.
- ✓A design sketch for your workload, not a plan menu
- ✓A zero-downtime cutover path for what you run today
- ✓A price for that design, after the review





