Drop a database being accessed by another users?

Quick fix in PgAdmin: just create another empty database. Select it. Delete the first one. Voila.

You can also connect to the command line without selecting a specific database, and drop your database.

The problem here is not that other users are connected to the database, but that you are.


Simplest fix for this is restart the postgresql. After that You can get rid of database!


This post by Leeladharan Achar was helpful for me in working with this error.

It essentially boils down to:

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'target_db'
  AND pid <> pg_backend_pid();

DROP DATABASE 'target_db';

If you want to use the pgAdmin4 interface, you have to first delete/drop the db, then, before waiting for the error, you have to immediatelly disconnect from the same database, then it gets deleted without problem.