What is MVCC in PostgreSQL

· Category: SQL & Databases

Short answer

MVCC (Multi-Version Concurrency Control) allows PostgreSQL to handle concurrent transactions by keeping multiple versions of a row, enabling readers and writers to coexist without blocking each other.

How it works

When a row is updated, PostgreSQL creates a new version rather than overwriting the old one. Each transaction sees a snapshot of the database at its start time. Old versions are eventually removed by the VACUUM process.

Example

Transaction A reads a row while Transaction B updates it. A sees the pre-update version, and B sees its own new version. Neither blocks the other.

Why it matters

MVCC eliminates the need for read locks in most scenarios, improving throughput. It supports multiple isolation levels, with READ COMMITTED and REPEATABLE READ as common choices.r