Browser-based plan reader · the plan is parsed here, never sent

Postgres EXPLAIN Visualizer

Paste EXPLAIN (ANALYZE, BUFFERS) output in JSON or text form and see where the time went: self time per node, estimate misses, seq scans that discard most rows, sorts and hashes that spilled, and plain-English hints for each.

Plan

Drop a plan file

A saved EXPLAIN result, up to 8 MB

Plans can contain table names, column names and literal values from your query. They are read in this tab and shown as text only.

Postgres EXPLAIN Plan Visualizer

Operator: Abdulla Al Fahad. How tools are built and checked

The total at the bottom of an EXPLAIN ANALYZE says how long the query took but not where the time went, and in a hundred-line plan the node that matters sits in the middle. Paste EXPLAIN (ANALYZE, BUFFERS) output and each node gets its own time, its share of the query and a verdict, with the nodes sorted so the expensive ones come first.

JSON and the default text format are both read. Everything stays in the browser tab, which matters because a plan quotes table names, column names and the literal values of your query.

Key features

  • Plan tree with self time, total time, rows planned and actual, loops, and block hits and reads per node
  • Slowest nodes by self time, and a tree you can switch to slowest-first order
  • Row-estimate misses with the factor, and a note when a miss merely follows from a node below
  • Hints for seq scans that discard most rows, disk sorts, hash spills, temp files, lossy bitmaps, index-only scans that still visit the table, slow nested loops, JIT and triggers
  • CSV of all nodes

How timings, estimates and buffers are read from a plan

A node's own time is its actual total time times its loops, minus the time of its children. Under a Gather or Gather Merge node the figures are averages per process, so the page divides by workers launched plus one to get wall-clock time. Time of InitPlan and SubPlan children is subtracted from the node that uses them. A CTE's time is subtracted from the first CTE Scan that reads it, because PostgreSQL runs the CTE when the scan first asks for rows. The result is clamped at zero.

Buffer counts in a plan include everything below the node, so the page subtracts the children to show what the node did itself; a block is taken as 8 kB. Row estimates are compared per loop, because both Plan Rows and Actual Rows are per execution of the node. Nodes that never ran (loops=0) are listed as never executed and cost nothing.

How it works

JSON is read from the array that psql or a driver returns, including a wrapped QUERY PLAN column. Text plans are rebuilt from the -> arrows and their indentation, with detail lines such as Buffers, Sort Method, Batches and Rows Removed by Filter assigned to the node above them. Plans without costs (COSTS OFF) read too, as long as a line starts with a PostgreSQL node name such as Seq Scan or Hash Join, so arbitrary text is refused instead of becoming a one-node plan. Buffers lines under Planning: and under Worker N: describe planning or one worker, so they are not added to the node above them. XML and YAML output is refused with a request to re-run in JSON or text.

Each hint has a fixed threshold, listed in the section on thresholds below, so a plan that shows no hints really did not cross them. Hints are ordered by severity, then by the milliseconds they affect.

When this helps

  • A developer sees a report query take 9 seconds, pastes the plan, and finds one nested loop whose inner index scan ran 52,000 times for 71% of the time, with the outer side underestimated 600 times; refreshing statistics fixes the estimate.
  • A DBA checks the same query after raising work_mem and watches the Sort Method change from external merge on disk to quicksort in memory.

Opening a file

  1. Run EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) on your query and copy the whole result.
  2. Paste it, or drop the saved file, and press Visualize plan.
  3. Read the slowest nodes, then open Hints and use show node to jump to each node mentioned.
  4. Click any node row to see its filters, conditions, hash and sort details.

Example

Built-in JSON plan (Sort over HashAggregate over a Hash Join of orders and customers)

Execution Time 836.2 ms. Seq Scan on orders: rows=1200 planned, 480000 actual, 1520000 removed by filter. Hash: 4 batches, 1800 kB.

Findings the page reports

high    Seq Scan on orders (o) takes 422 ms on its own
high    Seq Scan on orders (o): estimated 1,200 rows, got 480,000 per loop
medium  Hash used 4 batches with 1,800 kB of memory
medium  Hash used temporary files: 2,210 blocks written (17.3 MB)
info    Hash Join: estimated 1,200 rows, got 480,000 per loop (follows from a node below)

Tips for best results

  • Start with the miss that has no "follows from a node below" note. Estimates that go wrong lower in the tree carry upward, and fixing the lowest one often repairs the join order above it.
  • Compare self time with the Rows planned and actual columns together: a node that is slow with accurate estimates needs an index or less data, while a slow node with a 100x miss needs statistics.
  • Run the query twice and paste the second plan when the read hint appears; blocks read from outside shared_buffers may have come from the operating system cache, so a cold first run overstates disk time.

Limits

Hints are rules of thumb on one run. A plan from an idle test database can look healthy while production, with different data and statistics, chooses another plan, so use a plan from the environment you care about.

The text parser follows indentation, so a plan pasted from a tool that strips or wraps lines may attach details to the wrong node; JSON does not have that risk.

Times are what EXPLAIN ANALYZE measured, including its own timing overhead, which can be large on nodes that run millions of loops.

Common errors and how to fix them

"No plan nodes were found, so this does not look like EXPLAIN output."
The text has no line with (cost=...) and no line that starts with a node name. Copy the output of EXPLAIN itself, from the first node to the last line, and leave out the psql prompt and the query.
"This JSON has no \"Plan\" object. Run EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) and paste the whole result."
The pasted JSON is not a plan, or part of it was cut off. Copy the full array that starts with [ { "Plan": ... }.

Best practices

  • Keep the BUFFERS option on: without it the page cannot tell a node that waits on disk from one that works on cached pages, and it says so above the tree.

The thresholds behind the hints

Self time of 10% of execution and at least 1 ms is flagged as slow (high above 40%). An estimate off by 10 times or more, with at least 100 rows on either side, is a miss (high at 100 times). A sequential scan is flagged when its filter discards 90% or more of at least 10,000 rows, or when it runs 10 or more times as the inner side of a join and reads 10,000 rows in total.

A sort that used disk, a hash with more than one batch, any temp blocks, or a bitmap with lossy blocks is flagged on that node. Reads are flagged at 1,000 blocks and half of all accesses; an index-only scan at 1,000 heap fetches covering half the rows; an index scan whose filter removes 1,000 rows and ten times more than it keeps; a nested loop inner side that runs 1,000 times and takes 20% of the query. JIT is flagged at 10 ms and 20%, planning at 10 ms and more than execution, and trigger time at 1 ms and 10%.

Frequently asked questions

Why is a node's self time lower than its actual time?

Actual time includes the time of everything below the node, so the node's own share is what remains after subtracting its children, with loops and parallel workers taken into account.

Why does one parallel node show less time than the plan lists?

Nodes below a Gather report the average per worker process multiplied by loops, which counts every process. The page divides by the number of processes to approximate the wall-clock time the query actually waited.

Can it read a plan from EXPLAIN without ANALYZE?

Yes, but only planner costs and estimated rows are shown, with a notice. Timings, row misses, spills and buffer hints need ANALYZE, because they come from what actually ran.