Full answer
How to confirm:
pg_stat_user_tablesshowsn_dead_tupand the last autovacuum time for the table.pg_stat_activityshows old transactions (xact_start) or sessionsidle in transaction; their snapshot keeps dead rows visible, so VACUUM cannot remove them.- Abandoned replication slots and prepared transactions have the same effect.
Fixes:
- Lower
autovacuum_vacuum_scale_factorfor the hot table so vacuum runs after a fixed number of changes rather than 20 percent of the table. - Kill or fix long transactions; set
idle_in_transaction_session_timeout. - Reclaim existing bloat: plain VACUUM makes space reusable but rarely shrinks the file;
VACUUM FULLrewrites the table under an exclusive lock, whilepg_repackdoes it online. - Reduce churn: HOT updates (when no indexed column changes and the page has free space) avoid index bloat, so a lower
fillfactorcan help.
These are PostgreSQL-specific behaviours described here, not run.
Key points
- UPDATE creates dead row versions
- VACUUM reclaims them, unless old snapshots block it
- Tune autovacuum per hot table
- VACUUM FULL locks; pg_repack works online
- HOT updates reduce index churn
Common mistakes
- Running VACUUM FULL at peak time
- Ignoring idle-in-transaction sessions
Follow-ups
- What is transaction ID wraparound?
- How does fillfactor help HOT updates?
Tips
- Name the long-transaction cause