TOAST and overflow storage
Overview
Large values may not fit on an ordinary storage page. PostgreSQL TOAST can compress eligible variable-length attributes and/or move them into a separate TOAST relation, depending on data type and storage policy. A main tuple may hold a reference to an out-of-line value. SQLite uses overflow pages to store portions of large B-tree cell payloads. These are different implementations, not interchangeable SQL features.
First example
SELECT id,length(body) FROM st_row ORDER BY id;Observed SQLite result (rows in JSON):
[ [ 1, 32 ], [ 2, 6000 ], [ 3, 512 ]]How it works
The fixture stores BLOB lengths of 32, 6,000 and 512 bytes. SQLite dbstat reports five overflow pages totaling 5,120 allocated bytes for st_row. These observations describe the entire table in this exact fixture, not a universal threshold. PostgreSQL may compress repeated text sufficiently to keep it inline; length alone does not prove a value was moved out of line. Avoid retrieving large attributes unnecessarily; the actual I/O benefit depends on engine and access pattern.
Practical example
SELECT COUNT(*),SUM(pgsize) FROM dbstat WHERE name='st_row' AND pagetype='overflow';Observed SQLite result (rows in JSON):
[ [ 5, 5120 ]]Practice and mistakes
Practice: in a fresh database, insert a 10,000-byte BLOB and compare overflow page counts. Hint 1: use zeroblob(10000). Hint 2: filter dbstat on pagetype=overflow. Do not confuse logical byte length, compressed value size, and total relation size.
PostgreSQL 17 example — NOT RUN
BEGIN;SET LOCAL statement_timeout='10s';SET LOCAL lock_timeout='2s';CREATE TEMP TABLE st_pg(id integer PRIMARY KEY, label text, body text);INSERT INTO st_pg VALUES (1,'small',repeat('a',32)),(2,'large',repeat('b',6000)),(3,'medium',repeat('c',512));SELECT id,octet_length(body),pg_column_size(body),pg_column_compression(body) FROM st_pg ORDER BY id;ROLLBACK;Expected result, not executed: "Logical lengths 32,6000,512; inspect stored sizes and compression, no out-of-line allocation assertion."