PostgreSQL中删除数据库时出现“There are 2 other sessions using the database”报错

问题描述:

ERROR:  database "qinghua" is being accessed by other users
DETAIL:  There is 1 other session using the database.

错误原因:当前有其他的连接在使用该数据库
解决方案:
执行如下命令,断开qinghua数据库所有的连接。

select pg_terminate_backend(pid) from (select pid from pg_stat_activity where datname = 'Database_Name' ) a;

注:[$Database_Name]为数据库名称。
(谨慎删除数据库中的数据)

你可能感兴趣的:(postgresql,数据库)