--1.查詢指定庫下面的活動會話,procpid字段表示會話Proc select * from pg_stat_activity where datname = 'dbname'; --2.中斷查詢,${procpid}表示上面查詢對應的procpid,下同 select pg_cancel_backend(${procpid}); --3.中斷會話鏈接 select pg_terminate_backend(${procpid}); --4.若是須要批量終止或中斷鏈接會話,能夠寫成函數或簡單拼湊一下,手動執行,如: select 'select pg_terminate_backend('||procpid||');',* from pg_stat_activity where datname = 'dbname'; select 'select pg_cancel_backend('||procpid||');',* from pg_stat_activity where datname = 'dbname';