PostgreSQL logical replication slot grows and WAL accumulates after logical decoding plugin crashes on high-write primary
Environment
PostgreSQL 13.5 on Ubuntu 20.04 primary, logical replication slot used for an external decoder plugin (pgoutput/custom plugin) streaming to a downstream consumer over a networked decoder process; high write rate (large UPDATE batches).
Symptoms
Replication slot's restart_lsn stops advancing and pg_replication_slots reports 'active' false. wal directory accumulates many WAL files and disk usage grows until alarms. Downstream consumer shows disconnections and plugin process logs show decoder plugin segfaults or crashed worker process.
Observations
Postgres logs show 'logical decoding found consistent point' then later 'terminating walreceiver due to unexpected end of WAL' and plugin-related crashes. pg_stat_activity shows no active replication connection. Attempts to restart decoder process do not clear existing slot; vacuum/pg_switch_wal doesn't remove WAL files due to slot being retained.
Already attempted
Restarted decoder process and the consumer application; server side left slot intact. Created a new logical slot and pointed new consumer to it; it works but old slot still holds WAL. Attempting to drop slot with pg_drop_replication_slot fails while slot is active=false and no streaming connection present.
Question
How can I safely recover from a crashed logical decoding plugin that left a replication slot holding WAL indefinitely, reclaim disk space without data loss, and prevent recurrence under heavy write load?
Verified community troubleshooting
If the decoder can be restarted and attached to the same slot, that’s the safest path: bring the consumer back, resume streaming and let the slot advance — WAL files will then be removed. If the consumer is unrecoverable and disk is critical, after confirming you have an up-to-date base backup and accept losing that downstream state, drop the slot with SELECT pg_drop_replication_slot('slotname') to free WAL. Add monitoring for slot lag and supervise the decoding process so future crashes auto-restart and resume the slot. Verify by watching pg_replication_slots and disk WAL usage.
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Databases31% match
PostgreSQL logical replication falls behind after ALTER TABLE ADD COLUMN with non-null DEFAULT on large table
Open0 answers - Databases31% match
PostgreSQL replica stops streaming WAL after pg_repack on primary; replication slot reports missing WAL
Open0 answers - Databases31% match
PostgreSQL logical replication slot grows until disk full after subscriber disconnects during nightly load
Open0 answers - Databases27% match
PostgreSQL standby stops applying WAL after pg_basebackup restore — replication slot grows and disk fills
Open0 answers - Databases26% match
PostgreSQL replica SQL apply thread stalls 'waiting for table metadata lock' after large ALTER TABLE on primary
Open0 answers