Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Performance & internals
Stage 5: Specialization

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:

  1. Readers never block writers, writers never block readers. A long report SELECT and a stream of UPDATEs coexist; each sees its own consistent world.
  2. Writers block writers — on the same row. Two UPDATEs to one row queue up (that's the row lock, section 6).
  3. 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.

  1. Under MVCC, what does an UPDATE physically do?
  2. Who pays for the old versions, and when?
Show the answers
  1. Writes a new row version and expires the old one — no in-place overwrite.
  2. 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.

Search the guide