Database Internals

Why PostgreSQL Uses MVCC Instead of Locking

11 min readยทMay 21, 2026

What MVCC Solves

In a lock-based system, a reader blocks a writer. MVCC eliminates this entirely.

How It Works

Every row in Postgres has two hidden columns: xmin (transaction that created it) and xmax (transaction that deleted it). When you update a row, Postgres does not modify it in place. It marks the old row deleted and inserts a new version. Both coexist briefly.

Snapshots

Every transaction gets a snapshot โ€” a list of which transaction IDs were active when it started. A row is visible only if it was created by a committed transaction before your snapshot, and not deleted by one. Readers see a consistent point-in-time view. Writers create new versions. They never collide.