#why-vacuum
Why do you need VACUUM, and what exactly does it do?
What to say
Every UPDATE and DELETE leaves a dead row version. It is no longer visible to anyone but still takes up space in the page. VACUUM walks the table, finds versions invisible to any live snapshot, and frees their slots for reuse. The space stays with the table, but holes appear inside the pages for new rows. Along the way it updates the free space map (FSM) and the visibility map (VM), trims line pointers, and advances freezing. A plain VACUUM does not return space to the file system and runs without blocking writes.
What they want to hear
A senior should: - explain that vacuum reuses space inside the table rather than returning it to the OS (only `VACUUM FULL` does that) - tie "what can be removed" to the horizon: versions older than the oldest live snapshot are removed - name the side tasks: updating the FSM/VM, freezing, trimming pointers - know that a plain vacuum does not block SELECT/UPDATE and takes only a light lock
Pitfalls
- ✗ Saying "VACUUM frees disk space". A plain vacuum reuses space inside the table, and only `VACUUM FULL` returns disk to the OS
- ✗ Thinking vacuum removes any dead version. Only those older than the horizon
- ✗ Assuming vacuum blocks writes. The plain mode runs online
Follow-up
- ? How does VACUUM differ from VACUUM FULL in its effect on disk?
- ? Which row versions is vacuum not allowed to remove?
- ? Why does vacuum touch the FSM and VM?
Depth in knowledge base