PostgreSQL WAL archiver fails with 'could not stat' after backup script replaced pg_wal with symlink
Environment
PostgreSQL 13.5 running on Ubuntu 20.04 LTS; primary host: db-primary (4 vCPU, 8GB RAM); WAL archive_command used to copy files to /backups/wal; nightly filesystem snapshot job runs on secondary storage
Symptoms
WAL archiving stopped; primary emitted repeated archive errors and stopped recycling WAL segments; replication to standby stalled within 15 minutes of the issue appearing.
Observations
postgres log lines: "archive_command 'cp %p /backups/wal/%f' failed with exit code 1" and later "could not stat file "/var/lib/postgresql/13/main/pg_wal/0000000100000001000000A1": No such file or directory". ls -l /var/lib/postgresql/13/main/pg_wal shows pg_wal is a symlink to /mnt/wal_store/pg_wal; /mnt/wal_store is on an ext4 LVM snapshot target created by a cron job. The snapshot job replaced /mnt/wal_store with a new mount and recreated /mnt/wal_store/pg_wal as an empty directory, leaving the pg_wal symlink pointing to now-missing files. cp run manually on an existing WAL file fails with "No such file or directory". Owner and permissions on /backups/wal are postgres:postgres, 700.
Already attempted
Restarted PostgreSQL service (systemctl restart postgresql) — service started but archiving still failed. Verified standby still caught up only after manually copying missing WAL files from an older snapshot. Temporarily disabled archive_command in postgresql.conf and restarted to stop error spam. Inspected backup cron that manages snapshots but did not modify it yet.
Question
What is the safest way to restore WAL archiving quickly and prevent the snapshot job from breaking pg_wal again without compromising WAL integrity or losing replication continuity?
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
- Databases23% match
PostgreSQL WAL archiving fails with 'archive_command' permission denied after automated logrotate changed owner
Open0 answers - Databases22% match
Logical backups hang waiting for locks when VACUUM FULL is running on large PostgreSQL tables
Open0 answers - Databases21% match
PostgreSQL WAL archiving stalls during pg_basebackup when archive_command uses rsync over SSH
Open0 answers - Databases21% match
PostgreSQL logical replication slot grows until disk full after subscriber disconnects during nightly load
Open0 answers - Databases21% match
PostgreSQL standby stops applying WAL during long-running transactions on primary after pg_basebackup restore
Open0 answers