object in use
SQLSTATE 55006 is raised when an operation cannot proceed because the target object is currently in use by another session — for example, attempting to DROP a database while active connections exist, or reconfiguring an object that is currently being accessed.
- 1DROP DATABASE while client sessions are connected to it
- 2ALTER TABLESPACE or similar DDL on an object currently in use by active queries
DROP DATABASE with active connections.
DROP DATABASE myapp; -- active sessions are connected
expected output
ERROR: database "myapp" is being accessed by other users DETAIL: There are 3 other sessions using the database.
Fix 1
Terminate active connections before dropping the database
WHEN When dropping a database with active sessions.
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'myapp' AND pid <> pg_backend_pid(); DROP DATABASE myapp;
Why this works
pg_terminate_backend closes all other connections to the database, clearing the way for DROP DATABASE.
Fix 2
Use DROP DATABASE WITH (FORCE) in Postgres 13+
WHEN When immediate forced deletion is needed.
DROP DATABASE myapp WITH (FORCE);
Why this works
The FORCE option terminates existing connections before dropping the database in one step.
✕ Use pg_terminate_backend on the wrong database in production
Terminating connections on the wrong database causes an outage for legitimate users.
DROP DATABASE WITH (FORCE) option added in Postgres 13.
Class 55 — Object Not in Prerequisite State
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev