Writing SQL that works is the easy part. The trouble starts when the database is yours to keep alive. An index that helped last month is now making every insert slower. A schema change you shipped at noon froze every query behind one lock. Someone asks when the last backup was actually restored, and nobody knows. None of that is in a SELECT tutorial, and all of it is in this book.
The PostgreSQL Handbook, Second Edition takes you from your first query to running a production database. It is rebuilt for PostgreSQL 19: twenty-three chapters in five parts, seven appendices and 675 pages. You build one system the whole way through. Lumina Helpdesk is a support-ticketing database that grows from an empty schema into something with real data, real constraints, real indexes, real roles and a real replica.
Comfort with basic SQL is enough to start. Everything after SELECT, WHERE and JOIN is built on the page, in order, against that one running example.
You will learn how to:
· Choose data types and constraints that make bad data impossible, and write inserts that handle the row already there with upsert and MERGE
· Think relationally with joins, aggregation, percentiles, CTEs and window functions, so the logic stays in SQL instead of leaking into application code
· Use what makes PostgreSQL different: JSONB beside relational columns, JSON_TABLE, full-text search you can tune, and functions that tell the planner the truth about their volatility
· Reason about MVCC, isolation levels, row locks and timeouts, so a schema change on a live table fails fast instead of freezing everything behind it
· Pick the right index for the shape of a question, read an EXPLAIN plan from the bottom up, and tune with evidence instead of folklore
· Secure the database with roles, row-level security and TLS, including the pitfall that leaks one tenant's rows to another under a connection pooler
· Take backups that restore, rehearse a point-in-time recovery to the second before the mistake, and read the server log as a monitoring tool
· Partition a table that outgrew itself, fail over to a replica by hand, put PgBouncer in front of the server, and upgrade to the next major version with pg_upgrade
· Run the same database on a managed service or on Kubernetes with CloudNativePG, and know which of your own steps the platform takes over
· Reach PostgreSQL from C# with Npgsql and EF Core 10, and build semantic and hybrid search with pgvector in the database you already run
The last three chapters use C#, but this is not a C# book. The first twenty chapters contain none, and a reader who never opens Visual Studio loses nothing before Chapter 21.
What makes this book different is that you can check it. An automated harness ran 364 of the book's 373 SQL listings against a live PostgreSQL 19 server, each at the chapter state it assumes. A listing meant to succeed had to succeed, and a listing meant to fail had to fail with the error code the text names. The other nine are environment commands, such as promoting a standby. Most printed results come straight from a captured run instead of being typed in. The seed data is deterministic, and one script resets your database to the state any chapter expects, so the grid on the page is the grid you should see. The 69 exercise solutions went through the same harness.
The companion setup is one Docker image, pinned by digest, that serves every chapter from the first query to pgvector. Optional profiles add a replica and a connection pooler for the replication drills. Appendix A covers a native install if you would rather not use Docker.
Written for developers who already write some SQL and want to understand PostgreSQL itself, and for the accidental owner: the person who inherited a production database and now has to secure it, back it up, tune it, replicate it and upgrade it.
Read the first edition? This one targets PostgreSQL 19 instead of 18, adds two appendices on upgrades and on managed and Kubernetes deployments, and widens almost every chapter. The release notes list what changed.
Buying for a team? Volume licenses are available from 3 copies, with team pricing up to 40% off for larger groups: one purchase, one invoice, a copy for everyone.
The companion code lives at https://github.com/RachidD68/the-postgresql-handbook. It holds the schema, the seeds, every SQL listing as a runnable file, all 69 exercise solutions, the C# projects for Part V and the Kubernetes lab. It is MIT-licensed, separately from the book text, so you can use it in commercial work without restriction.