Databases

PostgreSQL VACUUM stalls on partitioned table during heavy insert bursts; autovacuum appears idle

Environment

Environment

PostgreSQL 13 on Linux with a large partitioned table (range partitions by time). Insert workers perform high-concurrency inserts into the newest partition; autovacuum is enabled cluster-wide with default thresholds. Observed during nightly ingestion bursts.

Symptoms

Symptoms

VACUUM commands (manual and autovacuum) take extremely long or appear to spin without progress on certain partitions. I/O waits spike, CPU on bgwriter low, and long-running transactions appear in pg_stat_activity. Table bloat increases and queries slowed due to vacuum not reclaiming tuples.

Observations

Observations

pg_stat_activity shows several long-lived replica read queries and an ETL transaction that opened before the burst and never closed. pg_locks shows AccessShareLocks and some older transactions holding snapshots. Autovacuum workers are launched but show 'waiting' status and little IO. disk IO scheduler shows high queued writes to the partition device.

Already attempted

Already attempted

Tried manual VACUUM VERBOSE on affected partition — progress stalls. Increased maintenance_work_mem temporarily; set autovacuum_vacuum_scale_factor lower for that partition via ALTER TABLE. Considered pausing inserts but system needs near-real-time ingest.

Question

Question

What are the most likely causes of autovacuum stalling under heavy insert bursts on partitioned tables, and what safe operational steps let me restore vacuum progress without long service interruptions?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Long-lived open transactions (snapshot holders) prevent VACUUM from reclaiming tuples, making autovacuum effectively idle. 80%
Disk IO saturation from heavy insert workload causing vacuum worker IO to starve and make no progress. 60%
Insufficient autovacuum workers relative to many partitions; workers never reach all partitions in time. 45%

Summary

Autovacuum stalls often come from long-running transactions that hold old snapshots (preventing cleanup), resource contention (IO saturation), or insufficient autovacuum worker capacity for many partitions. Partitioned tables amplify the problem because each partition needs attention and concurrent inserts keep new partitions busy. Diagnostics: check pg_stat_activity for long transactions, pg_stat_progress_vacuum for worker progress, and OS IO metrics. Recovery steps: identify and terminate/commit blockers, throttle or schedule inserts to allow vacuum, increase autovacuum worker settings for high-partition counts, and target vacuum on idle partitions first. Avoid VACUUM FULL on busy systems as it's more disruptive.

Suggested Fixes

Diagnostic step 1
Check pg_stat_activity and pg_locks for open transactions that predate the inserts; if safe, ask owners to commit/close or terminate hung sessions.
Diagnostic step 2
Inspect pg_stat_progress_vacuum to see where workers are stuck and use pg_stat_io or iostat to check for IO saturation.
Diagnostic step 3
Temporarily throttle insert workers (reduce client concurrency or use traffic shaping) for a maintenance window to let vacuum catch up.

Continue troubleshooting

Matched from the title, description and tags