Diagnostic Queries
Symptoms
A DROP DATABASE targeted the database the current session is connected to. PostgreSQL refuses with SQLSTATE 55006 (object_in_use).
- You tried to drop the database you are connected to.
- A session cannot drop its own database.
- Must connect elsewhere first.
What the server log shows
ERROR: cannot drop the currently open database
Why PostgreSQL raises this — what the manual says
the DROP DATABASE reference (Description):
“It cannot be executed while you are connected to the target database.”
A database in use by your own session is “in use” and cannot be removed. PostgreSQL blocks the drop with 55006 until you connect to a different database.
Common causes
- Issuing DROP DATABASE while connected to that same database.
- Scripts that don’t switch databases before dropping.
How to fix it
- Connect to another database (e.g.
postgres), then run DROP DATABASE. - In psql:
\c postgresbefore dropping. - Use
DROP DATABASE … WITH (FORCE)(PG13+) from another database to disconnect other users.
Related & next steps
Reference: PostgreSQL 18 — DROP DATABASE.
Thanks — noted. This helps keep the database accurate.