Diagnostic Queries
Symptoms
A DROP DATABASE failed because other sessions are still connected to that database. PostgreSQL raises SQLSTATE 55006 (object_in_use).
- Other users are connected to the target database.
- A database with active sessions can’t be dropped.
- Common when an app pool still holds connections.
What the server log shows
ERROR: database "appdb" is being accessed by other users
DETAIL: There are 4 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.”
A database in use by active sessions is “in use” and cannot be removed safely. PostgreSQL blocks the drop with 55006 until those sessions disconnect (or are terminated).
Common causes
- Application connection pools still attached to the database.
- Idle sessions left open.
- Monitoring/admin tools connected to it.
How to fix it
- Terminate connections, then drop:
DROP DATABASE appdb WITH (FORCE);(PG13+). - Manually terminate sessions via
pg_terminate_backend()filtered bydatname. - Stop the application/pool before dropping the database.
Diagnostic query
SELECT pid, usename, application_name, state FROM pg_stat_activity WHERE datname = 'appdb';
Identify and stop the listed sessions before dropping (or use WITH FORCE).
Related & next steps
Reference: PostgreSQL 18 — DROP DATABASE.
Thanks — noted. This helps keep the database accurate.