Sobes.tech
Middle+

What is MVCC in PostgreSQL and how do isolation levels work?

sobes.tech AI

Answer from AI

MVCC (Multiversion Concurrency Control) in PostgreSQL is a mechanism for managing concurrent access to data without read locks. Each transactional query sees its own 'snapshot' of data, allowing reading data without waiting for other transactions to complete.

PostgreSQL stores multiple versions of rows with different xmin/xmax (transaction identifiers) to determine which versions are visible to the current transaction.

Isolation levels in PostgreSQL:

  • Read Committed (default) — a transaction sees only changes that were committed before each individual query started.
  • Repeatable Read — a transaction sees the same snapshot of data throughout its execution, even if other transactions modify data.
  • Serializable — the strictest level, providing full isolation, preventing anomalies of concurrent access, sometimes through transaction rollback.

Example: at the Repeatable Read level, if you read a row and another transaction modifies and commits it, you will not see these changes until your transaction completes.