Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Performance & internals
Stage 5: Specialization

Part 15 / Topic 2 of 7

Storage: pages, tuples, out-of-line values

On disk, a table is a heap file divided into fixed 8 kB pages; each row lives in a page as a tuple. Everything Postgres reads or writes moves in whole pages — the unit that makes "how many pages must this query touch?" the performance question of this stage.

SHOW block_size;
 block_size 
------------
 8192
(1 row)

Build something measurable — 100,000 rows:

CREATE TABLE readings AS
SELECT g AS id,
       'sensor-' || (g % 50) AS sensor,
       g * 0.1 AS value
FROM generate_series(1, 100000) AS g;
SELECT pg_size_pretty(pg_relation_size('readings')) AS heap_size,
       (pg_relation_size('readings') / 8192) AS pages;
SELECT 100000
 heap_size | pages 
-----------+-------
 5120 kB   |   640
(1 row)

~650 pages for 100k skinny rows. A row's physical address is its ctid — (page, slot):

SELECT ctid, id, sensor FROM readings LIMIT 3;
 ctid  | id |  sensor  
-------+----+----------
 (0,1) |  1 | sensor-1
 (0,2) |  2 | sensor-2
 (0,3) |  3 | sensor-3
(3 rows)

Rows too big for a page (a few kB of text, a large jsonb) have their oversized values moved out of line: compressed and sliced into a companion table, the main tuple keeping a stub. It's automatic and invisible — until you SELECT a huge column you didn't need and pay its reassembly; one more reason Part 2 told you to name your columns.

🧪 Quick quiz — answer from memory, then check.

  1. What is PostgreSQL's page size, and why does it matter?
  2. What happens to a 50 kB text value?
Show the answers
  1. 8 kB (8192 — fixed at compile time); I/O happens in whole pages, so page counts drive query cost.
  2. It is moved out of line: compressed and stored in slices, reassembled when that column is actually read.

Done here? The practice set for Part 15 — 5 exercises with solutions — is on the part page.

Search the guide