PostgreSQL / Editorial solution guide
Diagnose retained WAL and replication-slot pressure
Identify why write-ahead logs are retained and restore consumer progress without discarding required recovery data.
Read-only knowledge base · No public comments
Recognize the symptoms
The filesystem containing pg_wal is growing, free space is falling, or a standby or logical consumer is lagging. The same symptoms can have several causes, including a stalled replication slot or an archiving problem. Capture the observation time, affected server, free-space trend, and consumer impact rather than assuming that every retained file is unnecessary.
Understand the likely causes
- A replication slot can retain WAL needed by its consumer while that consumer is stopped or behind. Failed archiving, WAL generation rate, checkpoint behavior, retention settings, and other consumers can also affect disk use. PostgreSQL exposes slot progress and WAL availability; the exact columns and settings depend on the server version.
Measure the pressure and identify the owner
Confirm the primary or standby identity, PostgreSQL version, filesystem free space, growth rate, write workload, and current service impact from authorized monitoring. Determine how much response time remains under the incident procedure. Identify each physical or logical consumer and its owner, and record whether it is active and making progress. Avoid publishing private host names or application data.
Inspect slot status and relevant replication and archiving evidence using privileges already authorized for monitoring. Compare multiple observations at known times: a single LSN or inactive flag does not explain why progress stopped or how fast disk space is being consumed.
SELECT slot_name, slot_type, active, restart_lsn, confirmed_flush_lsn, wal_status
FROM pg_replication_slots
ORDER BY slot_name;
This read-only query shows selected slot fields. Interpret NULL values and WAL status using the manual for the actual server version; no result is assumed. Access and visibility depend on the authorized environment.
Separate a stalled consumer from other retention
Compare the slot’s restart position and status over time with the consumer’s own logs and connectivity. For logical consumers, confirmed progress is a separate observation from the oldest WAL that may still be required. Check archiver failures and the configured retention policy as independent possibilities. A slot with no obvious owner must be investigated before action; it may support a standby, change-data capture, or recovery workflow.
Restore progress with a bounded procedure
Follow the incident procedure to restore the affected consumer, address archiving or resource pressure, and provide capacity where appropriate. Assess the consequences with the consumer owner before changing retention or removing a slot: the consumer may lose WAL needed to continue and require a documented rebuild or resynchronization. A configured slot WAL limit trades disk protection against the possibility that a lagging consumer loses required files. Never delete files directly from pg_wal as an improvised cleanup.
Verify both disk and consumer recovery
Observe free space, WAL generation, slot progress, and the consumer’s receive and apply or processing state over multiple intervals. Confirm that the application’s freshness and recovery objectives are met and that archiving succeeds where required. A falling directory size alone does not prove that a consumer can resume safely. Document ownership, alert on sustained lag and disk pressure, and rehearse consumer rebuild and backup restoration in an isolated environment.
Verify the fix
Free space stabilizes and the relevant consumer advances without reported missing-WAL errors over an observed interval.
The application freshness and required archive or recovery checks meet the documented objectives.
Keep it from recurring
- Assign an owner and lag, disk-space, and archive monitoring to each required consumer.
- Test recovery and resynchronization procedures before altering slot retention or removing a slot.