I'm am using postgresql 9.6; while deleting my mrt_210119 database, getting an error like "ERROR: database "mrt_210119" is being accessed by other users DETAIL: There is 1 other session using the database"
2 Answers
you cannot drop a database while clients are connected to it. then also, if you want to drop database than you need some sql statement to run which required superuser and database owner privileges .
first make sure no one connect to database further any more by using below update statement.
UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'mydb';`
Below select statement terminate all current connection which is connected to database.
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'mydb';
than drop statement-
DROP DATABASE mydb;
Comments
If you have an active connection to your database, close it. If you don't, try pkill postgres and then delete.
2 Comments
Zakir Hossain
#nasdenkov - where i execute the 'pkill postgres' command ? do you clear it ?
nasdenkov
In the terminal of the machine that is hosting the database service.