我正在尝试删除数据库。我重启了Postgresql服务:
sudo systemctl stop postgresql
sudo systemctl start postgresql
然而:
# drop database my_db1;
ERROR: database "my_db1" is being accessed by other users
为什么这样以及如何删除它?
这也不起作用:
select pg_terminate_backend(pg_stat_activity.pid)
from pg_stat_activity
where pg_stat_activity.datname = 'my_db1' and pid <> pg_backend_pid();
因为我运行后仍然存在活动连接;
答案 0 :(得分:1)
sudo dropdb my_db1
查看man dropdb
了解详情。
答案 1 :(得分:0)
REVOKE CONNECT ON DATABASE YourDbName FROM PUBLIC;
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE datname = 'YourDbName';
DROP DATABASE YourDbName;