skip to content
14, 12 chapters
MVCC and vacuum

MVCC and vacuum

why an UPDATE writes a new row, who can see which version, and the vacuum that cleans up after everyone.

start part 14part 14 of 18, 12 chapters
  1. 14.01an UPDATE is an INSERTpostgres never overwrites a row. it writes a new version and stamps the old one with xmax.
  2. 14.02transaction ids, xmin and xmaxwho made this version and who ended it. virtual xids, lazy assignment, and SELECT xmin, xmax, ctid.
  3. 14.03snapshotsxmin, xmax and the in-progress list. three numbers that decide everything your query can see.
  4. 14.04the visibility rulesis this version visible to me? the whole decision as a flowchart, checked against real rows.
  5. 14.05the commit log and hint bitspg_xact, two bits per transaction, and the SELECT that dirties a page.
  6. 14.06HOT updates and pruningan update that skips every index, if the page has room and no indexed column changed.
  7. 14.07VACUUMremoving dead versions, cleaning indexes, and why the file doesn't shrink. VACUUM FULL and the bloat it fixes.
  8. 14.08autovacuumthresholds, scale factors, cost limits, and the busy table it never seems to reach.
  9. 14.09the xmin horizonone forgotten transaction and nothing gets cleaned. dead, but not yet removable.
  10. 14.10freezing and wraparound32-bit transaction ids go round in a circle. freezing, age(), and the shutdown nobody wants.
  11. 14.11MultiXactswhen several transactions lock one row at once. the other counter that can wrap.
  12. 14.12MVCC with undo logshow InnoDB and Oracle keep old versions in an undo log instead, and what each design pays.