PostgreSQL warns of imminent transaction-id wrap after bulk DELETEs — autovacuum not preventing anti-wraparound
Environment
PostgreSQL 13.6 on Debian 11, primary server handling nightly ETL that massively deletes rows from partitioned table; autovacuum configured with multiple workers but uses low cost limits to avoid IO impact.
Symptoms
Server logs show repeated 'transaction ID wraparound' warnings and anti-wraparound cleanup requests. Autovacuum jobs run but take very long; autovacuum launch doesn't keep pace with high churn, and VACUUM can't finish before new transactions create more new XIDs.
Observations
VACUUM VERBOSE shows many pages to scan; autovacuum_cost_limit set low; maintenance_work_mem default small; CPU and IO used modestly due to cost delays. Manual VACUUM FREEZE on affected partitions completes but is slow. No crashes yet, but pg_stat_all_tables shows high n_dead_tup counts.
Already attempted
Increased autovacuum_max_workers, lowered autovacuum_vacuum_cost_delay temporarily, attempted manual VACUUM FREEZE during low load window; partial relief. Considered taking a scheduled downtime for full VACUUM but need safer immediate mitigation steps.
Question
What safe changes will stop anti-wraparound warnings and allow autovacuum to keep up without causing major I/O disruption for production load?
Verified community troubleshooting
Don't wait for wraparound. During a low-load window run VACUUM FREEZE on the affected partitions (vacuumdb or VACUUM (VERBOSE, FREEZE) per partition). Then temporarily make autovacuum more aggressive: raise autovacuum_max_workers, increase autovacuum_vacuum_cost_limit and reduce autovacuum_vacuum_cost_delay, and bump maintenance_work_mem so VACUUM can finish faster. Verify by watching pg_stat_all_tables (n_dead_tup drop) and server logs for anti-wrap messages. Roll back cost settings after cleanup if IO becomes problematic. If you can't run VACUUM now, coordinate a maintenance window and notify DBAs to avoid forced emergency downtime.
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Databases30% match
PostgreSQL 14: Rapid table bloat after nightly batch UPDATEs despite autovacuum enabled
Open0 answers - Databases29% match
PostgreSQL bulk INSERT throughput collapses on partitioned table after stats collector restart
Open0 answers - Databases29% match
PostgreSQL VACUUM stalls on partitioned table during heavy insert bursts; autovacuum appears idle
Open0 answers - Databases28% match
PostgreSQL autovacuum CPU spikes and accelerating table bloat after lowering autovacuum_vacuum_cost_delay
Open0 answers - Databases28% match
PostgreSQL replica SQL apply thread stalls 'waiting for table metadata lock' after large ALTER TABLE on primary
Open0 answers