What is MVCC

MVCC (Multi-Version Concurrency Control) is a concurrency mechanism where the database keeps multiple versions of each row so that readers don't block writers and writers don't block readers. Instead of locking a row while it is being modified, the database gives each transaction a consistent snapshot of the data as it existed at a specific point in time.

How it works

When a transaction updates a row, the database does not overwrite the existing version. Instead, it creates a new version tagged with the transaction's ID. The old version remains visible to any transaction that started before the update.

Each transaction sees a snapshot — a frozen view of the database at the moment the transaction began (or at each statement, depending on the isolation level). When transaction T1 reads a row that transaction T2 is updating, T1 sees the old version. T2's changes become visible only after T2 commits and T1 starts a new statement (read committed) or a new transaction (repeatable read).

PostgreSQL implements MVCC by storing old row versions directly in the table. Dead versions accumulate until VACUUM reclaims them. This is why VACUUM is important in PostgreSQL — without it, tables grow indefinitely with obsolete row versions.

InnoDB implements MVCC differently. It stores the current version in the table and keeps previous versions in the undo log. On rollback, the undo log restores the previous version. Old undo entries are purged automatically.

Both approaches achieve the same goal: high concurrency without read-write lock contention. The trade-off is storage overhead from maintaining multiple versions and the background cleanup work required to reclaim space.

Why it matters

MVCC is why modern databases handle concurrent workloads well. Without it, a long-running analytical query would block every write to the tables it reads, or vice versa. MVCC lets read-heavy and write-heavy workloads coexist on the same database without fighting over locks.

See How Transactions Work for the full explanation of isolation levels and snapshot visibility.