PostgreSQL 查看被锁的表

查看被锁的表:

1
2
3
4
5
6
7
8
9
10
select
b.relname,
a.pid,
a.locktype,
a.database,
a.mode,
a.relation
from pg_locks a
join pg_class b on a.relation = b.oid
where b.relname = '表名';

释放锁(取消后台操作,回滚未提交事物):

1
select pg_cancel_backend(pid); -- pid 就是上面查询到的 pid 列