Skip to content

Instantly share code, notes, and snippets.

@ilomon10
Last active April 10, 2021 09:39
Show Gist options
  • Save ilomon10/132e9a1857feaf35f46d750c8e41e2e5 to your computer and use it in GitHub Desktop.
Save ilomon10/132e9a1857feaf35f46d750c8e41e2e5 to your computer and use it in GitHub Desktop.
Kill postgresql session/connection
-- Ref: https://stackoverflow.com/a/5109190/8271526
SELECT
pg_terminate_backend(procpid)
FROM
pg_stat_activity
WHERE
-- don't kill my own connection!
procpid <> pg_backend_pid()
-- don't kill the connections to other databases
AND datname = 'database_name'
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment