不知道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);