Module 1 · Storage
Episode 9 Lab: I Deleted Half the Table and It Got Bigger
▶ This video is coming to YouTube soon.
We updated every row of a 100,000-row Postgres table, deleted half of them, and watched it grow from 5 MB to 11 MB. This lab reproduces it, shows the dead tuples page by page, then fixes it twice: VACUUM makes the space reusable (proved with pg_freespacemap), and VACUUM FULL shrinks the table to 3 MB under an ACCESS EXCLUSIVE lock that blocks every other query.
Chapters
- 0:00Intro
- 0:14The symptom
- 0:34Reproduce it
- 1:20Diagnose: UPDATE writes a second copy
- 2:18Diagnose: DELETE only marks
- 2:40Why the file can't just shrink
- 3:11Fix 1: VACUUM makes the space reusable
- 3:59Fix 1 on Postgres: VACUUM
- 4:29Fix 2: VACUUM FULL rewrites the table
- 5:08Fix 2 on Postgres: VACUUM FULL
- 5:19The price: ACCESS EXCLUSIVE
- 6:04Before and after
- 6:24Which fix, when
- 6:58Recap
- 7:25Next: B+ Trees: Search and Insert