Skip to content

Instantly share code, notes, and snippets.

@chetanppatil
Created July 26, 2018 06:04
Show Gist options
  • Save chetanppatil/dce5ed3eec20a31cb4260fc774643e6e to your computer and use it in GitHub Desktop.
Save chetanppatil/dce5ed3eec20a31cb4260fc774643e6e to your computer and use it in GitHub Desktop.
Terminate connection/session in PostgreSQL
SELECT
pg_terminate_backend(pid)
FROM
pg_stat_activity
WHERE
-- don't kill my own connection!
pid <> pg_backend_pid()
-- don't kill the connections to other databases
AND datname = '<db-name-here>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment