awesome-everything RU
↑ Back to the climb

Databases

MVCC and isolation: multiple-choice review

Crux Multiple-choice synthesis across the MVCC unit — snapshot visibility, isolation-level tradeoffs, write skew vs lost update, bloat pinning, and XID wraparound.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 14 min

Six questions that cut across the whole unit. Each one mirrors a call you make in a real incident — which isolation level, why autovacuum is stuck, what the 40001 actually means — not a definition to recite.

Goal

Confirm you can connect snapshot visibility, isolation-level choice, the anomalies each level allows, bloat pinning, and wraparound — the synthesis the seven lessons built toward.

Quiz

Connection B runs this under READ COMMITTED while connection A commits an UPDATE between the two statements: ```sql -- B: BEGIN; SELECT balance FROM accounts WHERE id = 42; -- returns 100 -- (A commits: UPDATE accounts SET balance = 0 WHERE id = 42) SELECT balance FROM accounts WHERE id = 42; -- returns ? ``` What does the second SELECT return, and why?

Quiz

An app reads a row, computes a new value in code, and writes it back. Two requests race: ```sql -- both sessions, concurrently: BEGIN; SELECT stock FROM items WHERE id = 7; -- both read 10 -- app computes 10 - 1 = 9 UPDATE items SET stock = 9 WHERE id = 7; COMMIT; ``` Under the default isolation level the final stock is 9, not 8. What is this and what is the minimal fix?

Quiz

A doctors table has the invariant 'at least one doctor on_call'. Two transactions run under REPEATABLE READ: ```sql -- T1: -- T2 (concurrent): SELECT count(*) FROM doctors SELECT count(*) FROM doctors WHERE on_call; -- 2 WHERE on_call; -- 2 UPDATE doctors SET on_call=false UPDATE doctors SET on_call=false WHERE name='alice'; WHERE name='bob'; COMMIT; COMMIT; ``` Both commit; now zero doctors are on call. What happened and which level prevents it?

Quiz

Autovacuum has run for 30 minutes on a 200 GB orders table and logs '287 million are dead but not yet removable, oldest xmin: 28391456'. n_dead_tup is not dropping. What is the root cause and the first thing you check?

Quiz

A bank's two-account transfer reads both balances, debits one, credits the other. The DBA proposes READ COMMITTED with SELECT ... FOR UPDATE on both rows (locked in a consistent order) instead of SERIALIZABLE, which is 5x slower at peak. Is that correct?

Quiz

A workload does heavy SELECT ... FOR KEY SHARE (the implicit lock from foreign-key checks) and hits an autovacuum wraparound warning much sooner than its transaction throughput would predict. Which counter is the constraint?

Recap

The through-line of the unit is one visibility rule and the choices stacked on it. Snapshots decide what each transaction sees (per-statement under READ COMMITTED, per-transaction under REPEATABLE READ). The isolation level decides which anomalies you own: RC leaves lost updates to the app, REPEATABLE READ raises 40001 on concurrent row updates but still allows write skew, SERIALIZABLE adds SSI to catch write-skew cycles. The storage tax — dead tuples — is reclaimed by autovacuum only up to the global oldest xmin, so a long transaction or orphan slot is the first suspect for runaway bloat. And the 32-bit XID and MultiXact counters both demand freezing before wraparound. Pick the weakest level that still protects your invariant, then defend the bound.

Continue the climb ↑MVCC and isolation: free-recall review
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.