Forked from jeffjohnson9046/kill-all-connections-to-db.sql
Created
May 13, 2021 06:40
-
-
Save m0zgen/48c0ad1823b2b99105ad98e37b03e7aa to your computer and use it in GitHub Desktop.
How to kill all connections to a Postgres 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
-- Accepted answer from here: https://stackoverflow.com/questions/5408156/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it | |
SELECT pg_terminate_backend(pg_stat_activity.pid) | |
FROM pg_stat_activity | |
WHERE pg_stat_activity.datname = '[your database name goes here]' | |
AND pid <> pg_backend_pid(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment