What pg_stat_statements means
pg_stat_statements is a supplied PostgreSQL extension that tracks planning and execution statistics for normalized statement fingerprints. Similar statements can be combined when their parsed structures match after literal constants are normalized.
Each row represents a combination that includes database, user, query identifier, and whether the statement is top-level. The counters are cumulative, not a live list of currently running queries.
Confirm the extension location
Extensions can be installed outside public. This read-only catalog query identifies the schema that owns the extension objects in the current database.
SELECT
e.extname AS extension_name,
n.nspname AS extension_schema,
e.extversion AS extension_version
FROM pg_extension AS e
JOIN pg_namespace AS n ON n.oid = e.extnamespace
WHERE e.extname = 'pg_stat_statements';No row means the extension is not installed in this database, even if the module is active for the PostgreSQL server. A relation-not-found error can also mean the extension schema is absent from the role's search path; use the discovered schema when qualifying the view.
Rank query fingerprints without SQL text
This bounded query deliberately omits the query column. Run it with a role that has the required statistics visibility and with the extension schema available on the search path.
SELECT
queryid::text AS queryid,
calls,
total_exec_time,
mean_exec_time,
rows,
shared_blks_hit,
shared_blks_read,
temp_blks_written,
wal_bytes
FROM pg_stat_statements
WHERE dbid = (
SELECT oid
FROM pg_database
WHERE datname = current_database()
)
ORDER BY total_exec_time DESC
LIMIT 50;Interpret the main counters
| Counter | Useful interpretation | Important limit |
|---|---|---|
total_exec_time | Cumulative execution time attributed to the fingerprint. | A large value can come from many fast calls or a few slow calls. |
mean_exec_time | Mean execution time across completed calls in the available window. | An average can hide variance and does not describe the currently running query. |
calls | Number of completed executions attributed to the entry. | It is cumulative and can change independently of planning counts. |
rows | Total rows retrieved or affected by the statement. | It is not necessarily rows returned to an end user. |
shared_blks_hit / shared_blks_read | Shared-buffer hits and blocks that required a read. | There is no universal healthy hit-ratio threshold for every workload. |
temp_blks_written | Cumulative temporary blocks written by the statement. | It does not by itself prove that a memory setting should be raised. |
Know the statistics window
The optional pg_stat_statements_info view reports when all statement statistics were last reset and how often entries were deallocated after the configured entry limit was exceeded. Locate it in the extension schema rather than assuming public.pg_stat_statements_info.
Without a reset timestamp, label the window unknown. Restarts, explicit resets, configuration changes, and entry deallocation can all limit comparisons. A fingerprint's queryid also has limited stability guarantees and should not be assumed stable across PostgreSQL major versions.
Common misleading interpretations
- The top cumulative contributor is not necessarily the slowest individual call or the current bottleneck.
- Two visually different statements can share a normalized entry, and identical-looking text can produce different identifiers when its parsed meaning differs.
- A cache-hit percentage is not a direct storage, disk-latency, or provider-cost measurement.
- One snapshot cannot show whether a contributor is accelerating; compare compatible counter differences across a known interval.
- Resetting statistics to simplify analysis destroys the existing observation window and should not be a routine diagnostic shortcut.
When DatabaseMeter can help
The pg_stat_statements analyzer ranks bounded fingerprints by total contribution, frequency, average execution time, planning time, temporary blocks, and WAL counters. Manual CSV, TSV, and JSON analysis stays in the browser; query-text columns are discarded before analysis and export.
An eligible connected database can return the same bounded counters without copy and paste. DatabaseMeter does not retain SQL text, does not reset PostgreSQL statistics, and does not turn a cumulative ranking into an automatic remediation.
Definitions and sources
Provider and PostgreSQL statements last reviewed August 29, 2026. Pricing consoles and invoices remain authoritative.
Related database resources
How to read pg_stat_activity
Inspect current session states and waits without treating a single activity snapshot as a trend.
Open resourcepg_stat_statements analyzer
Rank bounded query fingerprints from CSV, TSV, JSON, or an eligible connected database—without SQL text.
Open resourcePostgreSQL health check
Analyze bounded PostgreSQL catalog statistics locally—without connecting your database.
Open resource