Skip to content

Instantly share code, notes, and snippets.

@pjb3
Created March 25, 2015 02:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjb3/76ef1b996ba3d3b9b6c8 to your computer and use it in GitHub Desktop.
Save pjb3/76ef1b996ba3d3b9b6c8 to your computer and use it in GitHub Desktop.
Kill all queries that have been running for more than a minute in a Postgres datavase
select pg_terminate_backend(pid)
from (
SELECT
pid
FROM pg_stat_activity
WHERE query <> '<insufficient privilege>'
AND state <> 'idle'
AND pid <> pg_backend_pid()
AND query_start < now() - interval '1 minute'
ORDER BY query_start DESC) t;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment