Skip to content

Instantly share code, notes, and snippets.

@inouire
Created October 20, 2022 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inouire/2e8974fdbb58d00116b46d1c9d269234 to your computer and use it in GitHub Desktop.
Save inouire/2e8974fdbb58d00116b46d1c9d269234 to your computer and use it in GitHub Desktop.
Postgres find and kill long running queries
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__);
SELECT pg_terminate_backend(__pid__);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment