A practical checklist for PostgreSQL autovacuum lag
When an update-heavy queue or job-status table grows far larger than its live row count, default autovacuum thresholds are usually too lazy to keep up.
1. Check for old snapshots first
Autovacuum cannot reclaim dead tuples newer than the oldest open transaction. Before tuning anything, inspect pg_stat_activity for sessions stuck in idle in transaction.
2. Lower per-table thresholds on hot tables
The default autovacuum_vacuum_scale_factor = 0.2 waits until 20% of a table is dead. On a 10M-row table, that is two million dead rows before a vacuum even starts.
ALTER TABLE job_runs SET (
autovacuum_vacuum_scale_factor = 0.01,
autovacuum_vacuum_threshold = 1000,
autovacuum_analyze_scale_factor = 0.005
);
Combining per-table thresholds with a strict idle_in_transaction_session_timeout keeps table size predictable without scheduling downtime for VACUUM FULL.