Created
September 21, 2023 09:18
-
-
Save Jeetah/b0595bb5c8c22601abcdb87dedd4486f to your computer and use it in GitHub Desktop.
PG Query Resource Consumption
This file contains 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
SELECT substring(query, 1, 100) AS short_query, | |
round(total_time::numeric, 2) AS total_time, | |
calls, | |
round(mean_time::numeric, 2) AS mean, | |
round((100 * total_time / sum(total_time::numeric) OVER ())::numeric, 2) AS percentage_cpu, | |
round(blk_read_time) AS read, | |
round((100 * blk_read_time / total_time)::numeric, 2) AS percentage_read, | |
round(blk_write_time) AS write, | |
round((100 * blk_write_time / total_time)::numeric, 2) AS percentage_write | |
FROM pg_stat_statements | |
WHERE calls > 10 | |
AND query NOT LIKE '<insufficient privilege>' | |
ORDER BY total_time DESC | |
LIMIT 20; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment