Skip to content

Instantly share code, notes, and snippets.

@Jeetah
Created September 21, 2023 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jeetah/b0595bb5c8c22601abcdb87dedd4486f to your computer and use it in GitHub Desktop.
Save Jeetah/b0595bb5c8c22601abcdb87dedd4486f to your computer and use it in GitHub Desktop.
PG Query Resource Consumption
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