Playground

PostgreSQL simulator

A PostgreSQL simulator from one row to 1 TiB

Follow a PostgreSQL row from aligned tuple bytes into an 8 KiB heap page, then watch the heap and primary-key B-tree grow. Step through an INSERT, an indexed lookup or an unindexed scan. Every figure is a labelled model estimate; the simulator does not connect to a database.

What happens to a PostgreSQL row as a table grows?

This model places a 64-byte tuple plus its 4-byte line pointer into an 8 KiB heap page, fitting 120 rows per page. A primary-key B-tree adds levels as rows grow. At a 1 TiB heap, the model contains 16,106,127,360 rows across 134,217,728 heap pages; it counts modelled page visits, not physical disk reads.

Query to follow

One heap tuple: 64 bytes

68 bytes on disk for 36 bytes of data: a 23-byte header, 4 bytes of alignment padding, a 1-byte length header on the email and a 4-byte line pointer.

header23 B
pad1 B
idoffset 248 B
emailoffset 3221 B
pad3 B
created_atoffset 568 B

Offsets and bytes are the deterministic model for the fixed example schema. The line pointer sits at the start of the page, not in the tuple.

Step 1 of 10 · Zoom 5

Backend receives the query

A backend process handles this client's INSERT request. Modelled pages visited so far: 0.

Educational SQL example

INSERT INTO users (email, created_at) VALUES ('user@example.com', now());

This is a deterministic teaching model for a standard PostgreSQL profile. Page layouts, planner cost units, modelled page visits and file segments are estimates; real I/O and file sizes depend on build, settings and cache state. The 1 TiB example is too large for this model to represent vacuum, freezing, wraparound, backup or restore work. Catalog and multi-table counts are withheld pending measurement. No database is connected or queried. Read the methodology.

A row is more than its column values

The example schema has a bigint identity primary key, a short email and a timestamptz. PostgreSQL stores a tuple header, alignment padding and the column data. The heap page also has a 24-byte page header and a 4-byte line pointer per tuple. The exact layout depends on build options and values; this simulator labels its fixed-profile assumptions.

Heap pages hold the table rows

PostgreSQL stores heap tuples in 8 KiB pages. In this model, each row occupies 68 bytes on the page, so 120 rows fit after the page header. Relation files are split into 1 GiB segments by default. The file view shows a few segments and collapses the rest into a count.

A B-tree keeps primary-key lookups shallow

The primary-key index stores key and tuple-location entries in leaf pages. Internal pages lead from the root to a leaf. The simulator highlights one modelled page at each level, then a heap page. It does not promise physical disk reads: cache state, visibility checks and planner settings affect real I/O.

INSERT, WAL and commit

Follow the INSERT sequence from backend parsing and planning through the free space map, shared buffers, heap and index changes, WAL and commit. With synchronous commit enabled, PostgreSQL flushes the commit record to WAL before reporting success. Dirty data pages can be written later by a checkpoint. The displayed SQL is educational copy; this page never runs it.

The largest scale is an exact 1 TiB heap

The heap main fork contains 134,217,728 pages × 8,192 bytes = 1,099,511,627,776 bytes. At 120 rows per page, that is 16,106,127,360 rows. The primary-key index is shown separately and is estimated from the stated B-tree fill assumptions. The model does not cover vacuum and freezing, transaction ID wraparound, backup or restore work at this scale.

Model limits and sources

Planner costs are units, not time. Modelled page visits are not physical reads. Catalog and multi-table filesystem counts are withheld pending a measurement tied to a PostgreSQL version. For the assumptions behind this simulator, see the methodology.

Frequently asked questions

How does PostgreSQL store a row?

A heap tuple contains a header and aligned column data. A line pointer locates the tuple inside an 8 KiB page. The simulator shows each part for one fixed example table.

How many rows fit in a PostgreSQL page?

In this model, the 64-byte tuple plus a 4-byte line pointer uses 68 bytes per row. With a 24-byte page header, 120 rows fit in an 8 KiB page, with 8 bytes left.

What does the 1 TiB scale mean?

The heap main fork is exactly 1 TiB: 134,217,728 pages of 8 KiB each. At 120 rows per page, that is 16,106,127,360 rows. The primary-key index is extra.

Does this simulator connect to PostgreSQL?

No. It is a deterministic teaching model. It does not connect to a database, execute SQL, or measure physical I/O or query time.

Why is there no million-table scale?

Catalog and filesystem counts depend on the PostgreSQL version and how the tables are created. That scale is withheld until its counts are measured on a named PostgreSQL release.

No signup, nothing to install. It runs in your browser.

Open the PostgreSQL simulator ↓

One system design problem a week

A real scenario, its constraints, and where the obvious design breaks.

One email a week. Unsubscribe any time. Privacy

Now break one yourself.

The first challenge takes about two minutes. No signup.