Study Notebook / 04
Postgres
Schema, queries and indexes for people who have to keep the thing running
Types, constraints, relationships and indexes, then the part most courses skip: transactions and isolation, the N+1 problem, connection pooling, EXPLAIN, and vacuum. A schema you can draw is table stakes.
- pages
- 71
- sections
- 50
- editions
- Reading, Print, Tablet
Sign in to read it
Sign in and the whole notebook opens, all three editions with it. An account is what makes a download belong to someone.
Sign in with GitHub or GoogleStart reading
How to use this book
What is inside
Every section, and every one of them opens in the browser. Nothing here is hidden: if a section you need is not in this list, the notebook is not the right one and you should not spend a week on it.
- How to use this book
- The schema on one page
- 1Persistence, and where data lives
- 2What a text file cannot do
- 3What a DBMS promises
- 4Relational or not
- 5Why Postgres
- 6Numbers, and the money rule
- 7Text, and why the answer is `text`
- 8Time, and the one that bites
- 9Identity: serial, identity, uuid
- 10JSON and JSONB
- 11Enums, and the argument that actually wins
- 12Why you never touch the database by hand
- 13Up, down, and the version table
- 14Migrations that do not lock the table
- 15The columns every table has
- 16`NOT NULL` is the default you want
- 17Keys: primary, foreign, composite
- 18One to one, and when to split a table
- 19One to many
- 20Many to many, and the linking table
- 21Referential integrity on delete
- 22`CHECK`, `UNIQUE`, and pushing rules down
- 23Naming: plural, lower, snake
- 24Write `FROM` before `SELECT`
- 25`JOIN`, and why `LEFT` is usually right
- 26Nested JSON in one round trip
- 27Parameterised queries, and SQL injection
- 28Dynamic filters and sorts, without opening a hole
- 29Pagination: `OFFSET`, and why it dies
- 30Insert and update
- 31The N+1 problem
- 32What an index actually is
- 33What to index, and what Postgres already did
- 34What an index costs
- 35Reading `EXPLAIN ANALYZE`
- 36Beyond B-tree
- 37Transactions, and what ACID buys
- 38Isolation levels
- 39Row locks and `SELECT FOR UPDATE`
- 40The lost update, revisited
- 41Connection pooling
- 42Triggers, and when not to
- 43Vacuum, bloat and wraparound
- 44Backups, and the difference that matters
- 45The delivery script
- 46Follow-up question bank
- Appendix A. Defaults to memorise
- Appendix B. Glossary
- Appendix C. Self-test
How to read it
Read with a pen. Every notebook opens with a question to answer before you start and asks you to redo the answer at the end, and the margin in the Print edition exists so you have somewhere to be wrong first. The Tablet edition is 16:9 with vector text, so note apps draw on it rather than treating it as a photograph.