Dead Tuples and the MVCC Tax
How Postgres's row-versioning model creates lock-free reads, the background maintenance that keeps it solvent, and the catastrophic failure mode that waits at the end if that maintenance falls behind. Index internals live in the companion guide — this one is about transactions, cleanup, and the planner that sits on top of both.
What Is a Dead Tuple?
Every row stored in a Postgres heap file is called a tuple. When you UPDATE or DELETE a row, Postgres does not overwrite it. It writes a new version and marks the old one as dead. This is the foundation of Postgres's concurrency model: Multi-Version Concurrency Control (MVCC).
What Happens at the Storage Level During an UPDATE
Postgres heap files are divided into 8 KB pages. Each page contains tuple headers followed by tuple data. Every tuple header carries two critical fields:
| Field | Meaning |
|---|---|
xmin | XID of the transaction that created this tuple |
xmax | XID of the transaction that deleted or superseded this tuple (0 if still live) |
Both tuples coexist on disk. The old tuple's xmax is stamped with the updating transaction's XID. The new tuple gets a fresh xmin.
The Visibility Rule
When transaction T reads a row, it applies this check to each tuple it encounters:
A tuple is visible to transaction T if:
xmin committed AND xmin <= T's snapshot XID
AND (xmax = 0 OR xmax >= T's snapshot XID OR xmax aborted)This lets a long-running SELECT see a consistent snapshot of the database as it existed at its start time — even while concurrent writers are modifying rows. No read locks needed. That is the entire point of MVCC.
-- Inspect xmin/xmax directly
SELECT ctid, xmin, xmax, id, balance
FROM accounts
WHERE id = 1;
-- ctid | xmin | xmax | id | balance
-- -------+------+------+----+---------
-- (0,1) | 100 | 500 | 1 | 100 ← dead (xmax set)
-- (0,2) | 500 | 0 | 1 | 200 ← livectid is the physical location: (page, slot).
How Dead Tuples Accumulate and Bloat Pages
Every UPDATE and DELETE leaves a dead tuple behind. Because heap pages are fixed at 8 KB, pages fill up with dead tuples and Postgres must scan more pages to find the same number of live rows.
| Scan type | Dead tuple impact |
|---|---|
| Sequential scan | Postgres reads every page. Dead tuples waste I/O — you read 100 pages but only 20% of tuples are live. |
| Index scan | The index points to a physical ctid. If the ctid is a dead tuple, Postgres fetches the heap page, discovers the tuple is dead, then follows the HOT chain to the live version. Extra heap fetches = extra I/O. |
ASCII: Bloated page
[ dead | dead | dead | live | dead | live | dead | dead ]
↑ 75% of this page is wasted space, still read on every scan