🐘 PostgreSQL
Intermediate
What is MVCC in PostgreSQL?
Answer
MVCC (Multi-Version Concurrency Control) is PostgreSQL's mechanism for handling concurrent access without read locks. Instead of locking rows when they are read, PostgreSQL keeps multiple versions of each row. Each transaction sees a consistent snapshot of the database from the time it started — readers don't block writers, writers don't block readers. Row versions are stored as heap tuples with xmin (transaction that created it) and xmax (transaction that deleted/updated it) system columns. Old row versions become "dead tuples" after the transactions that need them finish. VACUUM reclaims space from dead tuples. MVCC enables high concurrency but requires periodic vacuuming to prevent table bloat and transaction ID wraparound.