SQLSTATE 55006 ERROR Class 55: Object Not In Prerequisite State

object_in_use database “…” is being accessed by other users — 55006

PostgreSQL error "database "…" is being accessed by other users" (SQLSTATE 55006): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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

  1. Connect to a different database (e.g. postgres) before dropping.
  2. Terminate other sessions: SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='orders' AND pid <> pg_backend_pid();.
  3. In PG13+, use DROP DATABASE orders WITH (FORCE); to disconnect users automatically.

Related & next steps

Reference: PostgreSQL 18 — DROP DATABASE.

Was this helpful?