You can't drop postgres database while clients are connected to it. Quite robust way to work around it, is
You can't do it all using only
- Make sure noone can connect to this database
update pg_database set datallowconn = 'false' where datname = 'mydb'; - Force disconnection of all clients connected to this database.
For postgres < 9.2:
SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = 'mydb';
for postgres versions >= 9.2 changeprocpidtopid:
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'mydb'; - Drop it
DROP DATABASE mydb;
You can't do it all using only
dropdb utility - which is a simple wrapper around DROP DATABASE server query.
No comments:
Post a Comment