postgresql 锁表查询语句

1 查找锁表的pid

select pid from pg_locks l join pg_class t on l.relation = t.oid where t.relkind = 'r' and t.relname = 'lockedtable';

2 查找锁表的语句

 

select pid, state, usename, query, query_start from pg_stat_activity where pid in ( select pid from pg_locks l join pg_class t on l.relation = t.oid and t.relkind = 'r' where t.relname =  'lockedtable');

3 查找所有活动的被锁的表

 

select pid, state, usename, query, query_start
from pg_stat_activity
where pid in (
select pid from pg_locks l
join pg_class t on l.relation = t.oid
and t.relkind = 'r'

);

 

4 解锁

 
SELECT pg_cancel_backend(pid);

 参考:postgresql 锁表查询语句 - wolbo - 博客园 (cnblogs.com)

 

 

posted @ 2021-08-30 15:02  littlevigra  阅读(1119)  评论(2编辑  收藏  举报