Last active
October 19, 2018 04:31
-
-
Save gmhawash/9145355 to your computer and use it in GitHub Desktop.
Rename a postgresql database with open connection
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
Ref: http://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection | |
Postgres (rightfully) stops you from renaming a database while it has connections open connections. To test an exception handler which attempts to handle lost database connection, I was able to do the following: | |
1. \c (database that you are not trying to rename) | |
\c template1 | |
2. select pg_terminate_backend(pid) from pg_stat_activity where datname ~ 'db_name_you_are_trying_to_rename'; | |
3. alter database db_name_you_are_trying_to_rename rename to new_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment