PostgreSQL WAL archiving stalls during pg_basebackup when archive_command uses rsync over SSH
Environment
Primary: PostgreSQL 13.6 on Ubuntu 20.04, physical host with 1 Gbps NIC. archive_mode = on, archive_command = 'rsync --relative %p backup@backup-host:/data/pg_wal/%f'. pg_basebackup run from backup host to create base backup while WAL shipping active.
Symptoms
During pg_basebackup, WAL archiving appears to stall: primary's pg_wal directory accumulates files and pg_stat_archiver shows a growing backlog. archive_command exits with success in some cases but remote archive directory is missing files or shows partial transfers. Backups cannot complete while archiving is stalled, causing replication slot WAL retention to grow.
Observations
postgres log shows repeated archive attempts with no explicit error. rsync logs on backup host show abrupt connection resets for long files. Running rsync manually for one WAL file sometimes works, sometimes times out mid-transfer. Network captures show TCP retransmits and occasional connection resets during large file transfers coinciding with high disk IO on backup host. SSH keepalive options were not configured. Disk space on backup host had short spikes of near-fullness due to concurrent backups.
Already attempted
Increased log verbosity for archive_command and rsync. Retried base backup during off-peak hours (less disk pressure) and observed fewer failures. Switched archive_command to scp for a test — similar intermittent failures. Increased ssh ConnectionTimeout and added ServerAliveInterval/ServerAliveCountMax on backup host; saw improvement but not elimination of stalls. Considered using WAL streaming to backup host instead of rsync-based archiving.
Question
What are recommended, robust approaches for WAL archiving during concurrent base backups to avoid archiving stalls? Are there safe configuration changes (archive_command, SSH options, rsync flags, or alternate transport mechanisms) that reduce the chance of partial transfers and stuck archiving without risking WAL 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
- Databases38% match
PostgreSQL standby stops applying WAL during long-running transactions on primary after pg_basebackup restore
Open0 answers - Databases27% match
PostgreSQL WAL archiver fails with 'could not stat' after backup script replaced pg_wal with symlink
Open0 answers - Databases25% match
PostgreSQL replica stops streaming WAL after pg_repack on primary; replication slot reports missing WAL
Open0 answers - Databases25% match
WAL archiving stalls and primary reports 'could not flush file' during checkpoint under nightly bulk load
Open0 answers - Databases25% match
PostgreSQL WAL archiving fails with 'archive_command' permission denied after automated logrotate changed owner
Open0 answers