The official documentaion here seemed quite cryptic to me. https://www.postgresql.org/docs/13/routine-vacuuming.html#AUTOVACUUM
Can someone offer an explanation of what happens under the hood during autovacuum or manually triggerred vacuum?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.
Sign up to join this communityThe official documentaion here seemed quite cryptic to me. https://www.postgresql.org/docs/13/routine-vacuuming.html#AUTOVACUUM
Can someone offer an explanation of what happens under the hood during autovacuum or manually triggerred vacuum?
The autovacuum launcher process wakes up regularly and determines – based on the statistical data in pg_stat_all_tables
and pg_class
and certain parameters settings – if a table needs to be VACUUM
ed or ANALYZE
d. If yes, it starts an autovacuum worker process that performs the required operation.
VACUUM
does a lot of things. The basic procedure is:
scan the table for dead row versions
scan all indexes and remove references to these dead row versions
scan the table again to remove the dead row versions found in the first step
if we are not done with the table yet, repeat the whole process
On the side lines, it also does these things:
update table statistics in pg_class
bring the “free space map” up to date, so that INSERT
s and UPDATE
s know where to find a block with enough free space
bring the “visibility map” up to date, so that PostgreSQL can perform efficient index-only scans
“freeze” all live rows older than a certain age to allow the transaction ID counter to wrap around without data loss