Skip to content

Instantly share code, notes, and snippets.

@dramsay
Created January 10, 2020 14:41
Show Gist options
  • Save dramsay/d71c00eb9cc60e500abf04e284cd6bd5 to your computer and use it in GitHub Desktop.
Save dramsay/d71c00eb9cc60e500abf04e284cd6bd5 to your computer and use it in GitHub Desktop.
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';
-- can take a few minutes
SELECT pg_cancel_backend(__pid__);
-- effectively kill -9, need to be careful
SELECT pg_terminate_backend(__pid__);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment