The change-data-capture connector Debezium stalled, and write-ahead log files fill the PostgreSQL primary's disk — diagnose
A Debezium connector streams the orders database from a PostgreSQL 18 primary into Kafka. Its Kafka Connect task failed at 03:10 and nobody restarted it. By noon the volume holding pg_wal is 93% full and still growing, though write traffic is normal and checkpoints complete on time. max_slot_wal_keep_size is unset. Constraints: base the cause on the output below, keep the primary up, and say what happens to the CDC stream after your fix.
SELECT slot_name, slot_type, active, wal_status,
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained
FROM pg_replication_slots;
slot_name | slot_type | active | wal_status | retained
-----------------+-----------+--------+------------+----------
debezium_orders | logical | f | extended | 412 GB
standby_1 | physical | t | reserved | 96 MB
$ df -h /var/lib/postgresql
Filesystem Size Used Avail Use%
/dev/nvme1 1.0T 930G 70G 93%Diagnose the cause.
The inactive slot debezium_orders pins 412 GB of WAL: a slot keeps every segment from its restart_lsn until the consumer confirms it, connected or not. Restart the connector, or drop an abandoned slot and re-snapshot; alert on retained WAL, cap it.
- Assuming a slot stops retaining WAL once its consumer disconnects
- Deleting files from pg_wal by hand, which can corrupt the database
- Dropping a logical slot without planning a new snapshot for the changes the consumer never read
- What does
max_slot_wal_keep_sizetrade away when it stops a slot from filling the disk? - Why does a stalled logical slot also hold back VACUUM of system catalog rows?
Reading the output. debezium_orders shows active = f and retains 412 GB — nearly all the used space. A replication slot is a server-side bookmark: PostgreSQL keeps every WAL segment from restart_lsn on until the consumer confirms it (confirmed_flush_lsn for a logical slot), and the consumer need not be connected for that. wal_status = extended means the retained WAL exceeds max_wal_size but is still kept — by a slot or by wal_keep_size; here it is the slot. The physical standby_1 is active and 96 MB behind — not the culprit. Checkpoints are fine, and max_slot_wal_keep_size = -1 (the default) sets no limit.
Fix.
-- 1. If the connector is still needed: restart the Kafka Connect task.
-- It reads WAL from the confirmed position, and the server starts removing segments.
-- 2. If the connector is abandoned or cannot catch up before the disk fills:
SELECT pg_drop_replication_slot('debezium_orders');
-- Changes after the last confirmation are lost to CDC:
-- Debezium must take a new snapshot of the tables on its next start.
-- 3. Guard rails
ALTER SYSTEM SET max_slot_wal_keep_size = '200GB'; -- past it, the slot is invalidated
-- PostgreSQL 18 also has idle_replication_slot_timeout: invalidates a slot idle longer than it
SELECT pg_reload_conf();
SELECT slot_name, active,
pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) AS retained_bytes
FROM pg_replication_slots; -- alert on retained_bytes and on active = falseDeleting files from pg_wal by hand is never acceptable: the server may fail to start after a crash. Besides WAL, a stalled logical slot also pins catalog_xmin, so VACUUM cannot clean system catalog rows.