PostgreSQL replica accumulates WAL and stalls after archive_command ownership changed during maintenance
Environment
Primary and standby on Ubuntu 20.04. Primary PostgreSQL 12.8 with streaming replication and archive_command writing WAL files to /var/lib/pgsql/archive owned by postgres:postgres. Admin ran maintenance and temporarily changed owner of archive directory to root; archive_command now runs via postgres user but fails to write.
Symptoms
Standby shows increasing 'replay' lag; primary's pg_wal directory grows until disk nearly full. Replication slot on primary grows in size and WAL segments are not removed. New connections to standby succeed but replication apply stalls with no clear error.
Observations
Primary log shows repeated 'archive command failed' errors with 'could not open file: Permission denied' for WAL segments. archive_mode=on and archive_timeout set. archive_command returns non-zero; WAL segments accumulate. Standby reports 'waiting for WAL to be archived' in pg_stat_replication state.
Already attempted
Restored ownership to postgres:postgres but left restrictive permissions (700) on archive parent directories; restarted postgres on primary; archive_command still intermittently fails for some WAL files. Ran pg_archivecleanup tests manually as postgres user; some files write fine, others fail.
Question
How to safely recover replication to streaming remove accumulated WAL, ensure archive_command reliably archives WAL again, and reclaim disk without data loss?
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
- Databases42% match
PostgreSQL WAL archiving fails with 'archive_command' permission denied after automated logrotate changed owner
Open0 answers - Databases41% match
Primary PostgreSQL WAL directory fills after interrupted base backup and failing archive_command
Open0 answers - Databases39% match
PostgreSQL replica stops streaming WAL after pg_repack on primary; replication slot reports missing WAL
Open0 answers - Databases39% match
PostgreSQL replica falls behind and reports WAL streaming delay when frequent autovacuum runs on primary
Open0 answers - Databases39% match
PostgreSQL logical replication slot grows and WAL accumulates after logical decoding plugin crashes on high-write primary
Open1 answer