PostgreSQL book cover

Your technical library

PostgreSQL

10 modules · 96 topics

About this book
Concepts · PostgreSQL

PostgreSQL

This course explains why PostgreSQL behaves the way it does — why an idle connection can slow everyone else, why a table can double in size while nobody deletes anything, why the same query is fast one day and slow the next, why a standby cancels your report — and what each of those behaviours costs you in production. It assumes no PostgreSQL experience beyond its prerequisite courses, and teaches you to predict it under load, debug it from evidence, and defend an architectural choice in a review. It is not a SQL course.

It builds on four others. The DBMS course builds a database engine from first principles — transactions and isolation, multiversion concurrency, slotted pages, buffer pools, write-ahead logging, lock managers, query optimisers. System Design teaches what changes across machines: replication and failover. Operating Systems covers the processes, shared memory, page cache and I/O underneath. Computer Networking supplies a fourth foundation, used only in the Security module: the TLS handshake, server identity and certificate chains. This course does not repeat them. It shows the particular, often unusual, answers one engine gave, recaps each general idea in a sentence with a link back to where it is taught, and compares PostgreSQL's answer with what MySQL, Oracle and SQL Server chose — including where PostgreSQL's is the worse one.

It is one chain of consequences. Architecture and the founding trade-offs starts with where PostgreSQL came from — a Berkeley research project of 1986 — and the decisions it has never reversed: never overwrite a row, one operating-system process per connection. It then builds the runtime every later module assumes: the shared cache of pages, the locks that guard it and the tables, and the catalogs in which the database describes itself. Physical storage opens a page and a row and finds every version's history written into them. WAL and durability shows how a change to that page survives a power cut, and what each durability setting can lose.

MVCC turns the row's fields into the visibility rule, and follows the bill for keeping old versions in the table: updates that rewrite every index, vacuum, bloat, freezing, row locks, and the horizon one forgotten transaction holds for everyone. Indexes and planner foundations takes the B-tree apart — concurrent splits, the bloat updates create, collations, key choice — and then builds the planner's core: how to read a plan, what a cost is, the statistics behind every estimate and where estimates go wrong. Specialised indexes, planner mechanics and index selection applies that to the access methods for data a B-tree cannot order — GIN, JSONB, full-text, GiST, BRIN, pgvector — then goes inside the planner's machinery and closes with how to choose, and pay for, an index.

The last four modules take the database into production. Recovery and replication replays the log after a crash, restores to a point in time, and keeps copies on standbys. Locking, schema change and partitioning explains why one `ALTER TABLE` can block a thousand reads and how to change a schema without taking the table down. Security covers who may connect — host rules, password exchanges, OAuth tokens — and over which wire, including what `sslmode` does and does not verify; and what a role may then touch, including the ownership and name-resolution rules behind most privilege escalations, the boundary where a superuser becomes the operating-system user, row-level policies that filter inside a table, and the logging and at-rest options that bound all of it. Operations ends the course with the evidence — wait events, statement statistics, memory, poolers, backups and upgrades — and a procedure for going from a symptom to its cause before touching anything.

Every topic says what it inherits and what it leaves open, names the PostgreSQL version that made each behaviour true — the course targets PostgreSQL 18 — and closes on something you can observe or decide.

Two topics are marked optional: the history of the project, which follows the opening picture tour of the server, and the two production accounts of replication at scale, which close the replication module. Nothing later depends on them, so you can pass over them and come back for the story. After the picture tour, the chain of mechanisms starts at The no-overwrite bet.

96 topics across 10 modules, in dependency order.

This course assumes System Design, and does not repeat it. MVCC, isolation levels, the write-ahead log, B-trees, amplification and replication are derived there in the abstract. Here they are only the starting point: what PostgreSQL specifically chose, and what that choice costs in production.

Every topic opens with what to read first. Each entry says what you need from it, so a topic reached from an incident rather than from the start of the course is still readable.

Where PostgreSQL differs from its peers, the lesson says so and gives a verdict — including where a peer is simply better. Transaction-ID wraparound, update amplification across secondary indexes and standby query cancellation are all places PostgreSQL loses, and pretending otherwise would make the rest untrustworthy.

Topics still being written are labelled and excluded from progress, so the count reflects what is actually finished.

Almost everything surprising about PostgreSQL follows from five decisions: old row versions live in the table rather than in an undo log; a connection is an operating-system process; the write-ahead log is physical, over an 8 kB page; planning is cost-based over sampled statistics; and types, operators and access methods are extensible. Each module is one of those decisions arriving as a bill.