Data and Knowledge SystemsIngestion and freshnessPrincipal
How can a paused logical-replication consumer exhaust its source database’s disk?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A search-indexing connector reads PostgreSQL changes through a logical replication slot. The connector pauses while source writes continue, and the database’s free disk falls. Explain why the source retains write-ahead logs, which slot positions and rates distinguish causes, and how to protect the database without silently losing the index’s recovery boundary. Use a hypothetical retention-capacity estimate and account for checkpoint enforcement.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
PostgreSQL writes changes to a write-ahead log, or WAL, before relying on them for recovery and replication. A logical replication slot records which history its consumer may still need. If that consumer stops advancing, the database can retain old WAL even while the main application continues generating new changes.
Pausing the consumer does not pause the source application's writes. The current WAL position advances while the slot's required position stays behind, and retained WAL can grow until the source disk is in trouble. PostgreSQL's replication-slot view exposes restart_lsn and retention state. Its replication configuration explains that an unlimited slot retention setting can retain unbounded WAL.
I would check every slot, not just whether the indexing worker process is alive. Compare current WAL LSN with each slot's restart_lsn, inspect confirmed_flush_lsn for the logical consumer, slot activity, retained bytes, disk free space and WAL generation rate. restart_lsn can trail the confirmed position for reasons such as transactions still relevant to decoding, so the metric needs interpretation. A slot can remain active while downstream publishing is stuck. One abandoned slot from an old connector may be the actual cause even if the current connector is healthy.
For a hypothetical source generating 6 GiB of WAL per hour with 60 GiB of free space, WAL alone would consume that space in about 10 hours if the rate stayed constant. Reserving 12 GiB for other needs leaves 48 GiB, or about 8 hours at that rate. Real rates, checkpoints and other disk users vary, so this is a headroom calculation rather than an exact outage deadline. Compare byte positions and actual disk growth instead of treating a long-running connector heartbeat as progress.
The immediate response protects the source database first. Restore consumption if feasible, reduce incoming pressure if the business can tolerate it, and plan disk headroom from generation rate times worst-case outage duration. In PostgreSQL 18, max_slot_wal_keep_size constrains slot retention at checkpoints, rather than acting as an instantaneous disk-usage ceiling. It can bound retained history, but once required WAL is removed the slot may be unusable and the consumer may need a fresh snapshot and a carefully joined change stream. Dropping a slot frees retention but gives up its continuity position. Do not do that merely to clear an alert without a recovery plan for the index.
After recovery, reconcile source document revisions against indexed revisions and prove the gap was closed. Alert on retained WAL bytes and time to disk exhaustion, not just connector lag. The CDC consumer is healthy again. Did it miss three days of changes? asks whether a healthy-again CDC consumer missed changes. This page is the reverse pressure: a stalled consumer can endanger the authoritative database before the search team notices stale answers.
A safe recovery exercise deliberately pauses a disposable consumer, observes retained bytes, then resumes it and verifies both slot progress and query-visible revisions. A separate test invalidates the slot in a fixture and proves that the connector detects the lost continuation rather than advancing a fabricated cursor. An emergency slot deletion is an operational decision with a continuity cost, not an automatic optimization the indexer should perform on its own.
Related questions
Keep practising data and knowledge systems
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux