MVCC in PostgreSQL Database
MVCC (Multi-Version Concurrency Control) in PostgreSQL allows multiple users to access the same data without blocking each other.
Instead of locking rows, PostgreSQL keeps multiple versions of a row.
The Problem MVCC Solves
In traditional databases (lock-based systems):
- Read can block write
- Write can block read
- Leads to slow performance & waiting
PostgreSQL avoids this by:
- Never modifying rows in place
- Creating new versions of rows
 Why MVCC?
- Avoids read locks
- Improves performance
- Supports concurrent transactions
How MVCC Works (Concept)
When you update a row:
- Old row version is not deleted immediately
- New row version is created
- Each transaction sees data based on its snapshot
Key Internals
- Each row has:
xmin→ transaction ID that created the rowxmax→ transaction ID that deleted/updated the row
SELECT xmin, xmax, * FROM student_mvcc;
Dead Rows & VACUUM
Old versions remain in table → called dead tuples
To clean them:
VACUUM emp;





