Skip to content

Instantly share code, notes, and snippets.

@avshyz
Last active June 30, 2020 12:03
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 avshyz/b0ef6290dac14692238b2dffb6fe10f1 to your computer and use it in GitHub Desktop.
Save avshyz/b0ef6290dac14692238b2dffb6fe10f1 to your computer and use it in GitHub Desktop.
[Postgres Delete Locks] delete all hang queries #postgres #db
SELECT pg_terminate_backend(b.pid)
from (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') as b
where pid <> pg_backend_pid();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment