Created
March 30, 2015 22:52
-
-
Save pguelpa/5935df7e90a46d49f681 to your computer and use it in GitHub Desktop.
PostgreSQL Reaper
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
DO $$DECLARE row record; | |
BEGIN | |
FOR row IN SELECT pid, query FROM pg_stat_activity WHERE query_start < NOW() - interval '30 minutes' LOOP | |
RAISE NOTICE 'Killing query: %s', row.query; | |
PERFORM pg_cancel_backend(row.pid); | |
END LOOP; | |
END$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment