Scrivio Interview library
DebuggingIntermediate6 min read · updated 12 November 2026

The primary's disk filled up overnight because pg_wal grew to 900 GB. SELECT slot_name, active, restart_lsn FROM pg_replication_slots shows a slot named debezium_old with active = f. Explain the cause and the fix.

A replication slot makes the primary keep every WAL file its consumer has not yet confirmed, and debezium_old is an inactive slot left behind by a CDC connector that stopped, so it has pinned all WAL since its restart_lsn and pg_wal grew until the disk filled. The fix is to confirm the slot is really unused, drop it with pg_drop_replication_slot('debezium_old'), and let the next checkpoint recycle the WAL. To stop it happening again, we cap retained WAL with max_slot_wal_keep_size and alert on inactive slots and retained WAL size.

Why this question is asked

A full disk on the primary is one of the worst PostgreSQL incidents, because when PostgreSQL cannot write WAL it stops accepting writes and may shut down. Forgotten replication slots are one of the most common causes, especially after a team experimented with change data capture and moved on. Interviewers ask this because the answer shows we understand what a slot promises, how to fix the problem without making it worse, and what guardrails belong in every setup. In this answer, we will recap what a slot does, work out why this one filled the disk, fix it safely, and then set up prevention.

1A Quick Recap of Replication Slots

A replication slot is a small record on the primary that remembers how far one consumer has read the WAL. The consumer can be a physical standby or a logical decoding client such as Debezium, a CDC connector that turns database changes into Kafka events. Each time the consumer confirms it has processed WAL up to a position, called an LSN (log sequence number), the slot moves forward.

The promise of a slot is that the primary never removes WAL the consumer still needs. Without a slot, a consumer that falls too far behind finds its WAL already recycled and has to start over. With a slot, the primary waits. That promise has no time limit by default: if the consumer never comes back, the primary waits forever.

2Why the Disk Filled Up

The slot's restart_lsn is the oldest WAL position the consumer might still need, so PostgreSQL keeps every WAL segment from there onwards. active = f means no process is connected to the slot. Together they say: an old connector created this slot, then stopped, perhaps months ago when the team replaced it, and nobody dropped the slot. Every WAL segment written since then is still in pg_wal.

SQL
SELECT slot_name, slot_type, active, restart_lsn,
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained
FROM pg_replication_slots;
-- debezium_old | logical | f | 1A/2C000000 | 900 GB
-- standby_b | physical | t | 9F/41000000 | 64 MB
Step throughHow an abandoned slot fills pg_wal
  1. Connector creates slot debezium_oldit reads and confirms changes
  2. Connector is stopped or replacednobody drops the slot
  3. Slot stays at its restart_lsnactive = f
  4. Checkpoint: is WAL older than every slot?
    YesRecycle the segmentNoKeep the segment
  5. pg_wal grows with every write900 GB until the disk is full

5 steps in order. Play them, or step through them one at a time.

Notice that the healthy standby slot retains 64 MB, while debezium_old retains 900 GB. The size grows with the write rate: a database writing 30 GB of WAL a day needs only a month to fill 900 GB. Checkpoints normally recycle old WAL segments, but they can only recycle segments older than every slot's restart_lsn, so this one slot blocked all recycling.

3Fixing It Safely

Before dropping anything, we confirm the slot is truly unused: check with the team that owned it, look in Kafka Connect for a connector configured with slot.name debezium_old, and check that no process has connected recently. Dropping a slot that a live consumer needs would force that consumer to start over, so this check matters even under pressure.

If the primary is still running, we drop the slot and force a checkpoint, so the old WAL segments are recycled straight away instead of at the next scheduled checkpoint.

SQL
SELECT pg_drop_replication_slot('debezium_old');
CHECKPOINT; -- recycle the segments now
SELECT pg_size_pretty(sum(size)) FROM pg_ls_waldir();
-- 1.2 GB

If the disk was completely full and PostgreSQL has stopped, we must first give it room to start, for example by growing the volume. We never delete files in pg_wal by hand: removing a segment the server still needs for recovery can make the cluster impossible to start. Once it is running, we drop the slot as above.

4A Second Cost: catalog_xmin and Catalog Bloat

An inactive logical slot does one more kind of damage. Logical decoding needs old versions of system catalog rows to understand past changes, for example what a table's columns were when a row was written. So a logical slot holds a catalog_xmin, an old transaction id, and vacuum cannot remove dead catalog rows newer than it. Over months, tables such as pg_attribute and pg_class bloat, which slows planning and catalog lookups for every query. Physical slots used with hot_standby_feedback can hold back the regular xmin in the same way and bloat user tables. Dropping the slot releases both, and the next vacuum can clean up.

SQL
SELECT slot_name, catalog_xmin, age(catalog_xmin) FROM pg_replication_slots;
-- debezium_old | 48211907 | 310000000 (vacuum on catalogs has been blocked this long)

5Preventing It Next Time

The first guardrail is max_slot_wal_keep_size, available since PostgreSQL 13. It caps how much WAL a slot may retain. When a slot passes the limit, PostgreSQL invalidates it and recycles the WAL, so the disk stays safe and only that consumer is affected. The wal_status column of pg_replication_slots shows the state, moving from reserved to extended to unreserved and finally lost.

SQL
ALTER SYSTEM SET max_slot_wal_keep_size = '100GB';
SELECT pg_reload_conf();
SELECT slot_name, wal_status, safe_wal_size FROM pg_replication_slots;
-- standby_b | reserved | 99 GB

The second guardrail is alerting: on any slot with active = f for more than an hour, and on retained WAL per slot above a threshold well below the cap. The third is process: whoever decommissions a connector must drop its slot, which we can write into the runbook and check with a weekly report. PostgreSQL 18 also adds idle_replication_slot_timeout to invalidate slots that sit unused for too long; check your version.

6Follow-up questions

What happens to the CDC consumer when its slot is invalidated?

It can no longer resume from where it stopped, because the WAL it needed is gone. When it reconnects, PostgreSQL refuses to stream from the slot with an error saying the slot has been invalidated. The connector needs a new slot and a fresh snapshot of the tables to rebuild its starting point, and downstream systems may see the snapshot rows again, so they must handle duplicates. That is a real cost, but it is much smaller than the primary's disk filling up.

Can a physical standby slot cause the same problem?

Yes. If a standby is shut down or loses its network but its slot remains, the primary keeps WAL for it in the same way. The same cap and alerts apply to physical slots.

Why not set max_slot_wal_keep_size very low to be safe?

Because a healthy consumer that falls behind briefly, for example during a Kafka outage or a long standby restart, would have its slot invalidated and need a full resync. We size the cap from the free disk and how long an outage we want to survive, for example two days of WAL.

7Conclusion

In this answer, we saw that a replication slot makes the primary keep WAL until its consumer confirms it, so an inactive slot left by an old CDC connector pinned 900 GB of WAL from its restart_lsn onwards. We confirmed the slot was unused, dropped it with pg_drop_replication_slot and ran a checkpoint to recycle the WAL, without ever deleting WAL files by hand. We also saw that inactive logical slots hold catalog_xmin and bloat the catalogs, and we prevented a repeat with max_slot_wal_keep_size, alerts on inactive slots and retained WAL, and a decommissioning step that drops slots.

What to say in the interviewAbout 90 seconds aloud

Open with

The cause is the inactive slot. A replication slot makes the primary keep all WAL that its consumer has not confirmed, starting from restart_lsn, and that promise has no time limit by default. debezium_old was created by an old Debezium connector; the connector was stopped or replaced, but nobody dropped the slot, so active is false and every WAL segment since then stayed in pg_wal, because checkpoints can only recycle WAL older than every slot.

Then, if they want more

I would measure it with pg_wal_lsn_diff between pg_current_wal_lsn and restart_lsn. For the fix, I would first confirm with the owning team and Kafka Connect that nothing uses the slot, then run pg_drop_replication_slot on it and a CHECKPOINT so the segments are recycled right away.

If the disk was full and the server down, I would grow the volume to get it started, and never delete WAL files by hand. I would also mention that an inactive logical slot holds catalog_xmin, which stops vacuum on the system catalogs, so there may be catalog bloat to clean up.

To prevent it, I would set max_slot_wal_keep_size, so a runaway slot gets invalidated instead of filling the disk, alert on slots inactive for more than an hour and on retained WAL per slot, and make dropping the slot part of decommissioning any connector.

About this answer

Last updated
12 November 2026
Versions it names
PostgreSQL 13, PostgreSQL 18
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
PostgreSQL documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "The primary's disk filled up overnight because pg_wal grew to 900 GB. SELECT slot_name...": https://scrivio-interview-library.netlify.app/databases/postgresql/0c80e10d3d/