PostgreSQL replica lag grows after nightly rsync base backups and manual WAL copy workflow
Environment
Primary PostgreSQL 13 on Linux writes ~2 TB/day; nightly 'rsync' used to copy data directory while DB running, followed by manual copy of recent WAL segments into archive-restore area on replica. Replica uses streaming but often falls behind and slot WAL accumulates.
Symptoms
Replica WAL apply lag increases over hours after each nightly job; replication slot size grows and pg_wal on primary increases until alerts. Manual replay on replica shows 'invalid record' and timeline gaps requiring rebase.
Observations
Rsync backup is not crash-consistent; primary continued running during copy. Archive command sometimes fails to find matching WAL filenames. Replica reports missing WAL segments and later reports checksum/invalid record errors. pg_basebackup wasn't used. Primary autovacuum and load unchanged.
Already attempted
Switched archive_command to a reliable remote-copy during the window, attempted base backup from snapshot LVM afterwards, and tried replaying missing WAL manually — some WAL segments rejected. Stopped rsync job and tested pg_basebackup on a smaller dataset successfully.
Question
Why does using rsync for live base backups cause replica WAL gaps and invalid WAL records, and how should we fix replication and prevent WAL accumulation without long downtime?
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
- Databases35% match
PostgreSQL replica falls behind and reports WAL streaming delay when frequent autovacuum runs on primary
Open0 answers - Databases31% match
PostgreSQL replica stops streaming WAL after pg_repack on primary; replication slot reports missing WAL
Open0 answers - Databases30% match
PostgreSQL WAL archiving stalls during pg_basebackup when archive_command uses rsync over SSH
Open0 answers - Databases30% match
PostgreSQL logical replication slot grows until disk full after subscriber disconnects during nightly load
Open0 answers - Databases30% match
PostgreSQL replica SQL apply thread stalls 'waiting for table metadata lock' after large ALTER TABLE on primary
Open0 answers