pg_stat_statements tracks planning and execution statistics of all SQL statements executed by a server.
Find the top 10 time-consuming queries
SELECT
round(
(
100 * total_exec_time / sum(total_exec_time) OVER ()
):: numeric,
2
) percent,
round(total_exec_time :: numeric, 2) AS total,
calls,
round(mean_exec_time :: numeric, 2) AS mean,
substring(query, 1, 200)
FROM
pg_stat_statements
ORDER BY
total_exec_time DESC
LIMIT
10;
Find the queries that are writing to the temp the most




Leave a Reply