-
-
Save MaherSaif/d65c2224b92c2e1925883d732f0575fa to your computer and use it in GitHub Desktop.
Quickly look at pg_stat_statements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- based on https://www.crunchydata.com/blog/understanding-postgres-iops | |
SELECT | |
interval '1 millisecond' * total_exec_time AS "Total Exec. Time", | |
to_char ( | |
(total_exec_time / sum(total_exec_time) OVER ()) * 100, | |
'FM90D0' | |
) || '%' AS "Proportional Exec. Time", | |
to_char (calls, 'FM999G999G999G990') AS "Calls", | |
interval '1 millisecond' * (blk_read_time + blk_write_time) AS "Time Spent on IO", | |
CASE | |
WHEN length (query) <= 41 THEN query | |
ELSE regexp_replace (query, '^(.{20}).*(.{20})$', '\1 {...} \2') | |
END AS "Query", | |
queryid AS "Query ID" | |
FROM | |
pg_stat_statements | |
ORDER BY | |
4 DESC | |
LIMIT | |
10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment