CertGrid CertGrid
Hands-on Lab·PostgreSQL

PostgreSQL Query Plans with EXPLAIN

EXPLAIN (ANALYZE, BUFFERS) gives estimates, actuals and the number that matters most - how many pages were touched. Adding one index takes a query from 4,546 buffers and two parallel workers to 21 buffers and none.

Performance Guide 33 of 47 Intermediate

BUFFERS is on by default with ANALYZE from PostgreSQL 18. On earlier versions you must ask for it, and it is the option most worth asking for.

Every command on this page ran on db-a01.
Server NameIP AddressOSRolesCPURAMHDD
db-a01192.168.0.81Ubuntu 26.04 LTSPrimary / Source / Replica Set Member 12 Core4 GB50 GB

This guide includes

Use this when a query is slow and you need the plan rather than a guess. This matters because EXPLAIN (ANALYZE, BUFFERS) gives estimates, actuals and buffer counts - and a plan is read inside out rather than top down.

Before you start

  1. Build a table worth planning against

  2. Read a plan with no index

  3. Add the index and compare

  4. Filter on the second column only

Official sources