PostgreSQL MVCC and Isolation Level Deep Dive

A 5-question reference set on PostgreSQL's MVCC implementation: tuple versioning, READ COMMITTED vs REPEATABLE READ vs SERIALIZABLE, row-level locks, and the autovacuum machinery that keeps txid wraparound at bay.

Question Bundle
Python
sql
database
concurrency
interview-prep

By CodeSnatch

April 20, 2026

·

Updated August 14, 2026

669 views

13

4.4 (16)

In PostgreSQL MVCC, every row update creates a new tuple version. Walk through what pg_attribute_xmin and xmax look like before and after a single UPDATE, and explain why concurrent readers do not block.

Examples

Example 1:

Input: SELECT balance FROM accounts WHERE id = 1;   -- xmin=100, xmax=0
       UPDATE accounts SET balance = 50 WHERE id = 1;   -- transaction 101
Output: Old tuple now has xmin=100, xmax=101; new tuple has xmin=101, xmax=0
Explanation: The UPDATE writes a new tuple version and stamps the old one with the deleting xact id.

Example 2:

Input: Concurrent SELECT in transaction 102 (started after 101 but before 101 commits)
Output: Returns balance from the old tuple (xmin=100, xmax=101 not yet visible to 102)
Explanation: Visibility is determined by snapshot: tuples are visible if xmin <= snapshot_xmin and xmax > snapshot_xmin (or xmax is a still-running xact).

4 more questions and all solutions are locked.

Purchase this item to access all questions, code snippets, and solutions.