PostgreSQL數據庫操做查找緣由以及解決建議

一、查看錶是否有鎖: sql

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';



二、根據上面查出的pid進行查找鎖對應的SQL語句:

select usename,current_query ,query_start,procpid,client_addr from pg_stat_activity where procpid = 12345;



三、解鎖(暴力的方法):

SELECT pg_cancel_backend(pid of the postgres process);
解決這種狀況最好是肯定好緣由,保證數據安全的狀況下,將鎖移除。
相關文章
相關標籤/搜索