Last active
March 18, 2019 09:51
-
-
Save hjhart/65a5ab33623c14995b48e1e7bdd3ff51 to your computer and use it in GitHub Desktop.
Identifying Expensive PostgreSQL queries
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 substr(query, 0, 250), calls, | |
to_char(total_time/(60*60), '999,999,9999,999') as "Cumulative Time (hrs)", rows, | |
to_char(total_time/calls, '999.999') as per_call_ms | |
from pg_stat_statements | |
order by total_time desc | |
limit 12; |
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 pg_stat_statements_reset() |
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
query | calls | Cumulative Time (hrs) | rows | per_call_ms | |
-------------------------------------------------------------------------------+-------------+-----------------------+------------+------------- | |
SELECT "posts".* FROM "posts" WHERE "posts"."crush_id" = ? LIMIT ? | 256078900 | 1510,418 | 35940202 | 21.234 | |
UPDATE "posts" SET "state" = ?, "updated_at" = ? WHERE "posts"."id" = ? | 48610033 | 1086,287 | 48610033 | 80.449 | |
etc... etc... | |
(12 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Total_time is in milliseconds, so to convert it to hours you should divide it by 1000.