55006ERRORTier 2 — Caution✅ HIGH confidenceobject in use
What this means
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.
Why it happens
- 1DROP DATABASE while client sessions are connected to it
- 2ALTER TABLESPACE or similar DDL on an object currently in use by active queries
How to reproduce
DROP DATABASE with active connections.
DROP DATABASE myapp; -- active sessions are connectedFix 1: Terminate active connections before dropping the database
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 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.
What not to do
Use pg_terminate_backend on the wrong database in production
Why it's wrong: Terminating connections on the wrong database causes an outage for legitimate users.
Version notes
Postgres 13+DROP DATABASE WITH (FORCE) option added in Postgres 13.Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 55 — Object Not in Prerequisite State
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE for object-in-use errors. Stable across all versions.
See also
🔗 Related errors
📄 Reference pages