skip to content

the contents

18 parts, 198 chapters, in the order they build on each other. the covers get darker as the book goes further down.

  1. 01, 7 chapters

    start here

    what a database actually is, the real postgres running in this page, and your first query.

  2. 02, 12 chapters

    one table

    SELECT, WHERE, NULL, ORDER BY and GROUP BY. everything you can ask of a single table.

  3. 03, 11 chapters

    joins and subqueries

    putting tables back together. every join, semi and anti joins, subqueries, set operations and CTEs.

  4. 04, 11 chapters

    windows, grouping and recursion

    the queries that make spreadsheets jealous. window functions, grouping sets and recursive CTEs.

  5. 05, 10 chapters

    changing data

    INSERT, UPDATE, DELETE, upserts, MERGE, bulk loads, and code that runs inside the database.

  6. 06, 11 chapters

    types and values

    numbers, text, time, json, arrays and ranges. picking the type is half the schema.

  7. 07, 13 chapters

    schema design

    keys, constraints, normal forms, and the patterns that keep data honest as it grows.

  8. 08, 12 chapters

    indexes, from the outside

    what an index is for, which queries it can help, and what it costs on every write.

  9. 09, 13 chapters

    how a query runs

    parse, plan, execute. EXPLAIN, scans, joins, sorts, and the iterator that pulls one row at a time.

  10. 10, 10 chapters

    the optimizer

    how postgres guesses row counts, prices every plan and picks the cheapest. and how it gets that wrong.

  11. 11, 11 chapters

    transactions and isolation

    ACID, the anomalies, the isolation levels, and what postgres really gives you at each one.

  12. 12, 12 chapters

    pages and the buffer pool

    where rows physically live. files, 8 KB pages, tuple headers, TOAST, and the cache in front of the disk.

  13. 13, 12 chapters

    inside indexes

    b+trees page by page, splits under concurrency, and how hash, GIN, GiST, BRIN and LSM trees are built.

  14. 14, 12 chapters

    MVCC and vacuum

    why an UPDATE writes a new row, who can see which version, and the vacuum that cleans up after everyone.

  15. 15, 10 chapters

    locks and concurrency control

    serializability theory, two-phase locking, postgres's lock manager, and the SSI that catches write skew.

  16. 16, 11 chapters

    WAL and recovery

    write-ahead logging, LSNs, checkpoints, crash recovery, backups and replication.

  17. 17, 10 chapters

    scale and distribution

    pools, partitions, replicas, shards, and what changes when the data no longer fits on one machine.

  18. 18, 10 chapters

    deep dives and interviews

    one row traced end to end, other engines compared, the interview questions, and a toy database you build yourself.