Created
July 26, 2016 19:38
-
-
Save luiscape/ee7aeb49aea96ebe7dd11339cb29e16a to your computer and use it in GitHub Desktop.
Closes all PostgreSQL connections except for the one sending this query.
This file contains 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
# | |
# The following statement closes | |
# all PostgreSQL connections except | |
# for the one currently open (i.e. | |
# the one sending the query). | |
# | |
# Original solution by: http://goo.gl/znBpH | |
# | |
SELECT pg_terminate_backend(pg_stat_activity.pid) | |
FROM pg_stat_activity | |
WHERE pg_stat_activity.datname = 'TARGET_DB' | |
AND pid <> pg_backend_pid(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment