Stage 4

Stage 4: Performance & internals

Goal: Learn how PostgreSQL stores and executes your queries — processes, pages, WAL, MVCC, VACUUM — then read query plans, design indexes and make slow queries fast with a repeatable method. Time: about 2 weeks at ~45–60 minutes a day (~18 hours including the project) · Level: requires Stages 1–3


Parts in this stage

Do them in order — plans only make sense on top of the internals, indexes on top of plans, tuning on top of all three. Lessons here build their own big lab tables with generate_series (seconds to create, honest to measure).

Part Topic You will be able to Time
15 How PostgreSQL works inside Explain pages, WAL, MVCC bloat, VACUUM and planner statistics ~2.5 h
16 Reading query plans Read EXPLAIN ANALYZE and catch bad estimates at the root ~2.5 h
17 Indexing Design composite, partial, expression, covering and specialist indexes ~2.5 h
18 Query tuning Find the worst queries and fix them with a method ~2.5 h
🏁 Project: Tune It Ten real slow-query tickets on a million rows, fixed with write-ups ~6–8 h

How every part is organised

part-NN-topic/
├── README.md      ← 1. read the lesson, running every query as you go
├── examples/      ← 2. runnable .sql files for the lesson's examples (\i them)
├── exercises.md   ← 3. solve the practice questions yourself
└── solutions/     ← 4. only then compare with the solution .sql files

Every output printed in a lesson comes from a real run against PostgreSQL 17. EXPLAIN demos use COSTS OFF/TIMING OFF so what you read is the stable part of the plan; your own timings will differ by machine — the shapes won't.

How to study each part

  1. Predict every plan before you EXPLAIN it — the miss is where the learning is.
  2. Keep BEGIN; ... ROLLBACK; wrapped around any EXPLAIN ANALYZE of a write.
  3. When a plan surprises you, check estimates vs actuals before anything else.
  4. Part 18's exercise 1 needs pg_stat_statements in shared_preload_libraries — set it up once, keep it forever.

Finish line

You are done with Stage 4 when your Tune It write-up covers all ten tickets — cause named in one sentence, before/after plans and timings attached, including the one ticket whose correct fix is "no change". Then head to Stage 5: Specialization.

Search the guide