scribase
Performanceversion 1.11preloadedon by default

pg_stat_statements

Timing and call counts for every query shape (Insights reads it).

What it is for

pg_stat_statements groups queries by shape (constants replaced with placeholders) and keeps calls, total and mean time, rows and buffer use for each. It is the first place to look when the database feels slow: sort by total time to find what costs the most overall.

Enable it

sql
create extension if not exists pg_stat_statements with schema extensions;

Its library is preloaded when the database starts (shared_preload_libraries), so CREATE EXTENSION is all you need.

Example

sql
select
  calls,
  round(total_exec_time) as total_ms,
  round(mean_exec_time::numeric, 2) as mean_ms,
  left(query, 80) as query
from pg_stat_statements
order by total_exec_time desc
limit 10;

Questions

How do I enable pg_stat_statements?

Run create extension if not exists pg_stat_statements with schema extensions; in the SQL editor, or switch it on from the Extensions page in the console. You do not need superuser access.

Which version of pg_stat_statements is installed?

1.11, on Postgres 17.6, as read from the running engine on 2026-10-08. Check yours with: select extversion from pg_extension where extname = 'pg_stat_statements';

Upstream project: www.postgresql.org/docs/17/pgstatstatements.html

More performance extensions

  • hypopg Try an index without building it, to see if the planner would use it.
  • index_advisor Suggest the indexes that would speed up a query.
  • pg_repack Remove table and index bloat without long locks.