問題場景:
今天程序在執行某條刪除語句時出現了阻塞情況,但對其他表操作一切正常,由此懷疑改表被鎖導致。
報錯原因:
事務未正常提交。
解決方法:
--查詢是否鎖表了
select oid from pg_class where relname='table_name' -- table_name 替換為可能被鎖的表
select pid from pg_locks where relation='oid' -- oid 替換為上面查出的oid
--如果查詢到了結果,表示該表被鎖 則需要釋放鎖定
select pg_cancel_backend(pid) -- pid替換為上面查到的pid
--如果無法取消,則強行干掉死掉的進程
select pg_terminate_backend(pid) -- pid替換為上面查到的pid
轉載於:https://blog.csdn.net/weixin_44720938/article/details/103000888