PG
PRO
55006ERRORTier 2 — Caution✅ HIGH confidence

object in use

Category: Object Not in Prerequisite StateVersions: All Postgres versions

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

  1. 1DROP DATABASE while client sessions are connected to it
  2. 2ALTER TABLESPACE or similar DDL on an object currently in use by active queries

How to reproduce

DROP DATABASE with active connections.

trigger — this will ERROR
DROP DATABASE myapp; -- active sessions are connected
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 dropping a database with active sessions.

fix
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.

fix
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

📄 Reference pages

DROP DATABASEpg_terminate_backendpg_stat_activity
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →