The Hidden Engine Behind Your Transactions
Mastering MVCC in PostgreSQL
Nikhil Hegde, Stryv.ai
HYDERABAD POSTGRES DAYS 2025
Agenda
Overall Architecture of PostgreSQL
What Happens When You Do an INSERT?
Pages, Blocks, and the Shared Buffer
What Happens When You Do an INSERT?
Write-Ahead Log (WAL)
ID | NAME | BALANCE | CREATED_BY | DELETED_BY | LOCATION |
1 | AMAN | 500 | 750 | 0 | (3,1) |
2 | BAMAN | 200 | 751 | 0 | (3,2) |
System Columns
ID | NAME | BALANCE | CREATED_BY | DELETED_BY | LOCATION |
1 | AMAN | 500 | 750 | 0 | (3,1) |
2 | BAMAN | 200 | 751 | 0 | (3,2) |
System Columns
TX_ID 763
UPDATE accounts SET balance = balance - 100 WHERE id = 1
UPDATE accounts SET balance = balance + 100 WHERE id = 2
COMMITTED
ID | NAME | BALANCE | CREATED_BY | DELETED_BY | LOCATION |
1 | AMAN | 500 | 750 | 763 | (3,1) |
2 | BAMAN | 200 | 751 | 763 | (3,2) |
1 | AMAN | 400 | 763 | 0 | (3,3) |
2 | BAMAN | 300 | 763 | 0 | (3,4) |
System Columns
What happens when you do a DELETE
What happens when you do an UPDATE
CLOG (Commit Log)
Visibility and Access Control
Source : Rohan Reddy Alleti
Visibility and Access Control
Isolation Levels
Isolation Levels
2.REPEATABLE READ
Isolation Levels
3. SERIALIZABLE
Actual Meaning of MVCC
READERS DON’T BLOCK WRITERS, AND WRITERS DON’T BLOCK READERS
Indexing
Updating an Index – NON-HOT Update
HOT (Heap-Only Tuple) Update
Updating an Index
HOT Chains: Why They Can’t Cross Pages?
Vaccum
Source : Rohan Reddy Alleti
TRIGGER_POINT = AUTOVACUUM_VACUUM_THRESHOLD
+ AUTOVACUUM_VACUUM_SCALE_FACTOR × RELTUPLES
Vaccum
Vaccum FULL
Vaccum
VACUUM FULL
References
1. PostgreSQL Global Development Group.PostgreSQL Documentation (https://www.postgresql.org/docs/current/index.html).
2. Alleti, Rohan Reddy. Internals of MVCC in Postgres: Hidden Costs of Updates vs Inserts (https://medium.com/@rohanjnr44/internals-of-mvcc-in-postgres-hidden-costs-of-updates-vs-inserts-381eadd35844)
3. Nasser, Hussein. PostgreSQL YouTube Playlist.(https://youtube.com/playlist?list=PLQnljOFTspQWGrOqslniFlRcwxyY94cjj&si=Qa5ouj08WAhZk8-t)
4. Wolever, David. Postgres, MVCC, and You (or, Why COUNT() is Slow) (https://www.youtube.com/watch?v=GtQueJe6xRQ).
5. Pavlo, Andy. (2023). The Part of PostgreSQL We Hate the Most. Carnegie Mellon Database Group Blog. (https://www.cs.cmu.edu/~pavlo/blog/2023/04/the-part-of-postgresql-we-hate-the-most.html)
Thank you!
Any Questions ?
📌 Connect With Me:
linkedin.com/in/nikhilhegde989
www.nikhilhegde.com