Skip to content

Instantly share code, notes, and snippets.

@carltondickson
Last active February 8, 2021 09:34
Show Gist options
  • Save carltondickson/c356325e0d03459bca73ff13965acce6 to your computer and use it in GitHub Desktop.
Save carltondickson/c356325e0d03459bca73ff13965acce6 to your computer and use it in GitHub Desktop.
Useful Postgres queries

Source: Hans-Jürgen Schönig - PostgreSQL performance in 5 minutes https://youtu.be/5M2FFbVeLSs?t=757

SELECT substring(query, 1, 5000) 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_overall
FROM pg_stat_statements 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