Module 01 · Database Internals · One Database, to the Bolt · with code: Python · about 19 min to read
Continue where you left off ×
Pages & Heap Files
Pages & Heap Files · Open board
Opens the Database Internals series, under Database Internals, the deep-dive set and following Storage Engines . It draws the page you’re about to take apart.
Before you start. You’ve used an app that saves things: a login, a cart, a comment, and somewhere behind it sat a database. This lesson opens that box for the first time: what a table actually is on disk, before any of the machinery later lessons build on top of it.
The idea in 30 seconds
A table on disk is not rows in a spreadsheet. It’s a file of fixed-size pages, and nothing beneath a database will hand it anything smaller than one whole page.
A page has a small header, then a list of slots (one short line per row, giving where on the page it sits), then empty space, then the rows packed in from the far end. It is full when slots and rows meet.
Postgres addresses a row by page number plus slot number, called a ctid, not by its exact byte position, so a row can move within its page without any reference to it elsewhere changing.
A Postgres table is a heap: pages in no sorted order, a new row on any page with room. Adding rows is cheap. Finding a row by its id takes two reads, an index (a sorted list of which page holds which id) and then the page.
Nearly every cost you’ll measure in a database: a slow query, a swollen table, a query fetching every column when it needed two, comes down to one question: how many pages did it touch?
Read the story
Lesson 3 of 26 in Database Internals · Free with an account
Keep reading. It's 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.
No card, and chalk sends no email. Google sign-in only.
Start free with Google
In this lesson 1979: a database that had to fit in 128 kilobytes The warehouse that will not hand you one can Opening one bin: a label, an empty gap, then cans packed from the back The tag that survives the shelf being rearranged The heap: a warehouse floor with no aisles Your bench Terms it explains: page, slots, tuple, ctid, heap, `t_xmin` / `t_xmax`, `pd_lsn`, Postgres: heap, InnoDB: index-organized, `_fsm`, `_vm`, column store, Dictionary encoding, Run-length encoding, PAX.
Review Database Internals
Mark as read Saved in this browser, and to your account when you sign in.