Diagnostic Queries
Symptoms
DROP DATABASE (or another exclusive operation) failed because other sessions are still connected to it. PostgreSQL raises SQLSTATE 55006 (object_in_use).
- A DETAIL reports how many other sessions are connected.
- Common when dropping/renaming a database with live connections.
- You must disconnect those sessions first.
What the server log shows
ERROR: database "orders" is being accessed by other users
DETAIL: There are 3 other sessions using the database.
Why PostgreSQL raises this — what the manual says
the DROP DATABASE reference (Description):
“Also, if anyone else is connected to the target database, this command will fail unless you use the FORCE option described below.”
Dropping or renaming a database requires exclusive access. While other backends are attached to it, PostgreSQL refuses the operation with 55006 to avoid disrupting active sessions.
Common causes
- Open sessions (including your own) connected to the target database.
- A connection pool holding idle connections to it.
- Background jobs or replicas attached to the database.
How to fix it
- Connect to a different database (e.g.
postgres) before dropping. - Terminate other sessions:
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='orders' AND pid <> pg_backend_pid();. - In PG13+, use
DROP DATABASE orders WITH (FORCE);to disconnect users automatically.
Related & next steps
Reference: PostgreSQL 18 — DROP DATABASE.
Thanks — noted. This helps keep the database accurate.