Cookbook recipe

Replication slot retaining WAL and growing disk usage

Applies to PostgreSQL 13–17 Last reviewed Nov 2025 Grounded in source
Estimated investigation4 min

Scenario

A replication slot — logical or physical — has stopped consuming WAL, and the pg_wal/ directory is growing without bound. Diagnose it -- Slot status and WAL retained: SELECT slot_name, slot_type, active, active_pid, wal_status, safe_wal_size, pg_size_pretty(…

Investigation Path

A replication slot — logical or physical — has stopped consuming WAL, and the pg_wal/ directory is growing without bound.

Diagnose it

-- Slot status and WAL retained:
SELECT slot_name,
       slot_type,
       active,
       active_pid,
       wal_status,
       safe_wal_size,
       pg_size_pretty(
           pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)
       )                         AS retained_bytes,
       inactive_since,           -- PostgreSQL 17+
       invalidation_reason       -- PostgreSQL 17+
FROM pg_replication_slots
ORDER BY pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) DESC NULLS LAST;

A slot with active = false and wal_status = 'lost' or
'unreserved' means WAL it needs has already been recycled — the slot is broken
and must be dropped.

Why it happens

PostgreSQL retains WAL segments until every slot’s restart_lsn has advanced
past them. A slot belonging to a logical replication subscriber that has gone offline,
a downstream service that has paused, or a slot created for testing and never dropped,
will silently accumulate retained WAL until disk space is exhausted.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • How to fix it
  • Prevent it next time
  • Related & next steps
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Career Impact

This scenario builds production judgment and operational confidence under pressure.

Open Career Dashboard →

Keep going

Related & next steps

Was this helpful?

← All cookbook recipes