0Pricing
PostgreSQL Performance & Query Optimization · Lesson

Reading EXPLAIN and EXPLAIN ANALYZE Output

Decode PostgreSQL query plans with EXPLAIN to see how the planner executes a query and where the time really goes.

Reading EXPLAIN and EXPLAIN ANALYZE Output is a free PostgreSQL Performance & Query Optimization lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the PostgreSQL Performance & Query Optimization learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Read Query Plans

Before tuning a slow query, see what PostgreSQL actually does. EXPLAIN shows the planner's chosen execution plan as a tree of nodes.

EXPLAIN vs EXPLAIN ANALYZE

EXPLAIN shows estimates only; EXPLAIN ANALYZE actually runs the query and reports real timings and row counts — far more useful for diagnosis.

EXPLAIN ANALYZE
SELECT * FROM orders WHERE customer_id = 42;

The Plan Tree

Read plan trees inside-out and bottom-up: leaf nodes scan data, parents join or aggregate. Each node reports its cost, rows, and width.

The cost Numbers

The cost reads as cost=0.00..18.45: first is startup cost, second is total, both in arbitrary planner units used to compare competing plans.

Sequential Scan

A Seq Scan reads the whole table — fine for small tables or when most rows match, but a red flag on a selective query over a large one.

Index Scan

An Index Scan uses an index to find matching rows, then fetches them from the table. It's the win for selective predicates.

Estimated vs Actual Rows

Compare estimated rows with actual rows. A big mismatch means stale statistics and often a bad plan — run ANALYZE to refresh them, as shown below.

ANALYZE orders;

Spotting the Bottleneck

To find the bottleneck, hunt for the node with the largest actual time, or one whose loops multiply its cost. That's where to focus tuning.

BUFFERS for I/O Insight

Add BUFFERS to your EXPLAIN to see how many pages came from cache versus disk — the fast way to spot I/O-bound queries. See the example below.

EXPLAIN (ANALYZE, BUFFERS)
SELECT * FROM orders WHERE total > 100;

Join Strategies

Watch the join strategy: Nested Loop, Hash Join, or Merge Join. A Nested Loop over many rows without an index is a classic slow pattern.

Readable Formats

For big plans, switch to FORMAT JSON or a visual tool to explore them more easily. The query below shows the JSON option.

EXPLAIN (ANALYZE, FORMAT JSON)
SELECT * FROM orders;

Quick Check

Test what you have learned.

Recap

Recap: read EXPLAIN trees, compare estimates with ANALYZE actuals, tell Seq from Index scans and join types, use BUFFERS, and find the bottleneck node.

Frequently asked questions

Is the “Reading EXPLAIN and EXPLAIN ANALYZE Output” lesson free?

Yes — the full text of “Reading EXPLAIN and EXPLAIN ANALYZE Output” is free to read here on the web, and the PostgreSQL Performance & Query Optimization course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the PostgreSQL Performance & Query Optimization course, upgrade to CoddyKit PRO.

What will I learn in “Reading EXPLAIN and EXPLAIN ANALYZE Output”?

Decode PostgreSQL query plans with EXPLAIN to see how the planner executes a query and where the time really goes. You practise PostgreSQL Performance & Query Optimization with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start PostgreSQL Performance & Query Optimization?

No prior experience is required. PostgreSQL Performance & Query Optimization on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Reading EXPLAIN and EXPLAIN ANALYZE Output” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this PostgreSQL Performance & Query Optimization lesson?

Yes. Every PostgreSQL Performance & Query Optimization lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Understanding Database Performance Basics
  2. PostgreSQL Architecture Overview
  3. Basic Query Execution Workflow
  4. Reading EXPLAIN and EXPLAIN ANALYZE Output
← Back to PostgreSQL Performance & Query Optimization