Full answer
Checklist:
- Replication slots:
SELECT slot_name, active, pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) FROM pg_replication_slots;An inactive slot from a decommissioned replica or CDC tool retains WAL forever. Drop it if it is no longer needed. - WAL archiving: if
archive_commandkeeps failing, WAL segments pile up; checkpg_stat_archiver. - Bloat: dead tuples in hot tables and indexes, blocked by long transactions.
- Temporary files: queries spilling sorts and hashes;
log_temp_filesshows them. - Logs: verbose statement logging can produce gigabytes per day.
- Largest objects:
SELECT relname, pg_size_pretty(pg_total_relation_size(oid)) FROM pg_class ORDER BY pg_total_relation_size(oid) DESC LIMIT 10;
Set alerts on disk usage and on slot lag (max_slot_wal_keep_size caps retained WAL in PostgreSQL 13+). Running out of disk can stop the database entirely, so treat a fast-growing disk as urgent. Described here, not run.
Key points
- Inactive replication slots retain WAL
- Failing archiving accumulates WAL
- Bloat and temp files consume space
- Find the largest relations
- Cap slot retention and alert early
Common mistakes
- Deleting WAL files by hand
- Only adding disk without finding the cause
Follow-ups
- What does max_slot_wal_keep_size do?
- How would you safely remove an old slot?
Tips
- Start with WAL and slots