PostgreSQL Enterprise (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
PostgreSQL MVCC: Multi-Version Concurrency Control, Dead Tuples, and Table Bloat.
senior LevelDatabases & SQLPostgreSQL
In Simple Words: PostgreSQL handles concurrent reads and writes without blocking each other using MVCC (Multi-Version Concurrency Control):
- How it Works: An
UPDATEdoes not overwrite the existing row in-place. Instead, it marks the old row version ("dead tuple") with an expiration transaction ID (xmax) and writes a completely new row version with an insertion transaction ID (xmin). - Dead Tuples & Bloat: Dead tuples remain on disk until cleaned up. If high-update tables are not vacuumed promptly, dead tuples accumulate, causing "table bloat" where sequential scans read gigabytes of obsolete data.