sql 断开数据库pg_stat_activity pg_terminate_backend

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 断开数据库pg_stat_activity pg_terminate_backend相关的知识,希望对你有一定的参考价值。

-- Query pg_stat_activity and get the pid values you want to kill, then issue SELECT pg_terminate_backend(pid int) to them.

-- PostgreSQL 9.2 and above:

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB' -- ← change this to your DB
  AND pid <> pg_backend_pid();

-- PostgreSQL 9.1 and below:

SELECT pg_terminate_backend(pg_stat_activity.procpid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB' -- ← change this to your DB
  AND procpid <> pg_backend_pid();
Once you disconnect everyone you will have to disconnect and issue the DROP DATABASE command from a connection from another database aka not the one your trying to drop.

以上是关于sql 断开数据库pg_stat_activity pg_terminate_backend的主要内容,如果未能解决你的问题,请参考以下文章

如何用Sql语句实现断开使用本数据库的链接的功能?

SQL Server2005还原数据库之前,怎么断开所有的用户链接?

Sql Server 强制断开数据库已有连接的方法

[SQL]用SQL语句断开某个数据库的所有活动连接

添加的 H2 数据在断开连接之前不会刷新

怎样用SQL语句断开数据库的连接?