PostgreSQL replica falls behind and reports WAL streaming delay when frequent autovacuum runs on primary
Environment
PostgreSQL 13 cluster: primary on cloud VM (8 vCPU, 32GB RAM), standby streaming replication over 1 Gbps link; autovacuum aggressive tuning with autovacuum_max_workers=20 and autovacuum_naptime=10s, several large partitioned tables with heavy UPDATE churn.
Symptoms
Standby replication_lag (pg_stat_replication) occasionally spikes to several minutes during nightly maintenance window; clients hitting the standby see stale data. Primary shows increased wal_sender delay and replica's replay_lag climbs. WAL shipping backpressure messages appear in primary logs during autovacuum bursts.
Observations
Primary disk I/O saturates while multiple autovacuum workers run concurrently: iostat shows >200% utilization (multiple vdevs), and checkpointer/background writer throughput increases. WAL generation rate spikes during autovacuum and update-heavy vacuum passes. Archive_command is synchronous but succeeding. Standby's walreceiver log shows 'server closed the connection' sometimes during peak I/O. autovacuum logs reveal long vacuum cycles on large partitions.
Already attempted
Reduced autovacuum_vacuum_cost_limit and increased cost_delay on primary to throttle autovacuum — replication lag improved but not fully eliminated. Increased wal_sender_timeout on primary. Temporarily paused non-critical autovacuum on biggest tables via ALTER TABLE SET (autovacuum_enabled = false) and manually scheduled throttled vacuums; lag decreased. No schema or logical replication changes made.
Question
How can I prevent autovacuum activity on the primary from causing WAL generation spikes that overwhelm standby replay capacity, while keeping table bloat under control? What configuration and operational changes are recommended?
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
- Databases37% match
PostgreSQL primary WAL sender CPU spikes and replication lag after enabling frequent TLS renegotiation on streaming replication
Open0 answers - Databases35% match
PostgreSQL replica stops streaming WAL after pg_repack on primary; replication slot reports missing WAL
Open0 answers - Databases33% match
PostgreSQL logical replication falls behind after ALTER TABLE ADD COLUMN with non-null DEFAULT on large table
Open0 answers - Databases27% match
PostgreSQL standby stops applying WAL during long-running transactions on primary after pg_basebackup restore
Open0 answers - Databases27% match
PostgreSQL logical replication slot grows until disk full after subscriber disconnects during nightly load
Open0 answers