Postgres 数据库查询表锁,释放表锁
1.查询表锁
sql
select
t3.datname 数据库名,
t2.relname 表名,
t1.pid sql线程号,
t3.usename 用户名,
t3.client_addr 客户端地址,
t3.query_start 查询开始时间,
t3.wait_event_type 等待事件类型 ,
t3.wait_event 等待事件,
t3.state 状态,
t1.mode 锁类型,
t1.granted 是否持锁,
t1.fastpath 是否通过快速路径获锁,
t3.query 查询语句
from pg_locks t1
left join pg_class t2 on t1.relation = t2.oid
left join pg_stat_activity t3 on t1.pid = t3.pid
where t1.locktype ='relation'
2.释放表锁
sql
-- 1 步骤中查询出来的造成锁表的pid
select pg_terminate_backend(pid)