Created
January 18, 2018 01:16
-
-
Save mladenp/091b6c90a13d14f0217f72fe5cc1ed6a to your computer and use it in GitHub Desktop.
Postgres DROP db - right way
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
/* Disable connection to Database */ | |
UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'mydb'; | |
/* Get postgres process id */ | |
SELECT pg_backend_pid(); | |
/* Force Disconnect all clients ( use pid from previous step) */ | |
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'mydb'; | |
/* Finaly Drop database */ | |
DROP DATABASE mydb; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment