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
The whole notebook is free for 7 days. No card, no payment. We ask for an account so the download link belongs to someone.
Sign in with GitHub or GoogleWhat is inside
The full table of contents. 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.
- The schema on one page
- 1. Persistence, and where data lives
- 2. What a text file cannot do
- 3. What a DBMS promises
- 4. Relational or not
- 5. Why Postgres
- 6. Numbers, and the money rule
- 7. Text, and why the answer is `text`
- 8. Time, and the one that bites
- 9. Identity: serial, identity, uuid
- 10. JSON and JSONB
- 11. Enums, and the argument that actually wins
- 12. Why you never touch the database by hand
- 13. Up, down, and the version table
- 14. Migrations that do not lock the table
- 15. The columns every table has
- 16. `NOT NULL` is the default you want
- 17. Keys: primary, foreign, composite
- 18. One to one, and when to split a table
- 19. One to many
- 20. Many to many, and the linking table
- 21. Referential integrity on delete
- 22. `CHECK`, `UNIQUE`, and pushing rules down
- 23. Naming: plural, lower, snake
- 24. Write `FROM` before `SELECT`
- 25. `JOIN`, and why `LEFT` is usually right
- 26. Nested JSON in one round trip
- 27. Parameterised queries, and SQL injection
- 28. Dynamic filters and sorts, without opening a hole
- 29. Pagination: `OFFSET`, and why it dies
- 30. Insert and update
- 31. The N+1 problem
- 32. What an index actually is
- 33. What to index, and what Postgres already did
- 34. What an index costs
- 35. Reading `EXPLAIN ANALYZE`
- 36. Beyond B-tree
- 37. Transactions, and what ACID buys
- 38. Isolation levels
- 39. Row locks and `SELECT FOR UPDATE`
- 40. The lost update, revisited
- 41. Connection pooling
- 42. Triggers, and when not to
- 43. Vacuum, bloat and wraparound
- 44. Backups, and the difference that matters
- 45. The delivery script
- 46. Follow-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.