Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop a database being accessed by another users?

I'm trying to drop a database from PgAdmin 3 and I get this error message:

ERROR: can't delete current database
SQL state: 55006

how can I force the delete/fix this error, of this database?

like image 962
josernestodavila Avatar asked Mar 19 '09 21:03

josernestodavila


1 Answers

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';
like image 170
Gio Avatar answered Nov 09 '22 23:11

Gio