PostgreSQL 查询被锁阻塞的连接

主要是查pg_lock,再结合pg_stat_activity和pg_class,我用的SQL是:

select relation::regclass, s.pid, granted, client_hostname, application_name, usename, query from pg_locks l, pg_stat_activity s where s.pid = l.pid;

可以根据查出来的pid或客户端,找到阻塞的连接和进程,手动杀掉

SELECT pg_cancel_backend(<pid>);

强制结束进程

SELECT pg_terminate_backend(11929);

原文链接:https://blog.csdn.net/howard_shooter/article/details/122063644

posted @ 2022-04-12 16:24  hubb  阅读(251)  评论(0编辑  收藏  举报