Zakir Hossain
Zakir Hossain

Reputation: 444

How to delete postgresql9.6 database on centos7?

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"

Upvotes: 0

Views: 244

Answers (2)

Kandy
Kandy

Reputation: 673

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;

Upvotes: 1

nasdenkov
nasdenkov

Reputation: 54

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

Upvotes: 1

Related Questions