PostgreSQL WAL backlog and standby lag after nightly bulk UPDATE with synchronous rsync archive_command
Environment
PostgreSQL 13.4 primary and one streaming standby on Debian 11 VMs. Primary configured with archive_mode = on, archive_command runs a shell wrapper that rsyncs WAL files to an S3 gateway appliance. Nightly bulk UPDATE job touching ~200M rows starts at 02:00 and lasts ~3–4 hours.
Symptoms
Standby falls behind during the bulk update. WAL files accumulate on primary (pg_wal grows), wal_sender processes show high CPU and some WAL segments remain needed by the replication slot for multiple hours; disk usage on primary creeping toward full.
Observations
pg_stat_replication shows standby state frequently 'streaming' but replay_lag increases; archive_command logs show intermittent timeouts/exit code non-zero when rsync to S3 gateway times out under high write churn. Manually running the archive_command for queued WAL files sometimes succeeds. No long-running user transactions on standby. The WAL sender CPU spikes correlate with archive_command failures.
Already attempted
Paused the bulk load job briefly and retried archive_command; increased checkpoints temporarily; ran manual rsync to the S3 gateway which succeeded for some WAL files; restarted WAL sender process — backlog persisted until network to S3 gateway stabilized. Did not disable archiving because archival retention policy must be preserved.
Question
What is the most likely cause of the WAL accumulation and standby lag during the bulk update, and what safe, reversible mitigations let replication catch up without data loss or violating retention policy?
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 replica falls behind and reports WAL streaming delay when frequent autovacuum runs on primary
Open0 answers - Databases21% match
PostgreSQL standby stops applying WAL during long-running transactions on primary after pg_basebackup restore
Open0 answers - Databases21% match
PostgreSQL 14: Rapid table bloat after nightly batch UPDATEs despite autovacuum enabled
Open0 answers - Databases20% match
WAL archiving stalls and primary reports 'could not flush file' during checkpoint under nightly bulk load
Open0 answers - Databases20% match
PostgreSQL logical replication slot grows until disk full after subscriber disconnects during nightly load
Open0 answers