Created
July 8, 2020 14:04
-
-
Save jweyrich/34732e248f1c5aedb9433aad664866c4 to your computer and use it in GitHub Desktop.
PostgreSQL performance troubleshooting
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
psql -h <host> -U <user> -W -d postgres | |
SELECT * from pg_stat_activity; | |
SELECT * from pg_stat_database; | |
# Queries running during >5 minutes | |
SELECT | |
pid, | |
datname, | |
query, | |
now() - pg_stat_activity.query_start AS duration, | |
time(pg_stat_activity.query_start) as started_at | |
FROM pg_stat_activity | |
WHERE pg_stat_activity.query <> ''::text | |
AND now() - pg_stat_activity.query_start > interval '5 minutes'; | |
SELECT | |
pid, | |
datname, | |
query, | |
now() - pg_stat_activity.query_start AS duration | |
FROM pg_stat_activity | |
WHERE pg_stat_activity.query <> ''::text | |
AND now() - pg_stat_activity.query_start > interval '5 minutes'; | |
# Kill pg sub-process: | |
SELECT pg_cancel_backend(<pid>); | |
# Really terminate it! | |
SELECT pg_terminate_backend(<pid>) from pg_stat_activity where datname='<datname>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment