Under the hood: how a row is stored

Step 1 of 90%

Concept · step 1 of 9

A table is a file of pages

Underneath, a table is a file on disk, cut into pages of the same size. Rows live inside the pages.

  • A page is 8 kB. in the docs' words, every table and index is stored as an array of pages of a fixed size, usually 8 kB.
  • Every row has an address, `ctid`. the page it is on, and its slot in that page.
  • The address belongs to a version of the row, not to the row. change the row and it moves.
SELECT ctid, title FROM books;
ctid is a system column: every table has it, though it never appears in SELECT *. Asking for it by name shows where each book physically sits.
PostgreSQL docs: Database page layout ↗

Starting Postgres in your browser

About 5 MB the first time, cached after that.

PostgreSQL running in your browser