FULL AI ANALYSIS

PostgreSQL replica lag grows after nightly rsync base backups and manual WAL copy workflow

Generated Oct 29, 2026, 9:46:59 AM

Analysis summary

Rsync of a live data directory produces an inconsistent base backup: files change while copying, leading to WALs that reference pages not matching the copied data. Replicas expect a consistent base backup (from pg_basebackup or filesystem snapshot with the database offline or LVM snapshot) plus continuous WAL stream. The manual copying of WALs can't reconcile page-level mismatches, resulting in invalid record/replay failures. WAL accumulation occurs because replicas wait for WAL that references a different base state and cannot apply it.

Possible causes

Use of rsync on a live data directory producing an inconsistent base backup leading to mismatched WAL and data pages

95%

Archive_command timing issues leaving gaps if WAL segments rotated during copy and not atomically archived

55%

Replica replay settings/timeline confusion when base backup and WALs come from different timelines or missing checkpoint info

45%

Disk corruption causing sporadic invalid WAL records (less likely given correlation with rsync runs)

10%

Suggested fixes

1

Diagnostic step 1

Stop using rsync on the live cluster. Create a consistent base backup using pg_basebackup or take an LVM/ZFS snapshot while pausing writes or using the database's online backup facility.

2

Diagnostic step 2

Set up continuous WAL archiving with a robust archive_command that writes WAL segments atomically (use tempfile+rename pattern) to remote storage.

3

Diagnostic step 3

To repair replica: promote to recovery from a fresh base backup plus continuous WAL stream or rebuild replica using pg_basebackup from primary.

4

Diagnostic step 4

Implement monitoring/alerts for replication slot size and archive_command failures so WAL accumulation is detected early.