dataiotech Labs
Scripts Library/postgresql/#13
Script #13
postgresql
Replicationread-onlyMin Version: 10

PostgreSQL Replication Slots and Retained WAL

Shows inactive slots and the WAL they retain. Critical for preventing an abandoned slot from filling the disk.

#replication-slot#wal#disk-full
postgresql · sql
SELECT slot_name, slot_type, active, restart_lsn,
       pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_wal
FROM pg_replication_slots
ORDER BY pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) DESC NULLS LAST;
Operational Notes & Remediation Guidance

Inactive replication slots retain WAL files on disk indefinitely, risking complete filesystem saturation.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 10).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.

Engineering Triad: Related Runbooks & Incident Response

Which production incidents and emergency drills execute this script as a diagnosis step?

Runbook Library (63)
Related Alerts & Metrics
M3PostgreSQL Replication Lag (Seconds)PostgreSQL
M4PostgreSQL WAL Retained by Replication SlotsPostgreSQL
M12PostgreSQL Data and WAL Disk Free SpacePostgreSQL