Top queries by mean execution time#
What it does
Shows statements with the highest mean execution time.
Use when
- Database-backed requests are consistently slow.
- Looking for expensive statements to investigate with EXPLAIN.
Inspect
- Statements with high mean execution time and enough calls to be representative.
- Low cache hit percentages or substantial temporary data writes.
Result
Cumulative statistics since PostgreSQL last reset the relevant counters.
Columns#
| Column | Meaning |
|---|---|
calls |
Number of times the normalized statement was executed. |
datname |
Database in which the statement was executed. |
hit_percent |
Percentage of shared block accesses served from shared buffers. |
mean_exec_time |
Mean statement execution time in milliseconds. |
query |
Representative text of the normalized statement. |
queryid |
PostgreSQL identifier for the normalized statement. |
temp_blks_written |
Human-readable temporary data written by the statement. |
toplevel |
Whether the statement was executed as a top-level statement when available. |
total_exec_time |
Total statement execution time in milliseconds. |
user |
PostgreSQL role that executed the statement. |
wal_bytes |
WAL bytes generated by the statement. |
wal_size |
Human-readable WAL bytes generated by the statement. |
Parameters#
| Option | Type | Default | Description |
|---|---|---|---|
--database |
string | null |
Database name to filter by; null uses the current database. |
--limit |
integer, minimum 1, accepts NULL | 20 |
Maximum number of statements to show. Use NULL for no limit. |
--minimum-calls |
integer | 2 |
Minimum number of calls required for a statement to be included. |
Privileges#
Without membership of pg_monitor, other sessions' query text and statistics may be hidden, and pgcue warns that results may be incomplete.
Compatibility#
- pg_stat_statements 1.5+
Related checks#
- Long-running transactions
activity.long_transactions