序言
1.1 专栏简介
⭐欢迎来到我的 CSDN 专栏——【TrobleShooting】
在这个专栏中,我将分享我在 IT 运维过程中遇到的一些 故障解决方案 。在实际工作中,我们经常会遇到各种千奇百怪的问题,而解决这些问题往往需要我们具备丰富的经验和扎实的技术功底。希望通过分享这些解决方案,能够帮助大家更快地找到问题的根源,更有效地解决故障,从而提升我们的工作效率。
故障案例
2.1 报错信息
使用drop database icpdb;删除数据库的时候,提示
ERROR: Database “icpdb” is being accessed by other users. You can stop all connections by command: “clean connection to all force for database XXXX;” or wait for the sessions to end by querying view: “pg_stat_activity”.
DETAIL: There are 5 other sessions using the database.
具体错误如下👇:
ERROR: Database "icpdb" is being accessed by other users. You can stop all connections by command: "clean connection to all force for database XXXX;" or wait for the sessions to end by querying view: "pg_stat_activity".
DETAIL: There are 5 other sessions using the database.
2.2 解决方案
⭐ 断开所有相关的数据库连接,再次删除数据库
# 断开所有连接
SELECT
pg_terminate_backend(pg_stat_activity.pid)
FROM
pg_stat_activity
WHERE
datname='icpdb'
AND
pid<>pg_backend_pid();
--查找相关连接数据库的主机信息(如果有程序会不停的连的话只能把连的程序停了才能删除)
SELECT
*
FROM
pg_stat_activity
WHERE
datname='icpdb'
# 再次删除
drop database icpdb;