PostgreSQL
medium 32 minPostgreSQL is an open-source relational database that never overwrites a row: every change adds a new version, readers pick the version their snapshot may see, and vacuum clears away versions nobody needs.
Remember it
The few things worth knowing cold, and how to make them stick.
Memory hook
Never paint over: add a version, log it first, clean up later.
A conservator hangs dated tracings beside the old ones. Visitors see the tracing their ticket allows. The cleaner may take away only what nobody inside can need.
Cheat sheet
- Default port
- 5432
- Page
- 8 kB
- Default isolation
- read committed
- Connections
- 100 by default, one process each
- Checkpoint
- 5 min or about 1 GB WAL
- Autovacuum
- 50 + 20% dead, cap 100 million
- shared_buffers
- start at 25% of RAM
- work_mem
- 4 MB per operation
- Retry code
- 40001
- Table limit
- 32 TB
Spot it when you see
- Correct money, stock or bookings.
- Joins and changing questions.
- Maps, JSON or search beside relations.
- One system instead of four for a small team.
Tricks that stick
- WAL: write the log, then the page.
- xmin born, xmax gone.
- GIN for things inside a value, BRIN for things in order.
- Backup is not replica.
Do not forget
- Transactions left open.
- Replication slots nobody reads.
- work_mem raised globally.
- Session features behind transaction pooling.
- Sharding before indexing.