不知道PID,刪除Postgresql lock鎖方法?通過事務ID刪除。


Remove pg_lock from postgres without any PID

查看DB鎖時發現鎖沒有pid,只有事務ID

這種情況通過kill pid的方法無法刪除鎖

-- 查詢pg_locks
postgres=# select * from pg_locks;

locktype      | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction |  pid  |       mode       | granted | fastpath
--------------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-------+------------------+---------+----------
relation      |    16390 |    19694 |      |       |            |               |         |       |          | -1/24019935        |       | RowExclusiveLock | t       | f
transactionid |          |          |      |       |            |      24019935 |         |       |          | -1/24019935        |       | ExclusiveLock    | t       | f

根據事務ID刪除鎖

-- 查詢事務的GID
SELECT gid FROM pg_prepared_xacts WHERE "transaction" = 165588128;
-- 回滾事務(鎖即可刪除)
ROLLBACK PREPARED '100_Z2xvYmFsVHJhbnNhY3Rpb25JZA==_M2M2YWExYjktZTRjYS00ZTZhLTg3ZjItYjlkNTMwZGM0MmU2';

這種鎖的產生原因可能是事務准備好后PID還沒產生、DB就重啟了,一般virtualtransaction開頭為-1的都是這種鎖

清除掉全部異常未完成的事務鎖

ROLLBACK PREPARED (SELECT gid FROM pg_prepared_xacts);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM