FULL AI ANALYSIS

PostgreSQL logical replication slot grows and WAL accumulates after logical decoding plugin crashes on high-write primary

Generated Oct 24, 2026, 9:21:01 AM

Analysis summary

Logical slots retain WAL until a consumer confirms consumption; a crashed decoding plugin left the slot in place, preventing WAL purge. Safe recovery options: reconnect a consumer to the slot and advance it (best), or if consumer cannot be recovered, drop the slot (data lost for that slot) after ensuring downstream state is acceptable. Prevent recurrence by making decoder process resilient (supervised service), monitor slot lag, and consider using replication slots with max_slot_wal_keep (PG 13 lacks built-in limit) or offload logical decoding to a durable process that can resume.

Possible causes

External logical decoding plugin or consumer process crashed and did not advance or close the replication slot, causing WAL retention

95%

Plugin hit a corner-case bug under high write rates causing fatal error and leaving slot orphaned

60%

Network blips causing frequent disconnects that left slot unadvanced and intermittent reconnect attempts failing to resume position

30%

Misconfiguration: consumer creates slot but is not designed to resume from the stored LSN, making recovery difficult

25%

Suggested fixes

1

Diagnostic step 1

Check pg_replication_slots and pg_stat_replication to confirm slot state and last_confirmed_flush_lsn.

2

Diagnostic step 2

If you can recover the decoder/consumer, start it and point it at the existing slot to stream and advance the slot; monitor WAL purge after consumer advances.

3

Diagnostic step 3

If consumer cannot be recovered and disk space is urgent, ensure you have a recent base backup; then drop the slot with SELECT pg_drop_replication_slot('slotname') to free WAL (note: downstream data for that slot will be lost).

4

Diagnostic step 4

Add monitoring/alerts for slot lag (e.g., compare current WAL location to slot's confirmed LSN) and supervise the decoder with systemd/pm2 to auto-restart and resume.

5

Diagnostic step 5

Consider changing architecture: stream logical changes into a durable queue or WAL shipping consumer that persists state, and review plugin for upgrades/bug fixes.