Module 01 · Database Internals · One Database, to the Bolt · with code: Python · about 15 min to read
Continue where you left off ×
Make this Postgres fast: the brief
The Map · Open board
The whole database in one picture, from the page to the lock. A tuning job is a walk through that map with a stopwatch: this lesson finds where the time goes, and Make this Postgres fast: the fixes and the write-up changes it.
Before you start. This is the capstone of the track, and it uses the lessons before it: reading a plan (The Query Planner , The plan, running ), choosing an index (Which shortcut to build ), diagnosing from a symptom (The Database That Won't Answer ) and writing the SQL (The sentence that says what ). You need the Docker bench from Pages & Heap Files , or any Postgres 16, and Python 3. The code is in teaching/code/database-internals/tuning.
The idea in 30 seconds
The advice not to optimize early is half of Knuth’s sentence. The other half says to find the small part that matters and not pass it up, and measuring is how.
Before you tune, write down the pages, their targets and a way to time them. A target is a decision someone makes. Here the numbers are made up.
pg_stat_user_tables and pg_stat_user_indexes tell you which tables are read start to end and which indexes are never used, and the counts can be checked against the workload by arithmetic.
In this shop, three pages of five miss their targets: a lower(email) filter, a foreign key with no index behind it, and a dashboard that reads the biggest table in full.
Two passing pages should be left alone, with a written reason, and a scorecard misses what it does not exercise: deleting one order costs 20 ms here and no page shows it.
Read the story
Lesson 24 of 26 in Database Internals
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson December 1974: forget the small efficiencies, 97 percent of the time The brief The bench The stopwatch Where did the time go? The plans behind the two scans What to leave alone What the scorecard cannot see Terms it explains: 5 statements, The index counters,, WAL bytes per order, buffer pool, page, vacuum.
Review Database Internals
Mark as read Saved in this browser, and to your account when you sign in.