Skip to content

Instantly share code, notes, and snippets.

@germanow
Created February 7, 2020 12:50
Show Gist options
  • Save germanow/1ab58af32ce547929dd469dcc929480d to your computer and use it in GitHub Desktop.
Save germanow/1ab58af32ce547929dd469dcc929480d to your computer and use it in GitHub Desktop.
Finding and killing long running queries on PostgreSQL
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';
SELECT pg_cancel_backend(__pid__);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment