CertGrid CertGrid
Configuration·PostgreSQL

PostgreSQL Query Statistics with pg_stat_statements

One extension, one restart, and every statement the server runs is aggregated by shape with call counts and timings - finding the query that takes 5 ms and runs a hundred thousand times, which no slow-query threshold ever will.

Performance Guide 36 of 47 Intermediate

Written against the versions above. `pg_stat_statements` must be in `shared_preload_libraries`, which requires a restart. It is the single most valuable extension to have installed before you need it.

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

Before you start

  1. Load the extension and reset the counters

  2. Run three queries and read them back aggregated

Official sources