skip to content
15, 10 chapters
locks and concurrency control
everything.locking

locks and concurrency control

serializability theory, two-phase locking, postgres's lock manager, and the SSI that catches write skew.

start part 15part 15 of 18, 10 chapters
  1. 15.01schedules and serializabilitywhat correct means for interleaved transactions. conflicts, precedence graphs and cycles.
  2. 15.02two-phase lockinggrow, then shrink. why 2PL guarantees serializability, and strict 2PL avoids cascading aborts.
  3. 15.03table lock modeseight modes from ACCESS SHARE to ACCESS EXCLUSIVE, and the matrix that decides who waits.
  4. 15.04how row locks are storedfour strengths, kept in the tuple header instead of the lock table. pgrowlocks shows them.
  5. 15.05watching locks with pg_lockspg_locks, pg_blocking_pids, and one query that shows who's blocking whom.
  6. 15.06the lock queuea long SELECT, an ALTER TABLE behind it, and every query behind that frozen. lock_timeout saves the day.
  7. 15.07inside the deadlock detectorwait-for graphs, deadlock_timeout, soft edges, and how a victim gets chosen.
  8. 15.08latches, spinlocks and LWLocksthe short locks that protect memory, not rows. why they never show up in pg_locks.
  9. 15.09timestamp ordering and OCCconcurrency control without locks: order by timestamp, or validate at the end and abort.
  10. 15.10serializable snapshot isolationSIRead locks, rw-antidependencies, and the dangerous structure that gets you a 40001.