FULL AI ANALYSIS

PostgreSQL autovacuum CPU spikes and accelerating table bloat after lowering autovacuum_vacuum_cost_delay

Generated Oct 21, 2026, 9:46:27 AM

Analysis summary

Setting autovacuum_vacuum_cost_delay very low makes autovacuum work more continuously and aggressively, which can increase CPU and worker churn (autovacuum spawns frequently, contends with user queries) and paradoxically accelerate bloat metrics if vacuum can't complete or is constantly preempted. The root is an imbalance between autovacuum aggressiveness, cost limits, maintenance_work_mem, and the rate of update/delete churn on large tables. Other contributors can be too-low autovacuum_vacuum_scale_factor/threshold for heavy-write tables and insufficient maintenance_work_mem causing many small passes rather than efficient vacuums.

Possible causes

autovacuum_vacuum_cost_delay set too low causing autovacuum to run aggressively and steal CPU cycles while not finishing tasks efficiently

92%

maintenance_work_mem too small so each vacuum workset is split into many I/O-bound passes increasing total overhead

68%

autovacuum settings (scale_factor/threshold) not tuned for high-churn tables, causing repeated vacuums on hot partitions

55%

Long-running transactions preventing vacuum from reclaiming space; autovacuum repeatedly visiting dead tuples but cannot clean them

40%

Suggested fixes

1

Diagnostic step 1

Restore autovacuum_vacuum_cost_delay to a conservative value (e.g., 20ms), monitor CPU and autovacuum log frequency for 1–2 hours.

2

Diagnostic step 2

Increase autovacuum_vacuum_cost_limit and maintenance_work_mem moderately (e.g., maintenance_work_mem to 256–1024MB depending on available RAM) so vacuums can batch more work per pass.

3

Diagnostic step 3

Lower autovacuum_vacuum_scale_factor for the largest/high-write tables or add table-level autovacuum settings to run less frequently but with larger cost limits.

4

Diagnostic step 4

Identify long-running transactions (pg_stat_activity) and address them. Consider scheduling manual VACUUM (not FULL) on badly bloated partitions during low hours.

5

Diagnostic step 5

After changes, watch pg_stat_progress_vacuum, pg_stat_user_tables relfrozenxid and n_dead_tup to confirm reduced bloat and fewer repeated vacuums.