ls lib/postgres-internals/

PostgreSQL internals, by building tinypg

lib / PostgreSQL internals, by building tinypg

How PostgreSQL 19.0 stores, logs, versions, indexes, plans and runs your data, read from its source, while a tiny Postgres in Python grows one piece per lesson.

For people who already write SQL against PostgreSQL and want to know what happens underneath: how a row is laid out on disk, how a crash is survived, how two transactions see different versions of the same row, how an index finds a key, and how a query becomes a plan that runs. Each lesson reads the relevant part of the PostgreSQL 19.0 source, checks it against a running 19.0 server, and then builds a simplified version of it in tinypg.

tinypg is a small Python program, standard library only, that grows one piece per lesson; each lesson links its state of the code as a tag. Where it implements something, it follows PostgreSQL’s on-disk format closely enough that its pages can be compared byte for byte with a real server’s. It is not a database you would store data in: it has one process, no SQL until the query part, and leaves out whatever a lesson has not reached. Using SQL itself is a different course.

Storage

Buffers and durability

MVCC

Indexes

Queries

Concurrency and the server