# Eight Kilobytes

> A free book on PostgreSQL performance and design, from the 8 KB page on disk to indexes, query plans, locking, migrations, and running it in production. Every example run against PostgreSQL 18.

---

LLMS index: [llms.txt](/en/llms.txt)

---

<span id="basics-book"></span>

**Chase Pierce**  
First edition · PostgreSQL 18 · 2026-10-05  
Publisher: Flagon

[Start reading](/en/01-preface/#basics-chapter-1) · [Print the whole book](/en/_print/)

Almost everything about PostgreSQL performance comes down to one number: 8,192. That's the size of a page, the unit Postgres reads, writes, and caches. A fast query touches few pages. A slow one touches many, or waits on someone else who is. Once you can see the pages, most of the mystery goes away.

You've probably met the symptoms already. The dashboard that was instant at launch and crawls now. The migration that "does nothing" and took the site down anyway. The table that keeps growing faster than the data in it. And the standing offer to fix all of it with a bigger instance. This book is the alternative to that offer.

## Count the pages, then earn the bigger box

The book starts at the bytes on disk and works up: how rows are stored and changed, how indexes and the planner find them, how to change a schema without an outage, and how to run Postgres in production. Along the way it builds two habits. Before you add an index, raise a setting, or blame the ORM, ask how many pages the work touches. And before you buy a bigger database, or a second one, use up the cheap fixes and prove in numbers that you've outgrown them.

That includes knowing where Postgres stops. On the same two million events, two column stores kept the data in under a fifth of the bytes and answered about ten times faster than a tuned Postgres. The book shows how far one Postgres goes, and the signal that tells you it's time for something else.

It's written for application developers who use Postgres every day, often through an ORM. You need basic SQL, not internals.

## Every claim that matters comes with a check

Every query ran against PostgreSQL 18, on a sample schema you can load in a minute, and every claim that matters comes with a lab check you can rerun on your own machine. Each chapter is a short essay you can read on its own; deep dives hold the machinery and the full measurements for when you want them.

## Free, and written in the open

Read it here, chapter by chapter, or download the whole thing as a PDF. It's versioned in git like everything else we publish, so when Postgres changes, the book does too. If something's wrong or unclear, that's a bug: [open an issue or send a fix](https://github.com/flagon-io/flagon/issues).

## Contents {#contents}

- [1 Before you start](/en/01-preface/)
- [2 Know the nouns first](/en/02-basics/)
- [3 Where the time goes](/en/03-latency/)
- [4 Everything is a page](/en/04-storage/)
- [5 The buffer cache decides what stays](/en/05-buffers/)
- [6 Updates are inserts](/en/06-mvcc/)
- [7 Keep your updates HOT](/en/07-hot/)
- [8 Write it down first](/en/08-wal/)
- [9 ACID\, honestly](/en/09-acid/)
- [10 Vacuum is not optional](/en/10-vacuum/)
- [11 Postgres is not MySQL](/en/11-not-mysql/)
- [12 Types are a contract](/en/12-types/)
- [13 Pick your keys once](/en/13-keys/)
- [14 Constraints\, chosen on purpose](/en/14-relationships/)
- [15 You don\'t need another database \(yet\)](/en/15-models/)
- [16 Extensions worth knowing](/en/16-extensions/)
- [17 The B\-tree does the heavy lifting](/en/17-btree/)
- [18 Beyond the B\-tree](/en/18-more-indexes/)
- [19 Read the plan\, not the clock](/en/19-explain/)
- [20 The planner is guessing](/en/20-planner/)
- [21 The cheapest plan wins](/en/21-plans/)
- [22 Queries that age well](/en/22-queries/)
- [23 Search without a search engine](/en/23-search/)
- [24 Code in the database](/en/24-functions/)
- [25 Everyone waits in line](/en/25-concurrency/)
- [26 Change the schema\, keep the site](/en/26-migrations/)
- [27 Load it fast](/en/27-loading/)
- [28 Connections aren\'t free](/en/28-connections/)
- [29 Measure honestly](/en/29-benchmarking/)
- [30 The settings that matter](/en/30-configuration/)
- [31 Watch it run](/en/31-observability/)
- [32 An untested backup is a rumor](/en/32-backups/)
- [33 Trust no tenant](/en/33-security/)
- [34 Someone else runs the box](/en/34-managed/)
- [35 Pick a provider you can leave](/en/35-providers/)
- [36 Fix the work\, then the box](/en/36-playbook/)
- [37 Scale up before you scale out](/en/37-scale/)
- [38 Copies of the truth](/en/38-replication/)
- [39 Partition for the delete](/en/39-partitioning/)
- [40 Shard last](/en/40-sharding/)
- [41 Where Postgres loses](/en/41-limits/)
- [42 Checklists](/en/42-checklists/)
- [43 Glossary](/en/43-glossary/)
- [44 Bibliography](/en/44-bibliography/)

## Figures {#figures}

- [Figure 2-1](/en/02-basics/#fig-2-1) — One server\, many databases\, a process per connection\. Each connection gets its own backend process\, which works in one database\; inside it\, schemas hold the tables\. Beside the backends\, the server runs its own processes\, and roles and settings belong to the whole server\.
- [Figure 3-1](/en/03-latency/#fig-3-1) — A page lives in one of three places\. A hit in shared\_buffers is a memory lookup\; a miss\, which EXPLAIN calls \"read\"\, costs a system call and a copy if the kernel has the page cached\, and a trip to the device if it doesn\'t\. Postgres can\'t tell those last two apart\.
- [Figure 4-1](/en/04-storage/#fig-4-1) — Line pointers from the front\, tuples from the back\. The two grow toward each other\, and the page is full when they meet\.
- [Figure 5-1](/en/05-buffers/#fig-5-1) — Finding a page is one hash lookup\. The tag lands in one of 128 separately locked partitions\. A hit pins the buffer and is done\; a miss has to evict a victim\, maybe write it out\, and read the page in\.
- [Figure 5-2](/en/05-buffers/#fig-5-2) — The hand takes a point from every buffer it passes\. It skips pinned buffers and evicts the first one it finds at zero\. A page read constantly is back at 5 before the hand returns\, so it never gets there\.
- [Figure 6-1](/en/06-mvcc/#fig-6-1) — An update is an insert plus a stamp\. The old version stays in slot 1\, stamped with the updater\'s XID and a ctid pointing at \(0\,4\)\; the new version is a complete copy in slot 4\. Four tuples now hold three rows\.
- [Figure 7-1](/en/07-hot/#fig-7-1) — HOT keeps the new version where the indexes can already find it\. A cold update puts the new version on another page and adds an entry to every index\. A HOT update writes it on the same page\, chained from the old one through t\_ctid\, and no index changes\; after pruning\, lp1 becomes a redirect to the new version\.
- [Figure 8-1](/en/08-wal/#fig-8-1) — A commit waits for the log\, not the pages\. The update dirties a page in shared\_buffers and appends a WAL record\. COMMIT waits only until that record is flushed to the sequential WAL\; the checkpointer or background writer writes the page to the data files later\.
- [Figure 8-2](/en/08-wal/#fig-8-2) — Recovery starts at the redo point\. A checkpoint begins at its redo point\, writes the dirty pages\, and logs its checkpoint record when done\. Everything before the redo point is already in the data files\, so after a crash\, replay starts there\.
- [Figure 8-3](/en/08-wal/#fig-8-3) — Every checkpoint resets the images\. The first change to a page after a checkpoint carries a full 8 KB image of it\; later changes to that page are small records\. After the next checkpoint\, the first change pays again\.
- [Figure 11-1](/en/11-not-mysql/#fig-11-1) — InnoDB finds rows by key\, Postgres by address\. In InnoDB the table is the primary key B\-tree\, so a secondary index entry holds the key and every row found through it descends that tree again\. In Postgres every index\, the primary key included\, points straight at a page in the heap\.
- [Figure 13-1](/en/13-keys/#fig-13-1) — Increasing keys append\; random keys scatter\. New identity or UUIDv7 keys all land on the rightmost leaf\, which stays in memory\. UUIDv4 keys land on any leaf\, a full leaf splits 50\/50\, and pages settle around 70 percent full against 90 for appends\.
- [Figure 17-1](/en/17-btree/#fig-17-1) — A lookup reads one page per level\, then the heap\. The primary key of events is 1 root page\, 19 internal pages and 5\,465 leaves over a heap of 35\,173 pages\, so finding a row reads three pages in the tree and one in the heap\.
- [Figure 21-1](/en/21-plans/#fig-21-1) — Find the node\, then fix the estimate or the work\. If estimated and actual rows differ 10x or more\, fix the statistics or the query that misleads them\; if the rows are right\, fix the index\, the shape or the prices\. Reach for enable\_\* and hints only at the end\.
- [Figure 22-1](/en/22-queries/#fig-22-1) — OFFSET counts from the front\; keyset starts at the bookmark\. OFFSET 1000000 reads 1\,000\,020 index entries and 21\,422 pages to show 20\. The keyset query seeks to where the last page ended and reads the next 20 in 5 pages\, the same on every page\.
- [Figure 25-1](/en/25-concurrency/#fig-25-1) — The second write wins\, silently\. Both transactions read 100\, and tx2 waits for tx1\'s row lock\, then writes a value computed from that stale read\. The balance ends at 80\, and tx1\'s spend is lost with no error\.
- [Figure 25-2](/en/25-concurrency/#fig-25-2) — One waiting lock stops every query\. The migration waits for the idle reporting transaction\, and every query after it\, even a plain read\, waits behind the migration\. When reporting commits\, the migration runs in a millisecond and the line drains\.
- [Figure 32-1](/en/32-backups/#fig-32-1) — Recovery is a base backup plus replay\. Restore the base backup\, then replay archived WAL forward until recovery\_target\_time\. Replay stops just before the 14\:02 mistake and the server opens there\.
- [Figure 38-1](/en/38-replication/#fig-38-1) — A replica replays the primary\'s WAL forever\. The walsender streams WAL to the standby\'s walreceiver\, the startup process replays it into pages\, and the standby reports its LSN positions back to pg\_stat\_replication\. It takes reads and refuses writes with 25006\.
- [Figure 39-1](/en/39-partitioning/#fig-39-1) — Deleting a month is work\; dropping one is a file\. The delete left 164\,383 dead tuples and wrote 32 MB of WAL\, and the vacuum after it wrote another 12 MB\. Detaching and dropping the month\'s partition unlinks its files and wrote under 150 KB\.
- [Figure 40-1](/en/40-sharding/#fig-40-1) — The shard key decides who does the work\. A query that names account\_id goes to the one shard holding that account\, where its rows sit together\. A query without it goes to every shard\, and the results are merged\.

## Tables {#tables}

- [Table 1-1](/en/01-preface/#tbl-1-1) — The machine comes first\; then jump to what hurts
- [Table 1-2](/en/01-preface/#tbl-1-2) — One ordinary SaaS schema runs through every chapter
- [Table 2-1](/en/02-basics/#tbl-2-1) — A handful of psql commands cover this book
- [Table 3-1](/en/03-latency/#tbl-3-1) — Memory is cheap\; everything else is expensive
- [Table 3-2](/en/03-latency/#tbl-3-2) — Round trips cost more than queries
- [Table 4-1](/en/04-storage/#tbl-4-1) — A row costs more than its columns
- [Table 5-1](/en/05-buffers/#tbl-5-1) — Your query shouldn\&\#x27\;t be the one writing dirty pages
- [Table 5-2](/en/05-buffers/#tbl-5-2) — Big operations get a ring
- [Table 7-1](/en/07-hot/#tbl-7-1) — A cold update pays for every index
- [Table 7-2](/en/07-hot/#tbl-7-2) — Every column an index mentions is indexed
- [Table 7-3](/en/07-hot/#tbl-7-3) — Leave room on the page\, or every update moves
- [Table 7-4](/en/07-hot/#tbl-7-4) — Leave room on the page\, or every update moves
- [Table 7-5](/en/07-hot/#tbl-7-5) — A long transaction turns HOT off
- [Table 7-6](/en/07-hot/#tbl-7-6) — Bottom\-up index deletion is the safety net
- [Table 8-1](/en/08-wal/#tbl-8-1) — wal\_compression is a cheap win
- [Table 8-2](/en/08-wal/#tbl-8-2) — Commit means flush
- [Table 9-1](/en/09-acid/#tbl-9-1) — Four promises\, four mechanisms
- [Table 9-2](/en/09-acid/#tbl-9-2) — Only serializable rules out every anomaly
- [Table 10-1](/en/10-vacuum/#tbl-10-1) — The defaults are wrong for big tables
- [Table 10-2](/en/10-vacuum/#tbl-10-2) — Wraparound stops writes before anything is corrupted
- [Table 11-1](/en/11-not-mysql/#tbl-11-1) — Where rows and old versions live decides the rest
- [Table 11-2](/en/11-not-mysql/#tbl-11-2) — Secondary lookups cost two descents in InnoDB
- [Table 11-3](/en/11-not-mysql/#tbl-11-3) — Integer division truncates\, and NULLs sort last
- [Table 11-4](/en/11-not-mysql/#tbl-11-4) — Most MySQL idioms have a direct Postgres equivalent
- [Table 12-1](/en/12-types/#tbl-12-1) — Integers run out sooner than you think
- [Table 12-2](/en/12-types/#tbl-12-2) — Pick a collation provider whose order never changes
- [Table 13-1](/en/13-keys/#tbl-13-1) — Random keys write nearly four times the WAL
- [Table 13-2](/en/13-keys/#tbl-13-2) — Random keys write nearly four times the WAL
- [Table 13-3](/en/13-keys/#tbl-13-3) — Every id format trades order against what it leaks
- [Table 14-1](/en/14-relationships/#tbl-14-1) — Store each fact once
- [Table 14-2](/en/14-relationships/#tbl-14-2) — The insert pays for every check
- [Table 14-3](/en/14-relationships/#tbl-14-3) — History is a table you design
- [Table 15-1](/en/15-models/#tbl-15-1) — Each model is one shape\, made fast
- [Table 15-2](/en/15-models/#tbl-15-2) — Entity\-attribute\-value is a trap
- [Table 15-3](/en/15-models/#tbl-15-3) — Closure tables store every ancestor pair
- [Table 16-1](/en/16-extensions/#tbl-16-1) — Contrib is the safest shelf\, though some of it is obsolete
- [Table 16-2](/en/16-extensions/#tbl-16-2) — A crashing extension drops every connection\, so vet it
- [Table 17-1](/en/17-btree/#tbl-17-1) — Every index is a tax on writes
- [Table 18-1](/en/18-more-indexes/#tbl-18-1) — Beyond the B\-tree
- [Table 18-2](/en/18-more-indexes/#tbl-18-2) — For containment\, jsonb\_path\_ops beats the default
- [Table 18-3](/en/18-more-indexes/#tbl-18-3) — GIN filters trigrams\; GiST ranks by similarity
- [Table 18-4](/en/18-more-indexes/#tbl-18-4) — A thousandth of the size\, nearly the same pages
- [Table 18-5](/en/18-more-indexes/#tbl-18-5) — The operator picks the index type
- [Table 20-1](/en/20-planner/#tbl-20-1) — Every price is relative to one sequential page
- [Table 20-2](/en/20-planner/#tbl-20-2) — Extended statistics measure columns together
- [Table 21-1](/en/21-plans/#tbl-21-1) — The 5\% rule is wrong in both directions
- [Table 21-2](/en/21-plans/#tbl-21-2) — Join order is a search\, and searches get expensive
- [Table 22-1](/en/22-queries/#tbl-22-1) — OFFSET reads every row it skips
- [Table 23-1](/en/23-search/#tbl-23-1) — Store the tsvector\; don\&\#x27\;t index the expression
- [Table 23-2](/en/23-search/#tbl-23-2) — Search extensions put BM25 in the index
- [Table 23-3](/en/23-search/#tbl-23-3) — ef\_search trades latency for recall
- [Table 24-1](/en/24-functions/#tbl-24-1) — The primary is your most expensive CPU
- [Table 24-2](/en/24-functions/#tbl-24-2) — A row trigger costs about a microsecond a row
- [Table 25-1](/en/25-concurrency/#tbl-25-1) — Row locks live in the row\, not in pg\_locks
- [Table 26-1](/en/26-migrations/#tbl-26-1) — Pick the index build that matches the table\&\#x27\;s traffic
- [Table 26-2](/en/26-migrations/#tbl-26-2) — Pick the index build that matches the table\&\#x27\;s traffic
- [Table 26-3](/en/26-migrations/#tbl-26-3) — Run a concurrent build alone\, untimed\, and check it\&\#x27\;s valid
- [Table 26-4](/en/26-migrations/#tbl-26-4) — Widening a type is free\; most other type changes rewrite
- [Table 28-1](/en/28-connections/#tbl-28-1) — Transaction pooling breaks session state
- [Table 29-1](/en/29-benchmarking/#tbl-29-1) — Ask one question
- [Table 30-1](/en/30-configuration/#tbl-30-1) — Context decides reload or restart
- [Table 30-2](/en/30-configuration/#tbl-30-2) — Autovacuum\&\#x27\;s defaults suit small tables and slow disks
- [Table 30-3](/en/30-configuration/#tbl-30-3) — Cheap logging answers most 3 a\.m\. questions
- [Table 32-1](/en/32-backups/#tbl-32-1) — Write down RPO and RTO first
- [Table 32-2](/en/32-backups/#tbl-32-2) — pg\_dump leaves out roles\; dump them separately
- [Table 32-3](/en/32-backups/#tbl-32-3) — pg\_upgrade \-\-link is fast and one\-way
- [Table 33-1](/en/33-security/#tbl-33-1) — The app never owns its tables
- [Table 34-1](/en/34-managed/#tbl-34-1) — Some jobs stay yours whoever runs the box
- [Table 34-2](/en/34-managed/#tbl-34-2) — Some jobs stay yours whoever runs the box
- [Table 34-3](/en/34-managed/#tbl-34-3) — The provider adds its own gate on CREATE EXTENSION
- [Table 34-4](/en/34-managed/#tbl-34-4) — Throttled I\/O shows as flat IOPS and rising latency
- [Table 34-5](/en/34-managed/#tbl-34-5) — Failover is DNS\, and your pool has to notice
- [Table 35-1](/en/35-providers/#tbl-35-1) — Know the shape and you know the tradeoffs
- [Table 35-2](/en/35-providers/#tbl-35-2) — Superuser access and retention rule services out
- [Table 36-1](/en/36-playbook/#tbl-36-1) — 10\. Scale out only for the signal that asks for it
- [Table 36-2](/en/36-playbook/#tbl-36-2) — Eight changes\, in the playbook\&\#x27\;s order
- [Table 36-3](/en/36-playbook/#tbl-36-3) — Eight changes\, in the playbook\&\#x27\;s order
- [Table 37-1](/en/37-scale/#tbl-37-1) — Measure before you buy anything
- [Table 37-2](/en/37-scale/#tbl-37-2) — Precompute what you show
- [Table 38-1](/en/38-replication/#tbl-38-1) — Synchronous commit costs a round trip
- [Table 38-2](/en/38-replication/#tbl-38-2) — Streaming for failover\, logical for a job
- [Table 39-1](/en/39-partitioning/#tbl-39-1) — Range fits time\; list and hash have narrow jobs
- [Table 39-2](/en/39-partitioning/#tbl-39-2) — Retention\: detach\, then drop
- [Table 39-3](/en/39-partitioning/#tbl-39-3) — Every partition a query can\&\#x27\;t prune costs planning time
- [Table 39-4](/en/39-partitioning/#tbl-39-4) — Every partition a query can\&\#x27\;t prune costs planning time
- [Table 40-1](/en/40-sharding/#tbl-40-1) — Each option moves the hard parts somewhere else
- [Table 40-2](/en/40-sharding/#tbl-40-2) — Each option moves the hard parts somewhere else
- [Table 41-1](/en/41-limits/#tbl-41-1) — Column stores keep a tenth of the bytes
- [Table 41-2](/en/41-limits/#tbl-41-2) — Postgres read every page for every query
- [Table 41-3](/en/41-limits/#tbl-41-3) — Column stores were about ten times faster\, and still faster on one core
- [Table 41-4](/en/41-limits/#tbl-41-4) — Column stores were about ten times faster\, and still faster on one core
- [Table 41-5](/en/41-limits/#tbl-41-5) — Rollups and a column extension close much of the gap
- [Table 41-6](/en/41-limits/#tbl-41-6) — Know the signal before you need it

## Parts {#parts}

| Part | Chapters |
| --- | --- |
| Front matter | [1](/en/01-preface/#basics-chapter-1)–[2](/en/02-basics/#basics-chapter-2) |
| The machine | [3](/en/03-latency/#basics-chapter-3)–[11](/en/11-not-mysql/#basics-chapter-11) |
| Designing for it | [12](/en/12-types/#basics-chapter-12)–[16](/en/16-extensions/#basics-chapter-16) |
| Finding rows fast | [17](/en/17-btree/#basics-chapter-17)–[24](/en/24-functions/#basics-chapter-24) |
| Changing it | [25](/en/25-concurrency/#basics-chapter-25)–[27](/en/27-loading/#basics-chapter-27) |
| Running it | [28](/en/28-connections/#basics-chapter-28)–[36](/en/36-playbook/#basics-chapter-36) |
| Scaling out | [37](/en/37-scale/#basics-chapter-37)–[41](/en/41-limits/#basics-chapter-41) |
| Back matter | [42](/en/42-checklists/#basics-chapter-42)–[44](/en/44-bibliography/#basics-chapter-44) |

## About this edition {#edition}

© 2026 Flagon, Inc. All rights reserved. This English web edition reproduces the first edition of *Eight Kilobytes: PostgreSQL from the page up*, published 2026-10-05, with examples run against PostgreSQL 18. The original book text and figures are available online at [Flagon](https://www.flagon.io/books/eight-kilobytes). The book's license permits online reading and reserves republication rights to Flagon, Inc.; this project records the source and version explicitly.

The lab kit and its MIT-licensed source files remain available from the original [Eight Kilobytes lab](https://www.flagon.io/books/eight-kilobytes/lab).

---

Section pages:

- [Before you start](/en/01-preface/): Why this book counts pages, why every claim comes with a proof, who it's for, how to read it at two depths, and how to run the same PostgreSQL 18 server and data used in every chapter.
- [Know the nouns first](/en/02-basics/): A primer on the SQL and PostgreSQL basics every later chapter assumes, from tables, queries, updates, joins, and indexes to the server, its processes, schemas, roles, transactions, the catalog, settings, and the files underneath.
- [Where the time goes](/en/03-latency/): Learn the latency numbers behind every query, so you can predict how fast a page read, a commit, or a round trip will be before you measure it.
- [Everything is a page](/en/04-storage/): Open the files and pages behind a table, read a row's header byte by byte, and design tables that fit more rows into every 8 KB page.
- [The buffer cache decides what stays](/en/05-buffers/): How shared_buffers finds, keeps, evicts, and writes pages, how to see what's cached and warm it after a restart, and where each backend's private memory goes.
- [Updates are inserts](/en/06-mvcc/): See exactly what UPDATE and DELETE do to a page, why tables bloat, and why one long transaction can hurt a whole database.
- [Keep your updates HOT](/en/07-hot/): Measure what a non-HOT update really costs, learn the exact rules for HOT, and design tables, indexes, and fillfactor so updates stay cheap.
- [Write it down first](/en/08-wal/): What happens between COMMIT and "it's safe", how to measure the WAL a statement writes, and why writes get expensive right after a checkpoint.
- [ACID, honestly](/en/09-acid/): What each ACID letter guarantees in Postgres, the mechanism behind it, what it costs, how it gets switched off, and exactly where it stops.
- [Vacuum is not optional](/en/10-vacuum/): What vacuum does to your pages, when autovacuum fires, what stops it working, and how to measure and fix bloat before it becomes an outage.
- [Postgres is not MySQL](/en/11-not-mysql/): The two databases bet opposite ways on where rows live and where old versions go. Learn the differences that follow, and the habits to drop.
- [Types are a contract](/en/12-types/): Pick column types and collations that stay correct and compact for years, and know which popular choices quietly cause bugs, bloat, or corruption.
- [Pick your keys once](/en/13-keys/): Choose primary keys and public ids with real numbers on index size, page density, and WAL for bigint, random UUIDs, and UUIDv7.
- [Constraints, chosen on purpose](/en/14-relationships/): Model data with constraints that hold, index your foreign keys, and measure what each one costs, so you keep them where they pay and drop them where they don't.
- [You don't need another database (yet)](/en/15-models/): Know how far Postgres stretches to cover key-value, document, graph, time-series, queue, search, and vector workloads, and when a separate system earns its place.
- [Extensions worth knowing](/en/16-extensions/): How Postgres extensions install, load, and upgrade, which ones earn their place, what each one costs, and how to vet one before you depend on it.
- [The B-tree does the heavy lifting](/en/17-btree/): How a B-tree finds a row in three or four page reads, how to order its columns, and how to spot the indexes that cost more than they give.
- [Beyond the B-tree](/en/18-more-indexes/): When to reach for GIN, GiST, SP-GiST, BRIN, or hash indexes, what each one costs, and how to prove it helped with a measured plan.
- [Read the plan, not the clock](/en/19-explain/): Read a PostgreSQL query plan node by node, find where the pages and the time actually go, and fix slow queries with measured before-and-after proof.
- [The planner is guessing](/en/20-planner/): Read the statistics the planner uses, find the estimate that went wrong, and fix it with ANALYZE, extended statistics, or a better query instead of a hint.
- [The cheapest plan wins](/en/21-plans/): Follow a query from SQL to plan, check the planner's arithmetic by hand, and see exactly why it picks each scan, join, worker count, and JIT.
- [Queries that age well](/en/22-queries/): The query shapes that stay fast as tables grow, from keyset pagination and N+1 fixes to upserts, batching, and top-N per group.
- [Search without a search engine](/en/23-search/): Build full-text and vector search in Postgres, measure what parsing, ranking, snippets, TOAST, and recall cost, and know when you need a search engine.
- [Code in the database](/en/24-functions/): Keep per-row work off the primary, write functions the planner can see through, label them honestly, and know what every trigger costs and hides.
- [Everyone waits in line](/en/25-concurrency/): Pick an isolation level on purpose, handle errors and retries in transactions, read pg_locks during an incident, and build a job queue on SKIP LOCKED.
- [Change the schema, keep the site](/en/26-migrations/): Ship schema changes to a busy database without stalls, using lock timeouts, NOT VALID constraints, concurrent indexes, and expand and contract.
- [Load it fast](/en/27-loading/): Load millions of rows in seconds with COPY, FREEZE, and late indexes, and pay the WAL, checkpoint, hint-bit, and statistics bills on your schedule.
- [Connections aren't free](/en/28-connections/): Size connection pools from cores and latency, choose a pooling mode knowingly, and set the timeouts that keep one bad client from exhausting the server.
- [Measure honestly](/en/29-benchmarking/): Benchmark Postgres so the numbers mean something. pgbench done right, latency percentiles that include the stalls, and test data shaped like production.
- [The settings that matter](/en/30-configuration/): Which of Postgres's 400 settings deserve your attention, how to change each one safely, and a commented starter config for a 4 vCPU, 16 GB server.
- [Watch it run](/en/31-observability/): Use pg_stat_statements, pg_stat_activity, and the cumulative statistics views to find what is slow, what is stuck, and what to alert on.
- [An untested backup is a rumor](/en/32-backups/): Choose between logical and physical backups, set up point-in-time recovery, prove your restores work, and upgrade major versions safely.
- [Trust no tenant](/en/33-security/): Separate owner and app roles, lock down schemas, build multi-tenant row-level security that is fast and pooler-safe, and harden connections.
- [Someone else runs the box](/en/34-managed/): What a managed Postgres service takes off your plate and what it leaves you, from admin roles and settings to I/O ceilings, poolers, upgrades, and failover.
- [Pick a provider you can leave](/en/35-providers/): Where Postgres can run in October 2026, why some providers benchmark faster than others, and how to choose one you can walk away from.
- [Fix the work, then the box](/en/36-playbook/): The order to make Postgres fast, lever by lever, each with the number that says you need it, proven end to end on one small app.
- [Scale up before you scale out](/en/37-scale/): Earn every bigger box with data. Find the real bottleneck, take the cheap structural wins, and know when one big box is truly done.
- [Copies of the truth](/en/38-replication/): Build streaming replicas, measure their lag, price synchronous commits, route reads safely, fail over without split brain, and use logical replication.
- [Partition for the delete](/en/39-partitioning/): Partition big time-series tables for retention and maintenance, read pruning in real plans, dodge the pitfalls, and convert a live table without downtime.
- [Shard last](/en/40-sharding/): Know when sharding is worth its cost, pick a shard key, keep the door open from day one, and choose among the real ways to shard Postgres.
- [Where Postgres loses](/en/41-limits/): The honest map of where another system beats Postgres, measured where we could, and how to add one without losing your source of truth.
- [Checklists](/en/42-checklists/): One line per habit, cheapest lever first, from finding the expensive work through queries, indexes, search, schema, migrations, and production to the bigger box, scaling out, and the slow-right-now incident, each linked to the section that proves it.
- [Glossary](/en/43-glossary/): The terms the book leans on, defined in a sentence or three, each with a link to the section that teaches it.
- [Bibliography](/en/44-bibliography/): Every source the book cites, grouped by kind, with the chapters that cite it.
