Tech Journal Back to Tech Journal

I get the message "cannot drop the currently open database" when trying to drop a DB in PostgreSQL, why?

First off, don't do something like:

dropdb -U postgres -W your_db_name

Since that connects to your_db_name, and makes it the active one! (The same applies to dropping the DB from within a command shell loaded using psql -U postgres your_db_name) The way to do it, is without connecting to a DB:

$ psql -U postgres
postgres=# drop database your_db_name

If that still fails, there might be something else (like an application) with an open connection to the DB. Restart the postgres server and try again.

Last updated on 2007-12-06 10:33:45 -0700, by Shalom Craimer

Back to Tech Journal