Last active
October 18, 2022 02:42
-
-
Save mlanett/42b6ad06aabffcffe6a5937ad467f1f2 to your computer and use it in GitHub Desktop.
Find and Kill 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 pid, | |
age(clock_timestamp(), query_start), | |
usename, | |
state, | |
-- get rid of newlines, runs of spaces | |
regexp_replace(query, E'[\\n\\r ]+', ' ', 'g' ) as query | |
-- , pg_terminate_backend(pid) -- UNCOMMENT TO KILL | |
FROM pg_stat_activity | |
WHERE query LIKE '%' -- Edit as necessary to match your query | |
AND query NOT LIKE 'SELECT pid,%' -- Don't kill the query-killing query… | |
AND state != 'idle' -- Idle connections are innocent. | |
AND usename != 'rdsadmin' -- Can't kill these, don't try. | |
ORDER BY age DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment