Created
July 9, 2019 10:18
-
-
Save pwilken/ea54787187268e393ad93f9003913998 to your computer and use it in GitHub Desktop.
PostgreSQL Performance Problems
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
-- Check active queries | |
SELECT * FROM pg_stat_activity WHERE state = 'active'; | |
-- Terminate active queries with ProcessID | |
select pg_terminate_backend(pid); | |
-- Get all queries which are older then 5 minutes (idle or active) | |
SELECT pid, now() - pg_stat_activity.query_start AS duration, query, state | |
FROM pg_stat_activity WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes'; | |
-- Cancel all processes older then 5 minutes | |
SELECT pg_terminate_backend(queries.pid) from ( | |
SELECT pid, now() - pg_stat_activity.query_start AS duration, query, state | |
FROM pg_stat_activity WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes' | |
) AS queries; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment