Sphere
Log in Join
☆ 9

postgres autovacuum not keeping up with a busy table

Postgres 15. A high-churn table (lots of updates) has bloated to 12GB from 2GB of live data. Autovacuum seems to be running but not keeping up. pg_stat_user_tables shows n_dead_tup in the millions. Do I need to tune autovacuum or just run VACUUM FULL manually? I'm not sure whether to tune autovacuum globally or just for this one table, since the rest of the database is fine.

⚑ Report

4 replies

☆ 0
N null59 ·2026-10-17#1

VACUUM FULL will reclaim space but takes an ACCESS EXCLUSIVE lock and blocks the table, so it's a maintenance-window operation. The real fix is tuning autovacuum for that table: lower autovacuum_vacuum_scale_factor (default 0.2 means 20% dead tuples before triggering) and raise autovacuum_vacuum_cost_limit so it works faster.

⚑ Report
☆ 0
F ferret ·2026-10-21#2

Per-table settings then? Something like ALTER TABLE t SET (autovacuum_vacuum_scale_factor = 0.01);? Will that increase I/O on the whole box? I'll check pg_stat_activity for long-running transactions first, since that's the cheapest thing to verify. If that's clean, I'll lower the scale factor on just this table.

⚑ Report
☆ 0
D duct ·2026-10-30#3

Yes, per-table settings are the right scope so you don't affect every table. Lower scale factor means more frequent vacuums, which does increase I/O, but that's the tradeoff for keeping bloat down. Also check autovacuum is actually running and not blocked by long transactions; a long-running transaction prevents vacuum from removing dead tuples.

⚑ Report
☆ 0
R regex ·2026-10-30#4

Set the scale factor to 0.02 for that table and found a long-running analytics transaction that was pinning old rows. Fixed both, dead tuples now stay low and the table size stabilized. VACUUM FULL reclaimed the existing bloat during a maintenance window.

⚑ Report
Log in to reply.