Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 01 · Database Internals · One Database, to the Bolt · with code: Python · about 28 min to read

Play it as a journeyTutor comes with a plan

The Database That Won’t Answer

Locks, Latches & Transactions
Locks, Latches & Transactions · Open board

The queries waiting on each other, drawn side by side with the engine’s own split-second holds. This lesson is what you do when one of those queues has frozen a real app and nobody yet knows which one.

Before you start. The last seven lessons opened one database a layer at a time: a table is a pile of 8 KB pages (Pages & Heap Files), an index is a sorted tree that finds a row in a few page reads (B-Tree on Disk), an update leaves the old row behind for vacuum to sweep up (MVCC & Vacuum), the planner bets on a plan from a small summary of each table (The Query Planner), and a lock makes one query wait for another’s whole transaction (Locks, Latches & Transactions). This lesson uses all of it at once, to work out which of those parts has gone wrong when a database gets sick.

Lesson 16 of 26 in Database Internals

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 27 July 2015: Joyent’s Manta fails one request in five for ten hours
  • What they had saved at 14:11: the oldest query in the building
  • Triage: symptom, one test, then the treatment
  • The ward list: pg_stat_activity, who is here and what each one waits on
  • The patient’s history: pg_stat_statements, which query ate the time
  • The chart on the bed: pg_stat_user_tables, what each table has been through
  • 1. One page is slow: a missing index
  • 2. The index is there and still slow: the wrong column order
  • 3. Fast yesterday, slow after a bulk load: stale statistics
  • 4. The table keeps growing: a session idle in a transaction
  • 5. Every page hangs, nothing errors: a lock queue
  • 6. The app cannot connect: connections exhausted
  • The six, on one card

Terms it explains: lock queue, session, pg_stat_activity, pg_stat_statements, pg_stat_user_tables.

Related paper

Review Database Internals