Skip to content

Instantly share code, notes, and snippets.

@danishabdullah
Last active February 27, 2024 19:55
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danishabdullah/670907788af8f3b0d9c9 to your computer and use it in GitHub Desktop.
Save danishabdullah/670907788af8f3b0d9c9 to your computer and use it in GitHub Desktop.
Postgres kill all idle in transaction

given a database named db:

SELECT pg_terminate_backend(pid) 
FROM pg_stat_activity 
WHERE datname='db'
  AND state = 'idle in transaction'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment