Part 12 / Topic 3 of 9
MVCC: why readers don't block writers
Postgres handles concurrency with multi-version concurrency control: an UPDATE doesn't overwrite a row — it writes a new version and marks the old one as expired. Each transaction reads the versions that were current in its snapshot. Consequences, in order of how often they'll matter to you:
- Readers never block writers, writers never block readers. A long report SELECT and a stream of UPDATEs coexist; each sees its own consistent world.
- Writers block writers — on the same row. Two UPDATEs to one row queue up (that's the row lock, section 6).
- Old versions pile up. Expired row versions ("dead tuples") are garbage-collected later by VACUUM — the Stage 4 lesson where MVCC's bill arrives.
You can see version bookkeeping on any row — xmin is the id of the transaction that created this row version:
SELECT xmin, product_id, name FROM products WHERE product_id = 2; -- output varies per run
xmin | product_id | name
------+------------+---------------
1952 | 2 | Laptop Air 13
(1 row)
Update the row and xmin changes — because you're looking at a different, newer row version. (The number itself varies per cluster; the lesson is that it changes.)
🧪 Quick quiz — answer from memory, then check.
- Under MVCC, what does an UPDATE physically do?
- Who pays for the old versions, and when?
Show the answers
- Writes a new row version and expires the old one — no in-place overwrite.
- VACUUM reclaims dead versions later (Stage 4); until then they occupy space.
Done here? The practice set for Part 12 — 6 exercises with solutions — is on the part page.