- 查询被锁的pid以及语句, state这列如果显示成 idle in transaction 就表示被锁了
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'
);
- 解锁: 拿着上面查询出的pid放入下面的语句中
// (只kill掉select)
SELECT pg_cancel_backend(pid)
// (kill掉 select、update、insert、delete)
SELECT pg_terminate_backend(pid)```