MVCC, snapshots and vacuum
Every UPDATE is an INSERT with a tombstone, and someone has to take the rubbish out before the transaction counter wraps
Session A runs BEGIN ISOLATION LEVEL REPEATABLE READ; SELECT count(*) FROM inventory; and then does nothing. Session B updates every row in inventory five times and runs VACUUM inventory. What does VACUUM remove?
A Postgres table is a heap of row versions, not a table of rows. Every row you have ever written is still there as a version until something removes it. The chapter on pages and the buffer pool showed where those versions live. This chapter is about the two numbers stamped on each one, how a transaction decides which versions it is allowed to see, and what has to happen to the versions nobody can see any more. The removal is called vacuum, and it is where most Postgres operational incidents come from.
Two numbers on every tuple
Each row version carries a header of 23 bytes before the data. Two fields in it matter here. xmin is the id of the transaction that inserted the version. xmax is the id of the transaction that deleted it or replaced it with a newer version, or zero if nobody has. Transaction ids are 32-bit integers handed out from a global counter to every transaction that writes.
You can read them. The system columns xmin, xmax and ctid are on every table:
SELECT ctid, xmin, xmax, product_id, on_hand FROM inventory WHERE product_id = 1;
An UPDATE does not touch the bytes of the old version. It writes a new version somewhere with room, with xmin set to the updating transaction and a new ctid, and stamps the old version’s xmax. A DELETE stamps xmax and writes nothing. A ROLLBACK does nothing to the heap at all: the transaction’s id is recorded as aborted in the commit log (pg_xact) and every version it created is dead from that moment, still on disk.
The rules for whether a version is visible to a transaction fall out of that. A snapshot is three things: the lowest transaction id that was still running when the snapshot was taken (xmin), one past the highest id that had finished (xmax), and the list of ids in between that were in progress. A transaction id is “in the snapshot” if it is below xmax, not in the in-progress list, and committed. A version is visible when its xmin is in the snapshot (or is the reader itself) and its xmax is zero, or belongs to a transaction that is not in the snapshot, or belongs to one that rolled back.
SELECT pg_current_snapshot(); -- e.g. 1203:1209:1203,1207
That output says: ids below 1203 are all finished, 1209 is the next id that will be handed out, and 1203 and 1207 are in progress. Anything committed with an id below 1209 other than those two is visible.
At READ COMMITTED, which is the default, every statement takes a fresh snapshot. At REPEATABLE READ and SERIALIZABLE, the transaction takes one snapshot at its first statement and keeps it. The next chapter is about what each choice lets through. For this chapter the point is that a snapshot held for an hour is an hour-old view of every table, and the engine has promised to keep that view answerable.
Watch it happen
The simulation below is this mechanism with one row and a handful of transactions. Each version is shown with its xmin and xmax. Run SNAPSHOT READ + ROLLBACK first and watch A keep reading 100 while B’s uncommitted 150 sits on top of it, then becomes dead when B rolls back. Then run NAIVE CHAIN: LOST UPDATE and FIX: FIRST-COMMITTER-WINS: snapshots make reads consistent, but they do nothing for a read-then-write unless the write checks that the version it is replacing is the newest one. The last two scenarios are the vacuum half of the story: VACUUM IGNORES OLD SNAPSHOT removes a version R still needs and R’s next read finds nothing, and FIX: VACUUM RESPECTS HORIZON keeps it and reports the horizon it stopped at.
MVCC (PostgreSQL-style, REPEATABLE READ: one snapshot per transaction;
PostgreSQL takes it at the first statement, this sim at BEGIN)
===================================================
Every version: value, xmin (creator txid), xmax (replacer txid or null)
Snapshot S = { txid, xmax: first txid not yet started, active: [in progress] }
sees(t, S) = t == S.txid OR (t < S.xmax AND t not in S.active AND committed(t))
visible(v, S) = sees(v.xmin, S) AND NOT (v.xmax AND sees(v.xmax, S))
READ: newest version visible to S. Never blocks, never sees uncommitted data.
WRITE (first-committer-wins):
cur = newest version whose creator did not abort
cur not visible to S? -> serialization failure, abort
cur.xmax set by a live/committed txn? -> serialization failure, abort
else cur.xmax = me; append { value, xmin: me, xmax: null }
(PostgreSQL waits on a live writer's row lock instead: it fails if that
writer commits and proceeds if it aborts. This sim aborts at once.)
ROLLBACK: nothing is undone in place. The version stays, dead.
VACUUM: horizon = oldest txid any active snapshot may consider running
remove v if creator aborted, or xmax committed AND xmax < horizon
one long transaction holds the horizon back: dead versions pile up (bloat) Writes use the naive chain: an UPDATE stacks a new version on whatever the transaction read, with no conflict check. A adds 50, B subtracts 30, starting from 100. Both commit. Order the steps so the balance does not end at 120.
GOAL: both commit and a committed update is lost
The simulation calls the write rule first-committer-wins. Postgres’s version is first-updater-wins: when an UPDATE at REPEATABLE READ finds that the version it wants to replace has an xmax from a transaction that is still running, it waits. If that transaction rolls back, the update proceeds. If it commits, the update fails with ERROR: could not serialize access due to concurrent update, SQLSTATE 40001, and your application must retry the whole transaction. At READ COMMITTED the same situation does not error: the update waits, then re-evaluates its WHERE clause against the newest version and proceeds. That difference is the subject of the next chapter.
Dead tuples, and who removes them
A version that no live or future snapshot can see is dead: it was replaced or deleted by a committed transaction older than every current snapshot, or created by one that rolled back. It occupies space on its page, its line pointer occupies space in the page header, and any index entries that point at it are still there. A sequential scan still reads the page it is on. An index scan still follows the pointer, reads the tuple header, and discards it.
Postgres has two mechanisms to remove dead versions. The first is HOT pruning, which happens on a page during ordinary reads and writes when the page is getting full. It is cheap because it is local to one page and it does not touch indexes, and it is the reason a hot row updated a thousand times a second does not grow a thousand-version chain. HOT is described in its own section below, because it has conditions.
The second is VACUUM. A plain VACUUM on a table does, in order: scan the heap, skipping pages the visibility map says have no dead tuples, and collect the ctids of dead versions; scan every index and remove entries pointing at those ctids; return to the heap and mark the line pointers as free; freeze old tuples (next section); update the free space map and the visibility map; and truncate any wholly empty pages at the end of the file. It takes a SHARE UPDATE EXCLUSIVE lock, which conflicts with other vacuums and with schema changes but not with SELECT, INSERT, UPDATE or DELETE, so it runs under production traffic.
What VACUUM does not do is shrink the table. Freed space is recorded in the free space map and reused by later inserts and updates, but the file stays the size it reached. A table that bloated to 3 GB and was vacuumed is a 3 GB file that is two-thirds free space. Only VACUUM FULL (or CLUSTER, or pg_repack) returns space to the operating system, by rewriting the whole table and its indexes into new files. That rewrite needs as much free disk as the live data, and it holds an ACCESS EXCLUSIVE lock on the table for its entire duration, which blocks every reader and writer. On a 50 GB table that is minutes of downtime for that table. VACUUM FULL is a repair, not maintenance. The decision at the end of this chapter is about when it is the right repair.
Since Postgres 17, VACUUM keeps the dead ctids in a compact radix tree rather than a flat array, and is no longer silently capped at 1 GB of memory for that structure whatever maintenance_work_mem says. The practical effect is that a vacuum of a large table with many dead tuples does one pass over the indexes instead of several. If you see index_vacuum_count above 1 in pg_stat_progress_vacuum, maintenance_work_mem (default 64 MB) is too small for that table.
The horizon
VACUUM decides what is dead by computing a horizon: the oldest xmin of any snapshot that anyone is holding. Everything replaced by a transaction older than that is removable. Everything replaced by a younger transaction is “dead but not yet removable”, and VACUUM VERBOSE tells you how many there are and which xmin is holding the line:
tuples: 0 removed, 300000 remain, 250000 are dead but not yet removable
removable cutoff: 1187, which was 5 XIDs old when operation ended
Four things hold the horizon back, and they are the four things to check when n_dead_tup climbs and vacuum runs but does not help.
A long transaction, which includes an idle one. A session that ran BEGIN an hour ago and has not committed holds a snapshot if it is at REPEATABLE READ or above, and even at READ COMMITTED it holds its backend_xmin if it has a statement in flight. Find them:
SELECT pid, state, age(backend_xmin) AS xmin_age,
now() - xact_start AS open_for, left(query, 60) AS query
FROM pg_stat_activity
WHERE backend_xmin IS NOT NULL
ORDER BY age(backend_xmin) DESC;
The state idle in transaction is the one to fear: a client opened a transaction and is doing something else. idle_in_transaction_session_timeout (default 0, disabled) kills such sessions after the given time, and Postgres 17 adds transaction_timeout to bound a transaction’s total life whether idle or not. Set them per role for application users, not globally for the DBA’s psql.
A replication slot. A physical standby with hot_standby_feedback = on (default off) sends its own oldest xmin to the primary so that vacuum does not remove rows the standby’s queries still need; a standby running a long report pins the primary’s horizon. A logical slot holds catalog_xmin. Both are visible in pg_replication_slots:
SELECT slot_name, active, age(xmin) AS xmin_age, age(catalog_xmin) AS catalog_age
FROM pg_replication_slots;
An inactive slot whose consumer was decommissioned and never dropped holds the horizon forever.
A prepared transaction left behind by a failed two-phase commit, in pg_prepared_xacts. And a long-running VACUUM on another table, which itself holds a snapshot.
Postgres 17 removed old_snapshot_threshold, which let vacuum remove rows a long transaction might need and fail that transaction later with “snapshot too old”. There is no longer a way to make the engine break its promise to a snapshot. The only cure for a held horizon is to end the holder.
Transaction id wraparound and freezing
Transaction ids are 32 bits. The counter wraps after about 4.3 billion ids, and the visibility rules compare ids by modular arithmetic: of any two ids, the one “in the past” is the one within 2 billion behind. A tuple whose xmin is 2.1 billion transactions old would suddenly be in the future, and invisible, to every new snapshot. Rows would vanish.
The defence is freezing. When VACUUM finds a tuple whose xmin is older than vacuum_freeze_min_age (default 50 million transactions) and is visible to everyone, it sets a flag in the tuple header that means “the inserter committed so long ago that it is visible to every possible snapshot”. The actual xmin value stops mattering. Pages where every tuple is frozen get an all-frozen bit in the visibility map, and future vacuums skip them.
Each table records the oldest unfrozen xmin it might contain in pg_class.relfrozenxid, and each database records the minimum across its tables in pg_database.datfrozenxid. The number to watch is the age of that value:
SELECT datname, age(datfrozenxid) FROM pg_database ORDER BY 2 DESC;
SELECT c.oid::regclass AS table_name, age(c.relfrozenxid) AS age,
pg_size_pretty(pg_total_relation_size(c.oid)) AS size
FROM pg_class c WHERE c.relkind IN ('r', 'm', 't')
ORDER BY age(c.relfrozenxid) DESC LIMIT 10;
Three thresholds matter. When a table’s relfrozenxid passes autovacuum_freeze_max_age (default 200 million), autovacuum launches an anti-wraparound vacuum of that table whether or not the table has dead tuples, and whether or not autovacuum is disabled for it. When the oldest datfrozenxid comes within 40 million transactions of wraparound, every command logs WARNING: database "shop" must be vacuumed within N transactions. At 3 million, Postgres refuses to assign new transaction ids: ERROR: database is not accepting commands that assign new transaction IDs to avoid wraparound data loss. Reads still work. Writes do not, until a vacuum has advanced datfrozenxid, and on a multi-terabyte table that vacuum takes hours. That is the Mandrill outage.
An anti-wraparound vacuum on a table with billions of rows is the slowest vacuum there is, because it cannot skip pages that are not yet all-frozen. Since Postgres 14 there is a failsafe: when a table’s age passes vacuum_failsafe_age (default 1.6 billion), the running vacuum drops its cost-based delay and skips index cleanup to finish as fast as possible. Do not plan on it. Plan on alerting when any age(datfrozenxid) passes 500 million, and on knowing which table is responsible.
Autovacuum and its knobs
Autovacuum is a launcher process that wakes every autovacuum_naptime (default 1 min), looks at the statistics for every table in one database, and starts up to autovacuum_max_workers (default 3) workers across the whole cluster. A table is vacuumed when its estimated dead tuples exceed:
autovacuum_vacuum_threshold + autovacuum_vacuum_scale_factor × reltuples
with defaults of 50 and 0.2. On a 50 000-row table that is 10 050 dead tuples. On a 2 000 000-row orders table it is 400 050, and on a 500 million-row table it is 100 million dead tuples before anything happens: a fifth of the table is garbage before autovacuum notices. The scale factor is the knob that scales wrongly, and the standard fix for large tables is a per-table override:
ALTER TABLE orders SET (
autovacuum_vacuum_scale_factor = 0.01, -- 1%
autovacuum_vacuum_threshold = 10000
);
Insert-only tables have their own pair, autovacuum_vacuum_insert_threshold (1000) and autovacuum_vacuum_insert_scale_factor (0.2), so that append-only logs still get frozen and their visibility map set. Analyze has a third pair with scale factor 0.1.
The second knob is speed. Autovacuum is throttled: each page it touches costs points (vacuum_cost_page_hit 1, vacuum_cost_page_miss 2, vacuum_cost_page_dirty 20) and when the sum reaches autovacuum_vacuum_cost_limit (default -1, meaning use vacuum_cost_limit, 200) the worker sleeps for autovacuum_vacuum_cost_delay (default 2 ms). Those defaults allow 200 points per 2 ms: at 20 points per dirtied page that is 10 pages, or about 40 MB/s of pages vacuum can dirty. That sounds like a lot until a 500 GB table needs a full pass, which takes hours, and the budget is shared across all running workers, so three workers each get a third of it. On any server with real write volume, raise autovacuum_vacuum_cost_limit to 1000 or more or lower the delay, and do it per table for the tables that need it:
ALTER TABLE inventory SET (autovacuum_vacuum_cost_delay = 0);
Watch what autovacuum did with log_autovacuum_min_duration (default 10 min; set it to 0 while you tune so every run is logged with its tuple counts and timing) and with the per-table statistics:
SELECT relname, n_live_tup, n_dead_tup,
round(100.0 * n_dead_tup / greatest(n_live_tup + n_dead_tup, 1), 1) AS dead_pct,
last_autovacuum, autovacuum_count,
n_tup_upd, n_tup_hot_upd
FROM pg_stat_user_tables
ORDER BY n_dead_tup DESC LIMIT 10;
n_dead_tup is an estimate maintained by the statistics collector, not a count; pgstattuple in the lab gives the exact figure by reading the table. A running vacuum shows up in pg_stat_progress_vacuum with its phase and how many heap blocks and indexes it has processed.
The failure mode to recognise: autovacuum runs, often, on the same table, and n_dead_tup does not fall. That is a held horizon, not an autovacuum problem, and no tuning fixes it. The second failure mode: autovacuum never seems to reach a table at all, and the log shows the three workers permanently busy on three huge tables. That is a cost limit problem or a worker count problem, and autovacuum_max_workers needs a restart to change.
HOT: the update that skips the indexes
Every new row version gets a new ctid, and every index on the table points at ctids. So in the general case an update of one column means a new entry in every index on the table, including indexes on columns that did not change, and later a vacuum of every one of those indexes. A table with eight indexes pays eight index writes per update. This is the write amplification that Uber’s 2016 post about leaving Postgres complained of, and it is real.
Heap-only tuples are the exception that makes Postgres usable for update-heavy rows. If the update changes no indexed column, and there is room on the same page as the old version, the new version goes on that page and no index is touched: the old version’s line pointer becomes a redirect to the new one, and index entries that point at the old ctid still find the row. A chain of heap-only versions on one page is pruned by any later visit to that page once the old versions are dead, without a vacuum. The two conditions are the two knobs. Do not index columns you update constantly, and give hot tables a fillfactor below 100 so pages have room:
ALTER TABLE inventory SET (fillfactor = 80);
VACUUM FULL inventory; -- fillfactor applies to pages written after the change
The shop’s inventory table has one index, the primary key on product_id, and the column that changes is on_hand. Every update of it is HOT-eligible, and pg_stat_user_tables.n_tup_hot_upd against n_tup_upd tells you how many actually were. Postgres 16 added n_tup_newpage_upd for the ones that were not because the page was full.
Reading the symptoms
Put together, this is the checklist when a Postgres database is “slowly getting slower”:
| symptom | query | likely cause |
|---|---|---|
n_dead_tup high and rising, last_autovacuum recent |
pg_stat_user_tables |
horizon held: check pg_stat_activity.backend_xmin, pg_replication_slots, pg_prepared_xacts |
n_dead_tup high, last_autovacuum old or null |
pg_stat_user_tables |
threshold too high for the table size, or workers saturated: lower the scale factor, raise the cost limit |
| table size far above live data | pgstattuple, pg_total_relation_size |
past bloat already vacuumed; only a rewrite shrinks it |
age(datfrozenxid) above 500 million |
pg_database |
anti-wraparound vacuum not keeping up; find the oldest table and vacuum it by hand with the cost delay off |
n_tup_hot_upd far below n_tup_upd |
pg_stat_user_tables |
an index on an updated column, or no room on the page: drop the index or lower fillfactor |
sessions idle in transaction for minutes |
pg_stat_activity |
application holds transactions open across network calls; set idle_in_transaction_session_timeout on its role |
Each row of that table is a lab step below.
You will pin the vacuum horizon with an idle transaction, bloat inventory five-fold, measure the exact damage with pgstattuple, release the horizon, and then make autovacuum notice the table within a minute. The atlas user is the database owner, so it can create extensions and alter tables.
1. Baseline. In terminal 1, open psql and record the table’s size and tuple layout before anything happens.
docker compose exec db psql -U atlas shopCREATE EXTENSION IF NOT EXISTS pgstattuple;
SELECT pg_size_pretty(pg_relation_size('inventory')) AS heap,
tuple_count, dead_tuple_count, round(free_percent::numeric, 1) AS free_pct
FROM pgstattuple('inventory');
SELECT n_live_tup, n_dead_tup, n_tup_upd, n_tup_hot_upd, last_autovacuum
FROM pg_stat_user_tables WHERE relname = 'inventory';n_dead_tup 0 and last_autovacuum from when the loader ran, or null. Keep this terminal; you will re-run these two queries after every step.2. Pin the horizon. In terminal 2, open a second psql and start a transaction that takes a snapshot and then does nothing.
BEGIN ISOLATION LEVEL REPEATABLE READ;
SELECT count(*) FROM inventory;
SELECT pg_current_snapshot();
-- leave this session open and idle50000 and a snapshot like 1412:1412: (no transactions in progress). This session is now idle in transaction and holds a snapshot whose xmin pins the horizon for the whole database.3. Bloat. Back in terminal 1, replace every row five times, then vacuum.
UPDATE inventory SET on_hand = on_hand + 1;
UPDATE inventory SET on_hand = on_hand + 1;
UPDATE inventory SET on_hand = on_hand + 1;
UPDATE inventory SET on_hand = on_hand + 1;
UPDATE inventory SET on_hand = on_hand + 1;
VACUUM (VERBOSE) inventory;tuples: 0 removed, 300000 remain, 250000 are dead but not yet removable and removable cutoff: <xid>, which was N XIDs old. The cutoff is terminal 2’s snapshot. Re-run the step 1 queries: the heap is now around 15 MB, dead_tuple_count is 250 000, and n_tup_hot_upd is a fraction of n_tup_upd because a full page has no room for a heap-only version, so most new versions went to new pages.4. Find the culprit the way you would in production. Still in terminal 1:
SELECT pid, state, age(backend_xmin) AS xmin_age, now() - xact_start AS open_for,
left(query, 50) AS last_query
FROM pg_stat_activity WHERE backend_xmin IS NOT NULL AND pid <> pg_backend_pid();idle in transaction, xmin_age of about 5 (one transaction id per UPDATE), open_for a few minutes, and the last query it ran. In production that row is the one you message the owner of, or terminate with pg_terminate_backend(pid).5. Release and vacuum. In terminal 2, COMMIT;. In terminal 1:
VACUUM (VERBOSE) inventory;
SELECT pg_size_pretty(pg_relation_size('inventory')) AS heap,
tuple_count, dead_tuple_count, round(free_percent::numeric, 1) AS free_pct
FROM pgstattuple('inventory');tuples: 250000 removed, 50000 remain. dead_tuple_count is 0 and free_pct is around 80, but the heap is still about 15 MB: VACUUM made the space reusable and did not give it back. Run VACUUM FULL inventory; and re-check: back to about 2.6 MB. Note that VACUUM FULL took an ACCESS EXCLUSIVE lock; try SELECT 1 FROM inventory LIMIT 1 from terminal 2 while it runs on a larger table and it blocks.6. Tune autovacuum for this table. The default threshold for 50 000 rows is 10 050 dead tuples, and autovacuum wakes once a minute. Make it react to 1% and run unthrottled, then make 1000 dead tuples and wait.
ALTER TABLE inventory SET (
autovacuum_vacuum_scale_factor = 0.01,
autovacuum_vacuum_threshold = 100,
autovacuum_vacuum_cost_delay = 0
);
UPDATE inventory SET on_hand = on_hand + 1 WHERE product_id <= 1000;
SELECT now(), n_dead_tup, last_autovacuum, autovacuum_count
FROM pg_stat_user_tables WHERE relname = 'inventory';
\watch 10n_dead_tup reads about 1000 immediately. Within 60 to 70 seconds last_autovacuum jumps to the current time, autovacuum_count increments, and n_dead_tup drops to 0. Press Ctrl-C to stop watching. Without the ALTER, 1000 dead tuples would sit there until the count reached 10 050. Check the server log (docker compose logs db | grep -i autovacuum) after setting ALTER SYSTEM SET log_autovacuum_min_duration = 0; SELECT pg_reload_conf(); to see each run’s tuple counts.7. HOT, and the fillfactor. Measure how many of the single-row updates are heap-only, then give the pages room.
SELECT n_tup_upd, n_tup_hot_upd, n_tup_newpage_upd FROM pg_stat_user_tables WHERE relname = 'inventory';
ALTER TABLE inventory SET (fillfactor = 80);
VACUUM FULL inventory;
UPDATE inventory SET on_hand = on_hand + 1 WHERE product_id % 50 = 0;
SELECT n_tup_upd, n_tup_hot_upd, n_tup_newpage_upd FROM pg_stat_user_tables WHERE relname = 'inventory';n_tup_newpage_upd. After the rewrite at 80%, nearly all of the 1000 new updates (three or so per page, spread across the table) are counted in n_tup_hot_upd: no index was touched and the dead versions on those pages will be pruned by the next visit, with no vacuum. The price is 20% more pages for the same rows.ALTER TABLE inventory SET (autovacuum_enabled = false);, run the five whole-table updates from step 3 again without any idle transaction, and watch n_dead_tup sit at 250 000 for as long as you like. Then look at age(relfrozenxid) for the table: autovacuum is off, but if that age ever reached autovacuum_freeze_max_age an anti-wraparound vacuum would run on it anyway, because that is the one thing the setting cannot disable. Before you leave, put the table back the way the loader made it: ALTER TABLE inventory RESET (autovacuum_enabled, autovacuum_vacuum_scale_factor, autovacuum_vacuum_threshold, autovacuum_vacuum_cost_delay, fillfactor); VACUUM FULL inventory;. The next chapters assume a healthy table with default settings.The shop's orders table has grown to 40 GB on disk while pg_stat_user_tables says it holds 9 GB of live rows. A six-month-old reporting replica with hot_standby_feedback on was found and fixed last week, so dead tuples are now being removed, but the file has not shrunk. Queries that scan the table are four times slower than they should be. The table is written to constantly and the shop must stay up. What do you do about the 31 GB?
- DOC Routine Vacuuming
The official account of what VACUUM does, the autovacuum threshold formula, freezing, and the exact wraparound thresholds (40 million warning, 3 million refusal). Read sections 24.1.1 to 24.1.6 in full; skip the multixact section until you need it.
- BOOK PostgreSQL 14 Internals Egor Rogov, 2022
The best long-form explanation of Postgres MVCC in print, with page dumps showing xmin and xmax changing under your eyes. Free PDF. Part I covers everything in this chapter; the version is 14 but the mechanism has not changed. Read: Part I: Isolation, Pages and Tuples, Snapshots, Page Pruning and HOT Updates, Vacuum and Autovacuum, Freezing.
- PAPER Architecture of a Database System Hellerstein, Stonebraker and Hamilton, 2007
Puts Postgres's choice in context: section 6 surveys concurrency control and recovery across engines, and explains why a multi-version engine needs a garbage collector where an in-place engine needs an undo log. Skip sections 2 to 5 for now; they belong to later chapters. Read: section 6, Transactions: Concurrency Control and Recovery.
- POST Transaction ID Wraparound in Postgres Sentry, 2015
A short, honest post-mortem of a wraparound outage: autovacuum tuned too conservatively, one large table never finished, writes stopped for most of a day. Read it for the decision they made under pressure (truncate a table) and whether you would have made it.
- POST What We Learned from the Recent Mandrill Outage Mailchimp, 2019
The same mechanism four years later at larger scale: about 40 hours of impaired sending. Useful for the recovery timeline, which shows how long a forced vacuum of a huge table takes once writes have already stopped.
- DOC pgstattuple
The extension the lab uses. The exact meaning of each column, and pgstattuple_approx for tables too large to scan in full. Two pages; read all of it.
- POST Why Uber Engineering Switched from Postgres to MySQL Evan Klitzke, 2016
The famous critique of Postgres's write amplification: every non-HOT update touches every index. Read the section on the on-disk format and the update example; the replication arguments are out of date. Then read the HOT section of this chapter again and decide how much of it still applies to a table with one index.
- PAPER An Empirical Evaluation of In-Memory Multi-Version Concurrency Control Wu, Arulraj, Lin, Xian and Pavlo, 2017
The design space Postgres sits in one corner of: append-only versus delta versus time-travel version storage, and tuple-level versus transaction-level garbage collection. Read sections 4 and 5 to see what the alternatives to vacuum look like; the benchmarks in section 7 are optional. Read: sections 4 (Version Storage) and 5 (Garbage Collection).
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.