Skip to main content
InterviewHubPRO
Section Overview
Q11

Question 11 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

22%
PostgreSQL Enterprise (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

How does Multi-Version Concurrency Control (MVCC) work internally in PostgreSQL?

senior LevelCode ExampleSystem DesignDatabases & SQLPostgreSQL

In Simple Words: PostgreSQL implements MVCC by retaining historical tuple versions directly inside table data pages (Heap files):

  • Every table row header contains hidden transaction metadata:
    • xmin: The Transaction ID (txid) of the transaction that created/inserted the row.
    • xmax: The Transaction ID of the transaction that deleted or updated the row (0 for live active rows).
  • Update Mechanism: In PostgreSQL, an UPDATE does not overwrite data in place! It marks the existing row with xmax = current_txid (soft delete) and inserts a completely new row tuple with xmin = current_txid!
  • Readers compare xmin and xmax against their transaction snapshot to determine row visibility without locking.
text
PostgreSQL Update via MVCC:
[Old Tuple: Row 1] ──► Header: xmin = 100, xmax = 105 (Marked Deleted by Tx 105)
                             │ Pointer to new version (t_ctid)
                             ▼
[New Tuple: Row 1'] ──► Header: xmin = 105, xmax = 0   (Active live row!)