Cookbook recipe

Manage WAL archive disk usage

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source
Estimated investigation4 min

Scenario

The pg_wal directory keeps growing and threatens to fill the disk — a classic cause of an outage. Find why WAL is being retained. Diagnose it Check what holds WAL back: SELECT slot_name, active, pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn))…

Investigation Path

The pg_wal directory keeps growing and threatens to fill the disk — a classic cause of an outage. Find why WAL is being retained.

Diagnose it

Check what holds WAL back:

SELECT slot_name, active,
  pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained
FROM pg_replication_slots ORDER BY retained DESC;

Why it happens

WAL is retained until it is archived and no longer needed by checkpoints or replication slots. An inactive replication slot or a failing archive_command pins WAL forever, filling the disk.

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