Limit the WAL that slots can retain (max_slot_wal_keep_size)
PostgreSQLReplicationCommand
ALTER SYSTEM SET max_slot_wal_keep_size = '100GB';
SELECT pg_reload_conf();
SELECT slot_name, active, wal_status, pg_size_pretty(safe_wal_size) AS safe_wal_size FROM pg_replication_slots;What it does
Sets an upper bound on the WAL that replication slots can keep in pg_wal (default -1 = unlimited); when exceeded, checkpoint removes old WAL and the slot becomes wal_status = 'lost'. The parameter takes effect with a reload.
When to use it
As a safeguard on every cluster that uses slots, against the risk of a disconnected standby or subscriber filling the primary's disk and stopping the whole system.
Caution
The limit favors keeping the primary alive at the expense of the slot owner: a standby with a 'lost' slot must be rebuilt and a logical subscription recreated. Choose a value below the free space of the pg_wal disk but larger than the WAL generated during the longest expected outage. If wal_status is 'unreserved' the slot is about to be lost; raise an alert.