Symptoms
The operation cannot proceed because the object is currently in use.
- The error is written to the server log and returned to the client carrying
SQLSTATE 55006. - Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
- PL/pgSQL can trap it by name:
EXCEPTION WHEN object_in_use THEN.
Environment
Severity: ERROR | PostgreSQL versions: 12, 13, 14, 15, 16, 17
Reproduce with the exact statement and read the full message in the server log (raise log_min_messages / set log_min_error_statement for more context).
Root Cause
Another session holds the object — for example dropping a database with active connections.
Diagnostic Queries
Recovery
Steps to resolve 55006:
- Disconnect users of the object:
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'db' AND pid pg_backend_pid();. - Retry once the object is free; schedule during a maintenance window.
Reference: PostgreSQL error codes — Class 55 (Object Not In Prerequisite State).
Thanks — noted. This helps keep the database accurate.