Created
May 23, 2017 12:52
-
-
Save flavianmissi/30a47c51c81944b9662cb0ad5ea54f74 to your computer and use it in GitHub Desktop.
kill psql connection to a database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- show | |
SELECT * from pg_stat_activity; | |
-- Get the pid from the above query. Then: | |
-- kill | |
SELECT | |
pg_terminate_backend(pid) -- this is your 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 = '<dbname>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment