Last active
December 30, 2019 03:55
-
-
Save platinumthinker/df06eb1f2839af5d5ccced44a441c01c to your computer and use it in GitHub Desktop.
Slow postgress queries
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
| SELECT | |
| relname, | |
| seq_scan - idx_scan AS too_much_seq, | |
| CASE | |
| WHEN | |
| seq_scan - coalesce(idx_scan, 0) > 0 | |
| THEN | |
| 'Missing Index?' | |
| ELSE | |
| 'OK' | |
| END, | |
| pg_relation_size(relname::regclass) AS rel_size, seq_scan, idx_scan | |
| FROM | |
| pg_stat_all_tables | |
| WHERE | |
| schemaname = 'public' | |
| AND pg_relation_size(relname::regclass) > 80000 | |
| ORDER BY | |
| too_much_seq DESC; |
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
| CREATE EXTENSION pg_stat_statements; | |
| SELECT | |
| pd.datname | |
| ,pss.query AS SQLQuery | |
| ,pss.rows AS TotalRowCount | |
| ,(pss.total_time / 1000 / 60) AS TotalMinute | |
| ,((pss.total_time / 1000 / 60)/calls) as TotalAverageTime | |
| FROM pg_stat_statements AS pss | |
| INNER JOIN pg_database AS pd | |
| ON pss.dbid=pd.oid | |
| ORDER BY 1 DESC | |
| LIMIT 10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment