Skip to content

Instantly share code, notes, and snippets.

@pyprism
Created February 23, 2019 03:49
Show Gist options
  • Save pyprism/d03e5168e9c7aa8d6adf25ac034e7aa0 to your computer and use it in GitHub Desktop.
Save pyprism/d03e5168e9c7aa8d6adf25ac034e7aa0 to your computer and use it in GitHub Desktop.
A quick/dirty top 20 list of your slowest, or biggest, or hardest on the cpu queries. (Postgres)
SELECT query
, calls
, total_time
, total_time / calls as time_per
, stddev_time
, rows
, rows / calls as rows_per
,100.0 * shared_blks_hit / nullif(shared_blks_hit + shared_blks_read, 0) AS hit_percent
FROM pg_stat_statements
WHERE query not similar to '%pg_%'
and calls > 500
--ORDER BY calls
--ORDER BY total_time
order by time_per
--ORDER BY rows_per
DESC LIMIT 20;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment