Primary PostgreSQL WAL directory fills after interrupted base backup and failing archive_command
Environment
PostgreSQL 14 on Ubuntu 20.04 as primary: streaming replication to two standbys, WAL archiving to S3 via external wal-e process (archive_command calls wal-e); a pg_basebackup run from 02:00 failed midway due to network outage; archive_command runs as postgres user; disk usage at 92% of /var/lib/postgresql/14/main/pg_wal.
Symptoms
pg_wal directory accumulates many WAL segments and does not purge. Archive logs show lines like 'archive_command failed: exit code 1', and archive_status/*.ready files exist, preventing WAL removal. Standbys are disconnected and report needing older WAL segments.
Observations
pg_stat_archiver shows repeated failed archive attempts; pg_stat_replication shows no connected replicas after the outage; wal_e logs show permission denied to S3 due to rotated credentials on the archival container. Manual deletion of WAL segments attempted but PostgreSQL refuses to start if missing files.
Already attempted
Restarted archive agent, restored S3 credentials temporarily (failed due to credential rotation history), attempted pg_archivecleanup on segments older than last known required LSN (operation refused because replicas may still need them), considered deleting .ready files but hesitated.
Question
What is the safe procedure to reclaim WAL space without breaking replication or corrupting backups when a base backup was interrupted and archiving is failing?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Databases47% match
PostgreSQL standby stops applying WAL after pg_basebackup restore — replication slot grows and disk fills
Open0 answers - Databases39% match
PostgreSQL WAL archiving stalls during pg_basebackup when archive_command uses rsync over SSH
Open0 answers - Databases39% match
PostgreSQL standby stops applying WAL during long-running transactions on primary after pg_basebackup restore
Open0 answers - Databases36% match
PostgreSQL replica stops streaming WAL after pg_repack on primary; replication slot reports missing WAL
Open0 answers - Databases32% match
PostgreSQL logical replication slot grows and WAL accumulates after logical decoding plugin crashes on high-write primary
Open1 answer