Find slow queries in Postgres

Sql

Ranks statements by total time spent. Needs the pg_stat_statements extension enabled.

SELECT
  round(total_exec_time::numeric, 1) AS total_ms,
  calls,
  round(mean_exec_time::numeric, 2) AS mean_ms,
  query
FROM pg_stat_statements
ORDER BY total_exec_time DESC
LIMIT 20;

More in Databases

Random picks