PostgreSQL · SQL
SELECT LEFT(query, 160) AS statement,
calls,
ROUND(total_exec_time::numeric, 0) AS total_ms,
ROUND(mean_exec_time::numeric, 2) AS mean_ms,
rows,
ROUND(100.0 * shared_blks_hit / NULLIF(shared_blks_hit + shared_blks_read, 0), 1) AS cache_hit_pct
FROM pg_stat_statements
ORDER BY total_exec_time DESC
LIMIT 20Needs something on the server: The pg_stat_statements extension must be installed and in shared_preload_libraries.
This query is part of the "PostgreSQL health" pack: connect the database in DataRunner and install the whole pack — queries, dashboard and checks — at once.