Skip to content

Instantly share code, notes, and snippets.

@Dombo
Created February 11, 2019 00:16
Show Gist options
  • Save Dombo/cec92c099c2b09f670528003d37dc138 to your computer and use it in GitHub Desktop.
Save Dombo/cec92c099c2b09f670528003d37dc138 to your computer and use it in GitHub Desktop.
WITH longrunners AS (
SELECT pid, age(query_start, clock_timestamp()), query_start, usename, query
FROM pg_stat_activity
WHERE
now() - query_start > '3 minutes'::interval
AND
query NOT ILIKE '%vacuum%'
ORDER BY query_start desc
)
SELECT pg_cancel_backend(pid)
--- SELECT pg_terminal_backend(pid) if they do not yield
FROM longrunners;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment