What is MVCC in PostgreSQL?

IntermediateConceptPostgreSQL
Answer

Short answer

MVCC (Multi-Version Concurrency Control) means PostgreSQL keeps multiple versions of a row instead of overwriting it. An UPDATE writes a new row version and marks the old one as dead. Each transaction sees a consistent snapshot, so readers never block writers and writers never block readers.

How it plays out

  1. Transaction A starts reading orders.
  2. Transaction B updates order 42 and commits → a new version of row 42 is written.
  3. A still sees the old version (its snapshot), B and new transactions see the new one.
  4. Later, when no transaction needs the old version, VACUUM cleans it up.

Why DevOps cares

  • Dead rows accumulate → table and index bloat unless autovacuum keeps up.
  • Long-running transactions (an open BEGIN in someone's psql session, a stuck report) prevent cleanup of everything newer — the database grows and slows.
SELECT pid, state, now() - xact_start AS age, query
FROM pg_stat_activity WHERE xact_start IS NOT NULL ORDER BY age DESC LIMIT 5;

What to say in the interview

"MVCC keeps row versions so each transaction sees a snapshot and reads don't block writes. The cost is dead tuples that VACUUM must remove, so I watch autovacuum and kill long-running or idle-in-transaction sessions that block cleanup."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: PostgreSQL basics

More on PostgreSQL