Module 01 · Database Internals · One Database, to the Bolt · about 17 min to read
Continue where you left off ×
The Buffer Pool
The Buffer Pool · Open board
The room every page has to pass through on its way in or out, and the rule that keeps a crash from lying about what was saved.
Before you start. Pages & Heap Files showed you that a table on disk is a pile of fixed 8 KB pages, and every page holds its rows behind a slot list at the top of it. This lesson puts a room between that pile and the program reading it, and asks what happens the day the room fills up.
The idea in 30 seconds
A table is stored as fixed 8 KB chunks called pages. Every read or write goes through the buffer pool, a fixed set of page slots in memory, never straight to disk.
A page is dirty if it has changed since it was read in, and pinned if someone is reading or writing it right this instant. Either can be true without the other.
“Evict whichever page was touched longest ago” fails on one sequential scan (reading a whole table start to end): it touches every page once and evicts everything anyone else was using.
The database Postgres picks what to evict with a clock sweep instead: each page slot has a small usage counter, and a pointer circling the slots counts each one down and evicts the first it finds at zero. No shared list to fight over.
The write-ahead log is a separate file recording every change in order. A changed page may never reach disk before the log entry describing that change does. That single ordering rule is what makes recovering from a crash possible at all.
Read the story
Lesson 4 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 plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson 1981: the paper that told database builders not to trust the operating system Two flags on every desk: scribbled on, and in someone’s hands The trap: the visitor who reads every book once The fix: a clock that never stops The rule a crash cannot break See it on your own machine Terms it explains: buffer pool, dirty, pinned, clock sweep, write-ahead log, WAL.
Review Database Internals
Mark as read Saved in this browser, and to your account when you sign in.