PostgreSQL does an amazing job populating query plans with useful information, but reading and understanding them can be tricky.

Here is a simple example:

 
Query
----------
explain select * from t order by c;

Query plan
----------
 Sort  (cost=813.32..837.48 rows=9664 width=32)
   Sort Key: c
   ->  Seq Scan on t  (cost=0.00..173.64 rows=9664 width=32)

This tells us that Postgres would do a Seq Scan of our table “t”, then a Sort by column “c”. The numbers tell us the Startup Cost, the Total Cost, the Plan Rows, and the Plan Width at each stage.

We have documented many of the operations and field definitions you’re likely to come across while using explain, along with performance advice and links to further learning resources.

For advice based on a specific query plan, check out our product pgMustard.

 


Last updated: January 2025, PostgreSQL 17

Issue reports and suggestions are welcome, please get in touch.