Machine-readable EXPLAIN output

Starting with PostgreSQL 9.0, there are several new formats you can produce EXPLAIN output in. In addition to the old text format, you can output in XML and JSON, which allows analysis using the rich library of tools found in many programming languages for operating on that sort of data. You can also produce plans in YAML format, which is interesting because it is both machine parsable and arguably easier to read than the standard format. Consider this relatively simple plan:

EXPLAIN SELECT * FROM customers WHERE customerid>1000 ORDER BY zip;
QUERY PLAN
    ----------
Sort  (cost=4449.30..4496.80 rows=19000 width=268)
   Sort Key: zip
   ->  Seq Scan on customers  (cost=0.00..726.00 rows=19000 width=268)
     Filter: (customerid ...

Get PostgreSQL 10 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.