0

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 2

1

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;
Sign up to request clarification or add additional context in comments.

Comments

1

If you have an active connection to your database, close it. If you don't, try pkill postgres and then delete.

2 Comments

#nasdenkov - where i execute the 'pkill postgres' command ? do you clear it ?
In the terminal of the machine that is hosting the database service.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.