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; |