1、查看表是否有锁:
select a.locktype,a.database,a.pid,a.mode,a.relation,b.relname
from pg_locks a
join pg_class b on a.relation = b.oid
where upper(b.relname) = 'TABLE_NAME';
2、根据上面查出的pid进行查找锁对应的SQL语句:
select usename,current_query ,query_start,procpid,client_addr from pg_stat_activity where procpid = 12345;
3、解锁(暴力的方法):
SELECT pg_cancel_backend(pid of the postgres process);
解决这种情况最好是确定好原因,保证数据安全的情况下,将锁移除。