How to Read a PostgreSQL EXPLAIN ANALYZE Plan
Last updated: 23 October 2026
A PostgreSQL EXPLAIN ANALYZE plan shows what the query planner decided to do and how long each step actually took. Reading one means working from the innermost (most indented) line outward, comparing each node's estimated rows to its actual rows, and checking whether its time came from CPU work or from reading data off disk. Most slow query problems are one of three things: a wrong row estimate, a read that is bound by disk rather than memory, or a step that runs far more times than expected.
This post walks through a real plan line by line. If you want to skip straight to a visual diagram instead of reading raw text, GresTrace does that part for free.
EXPLAIN vs EXPLAIN ANALYZE
EXPLAIN alone shows what the planner expects to happen: estimated costs and row counts, based on table statistics. It doesn't run the query.
EXPLAIN ANALYZE actually runs the query and shows what really happened: actual time, actual row counts, actual loop counts. This is the one to use when debugging a slow query, because the planner's estimate and reality can diverge a lot, and that gap is usually the bug.
Add BUFFERS too. It's free information and tells you whether the time was spent in memory or on disk:
EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM orders WHERE customer_id = 42;
One caveat: EXPLAIN ANALYZE actually executes the query, including any INSERT, UPDATE, or DELETE it contains. Wrap those in a transaction you roll back if you're testing against real data:
BEGIN;
EXPLAIN (ANALYZE, BUFFERS) UPDATE orders SET status = 'shipped' WHERE id = 42;
ROLLBACK;
A real plan, read top to bottom
Here's a plan for a query joining orders to customers:
Nested Loop (cost=0.43..892.15 rows=1 width=120) (actual time=0.052..45.891 rows=3200 loops=1)
Buffers: shared hit=12 read=3104
-> Seq Scan on orders (cost=0.00..850.00 rows=1 width=64) (actual time=0.018..38.204 rows=3200 loops=1)
Filter: (customer_id = 42)
Rows Removed by Filter: 996800
Buffers: shared hit=2 read=3100
-> Index Scan using customers_pkey on customers (cost=0.43..8.45 rows=1 width=56) (actual time=0.001..0.001 rows=1 loops=3200)
Index Cond: (id = orders.customer_id)
Buffers: shared hit=10 read=4
Read the innermost, most indented lines first. Those run first and feed the outer nodes.
What does "loops" mean in an EXPLAIN ANALYZE plan?
When loops is greater than 1, the actual time and rows values shown are the average per execution, not the total. Per the PostgreSQL documentation, you multiply by loops to get the real total.
In the plan above, the Index Scan says actual time=0.001..0.001 rows=1 loops=3200. That is not "ran once, returned 1 row total." It ran 3,200 times, returning 1 row each time, for 3,200 rows and roughly 3,200 × 0.001ms ≈ 3.2ms total. Misreading this is one of the most common ways people misjudge a plan: a node that looks trivial per execution can still dominate the total runtime once you account for how many times it actually ran. (When loops=1, as on the other two nodes here, no averaging is needed, since the actual value already is the total.)
Why is the row estimate so far off?
The outer Nested Loop and the Seq Scan both say rows=1 in the cost estimate, but actual rows=3200 once it ran. The planner thought this query would return one row and chose a Nested Loop, a strategy that's cheap if the outer side really is one row, because it means executing the inner Index Scan only once more. Instead it ran 3,200 times.
A nested loop that's correct for rows=1 and catastrophic for rows=3200 is one of the most common causes of a query that's fast in one environment and slow in another, because the planner's statistics were stale or skewed, not the query itself. The fix is usually ANALYZE on the table, or ALTER TABLE ... ALTER COLUMN ... SET STATISTICS on a skewed column, not rewriting the query.
What does "Rows Removed by Filter" mean?
Rows Removed by Filter: 996800 means the sequential scan read and then discarded nearly a million rows to find the 3,200 that matched customer_id = 42. That's the signature of a missing index: PostgreSQL has no way to jump straight to the matching rows, so it reads every page in the table and checks each one.
What's the difference between shared hit and shared read?
shared hit=2 read=3100 on that same Seq Scan: hit means the page was already in PostgreSQL's shared memory cache. read means it had to be fetched from outside that cache (the OS page cache, or disk if it wasn't there either). 3,100 reads against 2 hits means almost none of this table's data was cached, so this scan is bound by disk, not by CPU. If you only looked at CPU usage on the server, you'd see nothing wrong, because the bottleneck is I/O wait, not computation.
The three questions to ask of any plan
- Does actual rows match the estimated rows? A large mismatch (especially on the outer side of a Nested Loop) means the planner's statistics are stale, and the join strategy it picked may be wrong for the real data volume.
- Is Rows Removed by Filter large relative to what was returned? That's an unindexed (or wrongly indexed) filter, meaning the database is reading far more than it needs to.
- Is shared read large relative to shared hit? That's I/O bound by disk, not CPU. Plain
EXPLAIN ANALYZEoutput won't show you this, so you need theBUFFERSoption.
Seeing this as a diagram instead of text
GresTrace turns a pasted EXPLAIN (ANALYZE, BUFFERS) plan, in either text or JSON, into a visual node tree, flags the node responsible for most of the execution time, and for patterns like the ones above (bad row estimates, unindexed filter scans, reads bound by disk), shows an explanation in plain language of what's happening. It's free to use, with no run limit.