ERROR: database "x" is being accessed by other users — There is 1 other session using the database.

DROP/RENAME DATABASE can’t run while other sessions are connected.

Seen on: PostgreSQL

Meaning

Your app, a GUI tool or another psql session keeps a connection open.

Common causes

  • App or pool still connected
  • GUI client (pgAdmin, DBeaver) open
  • Another terminal session

⚡ Quick fix

  1. Stop the app / close clients
  2. PostgreSQL 13+: DROP DATABASE x WITH (FORCE)
  3. Terminate sessions with pg_terminate_backend

Detailed fix by platform

PostgreSQL

  1. DROP DATABASE appdb_test WITH (FORCE);

How to diagnose

  1. Sessions — SELECT * FROM pg_stat_activity WHERE datname = 'x'
  2. Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.