PostgreSQL Enterprise (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What are Dead Tuples, Table Bloat, and why is `VACUUM` required?
senior LevelSystem DesignPostgreSQL
In Simple Words:
- Dead Tuples: Obsolete row versions left behind after updates and deletes that are no longer visible to any active transaction.
- Table Bloat: Accumulation of millions of dead tuples consuming disk space and inflating index sizes, forcing queries to scan unnecessary pages.
VACUUM: Reclaims space occupied by dead tuples:- Standard
VACUUM: Marks dead tuple space as reusable for futureINSERTs without locking the table. VACUUM FULL: Rewrites the entire table into a new clean file on disk to shrink physical file size, but acquires an exclusive table lock (ACCESS EXCLUSIVE) that blocks all reads and writes!
- Standard