从没有任何 PID 的 postgres 9.6.6 中删除 pg_lock
Remove pg_lock from postgres 9.6.6 without any PID
我们有一个任务卡住了,所以我使用 SELECT pg_cancel_backend(<pid of the process>)
终止了该任务。然而,任务持有的锁并没有消失,现在我的 table 之一被锁定了。
我正在尝试 运行 table 上的 COPY
命令,但它卡在了 wait_event_type = Lock
。
正在使用的系统:
Server: AWS RDS db.m4.xlarge
DB: PostgreSQL 9.6.6
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
select * from pg_prepared_xacts where transaction=24019935;
transaction | gid | prepared | owner | database
------------+------------------------------+------------------------------+----------+----------
24019935 | PGDIRTY:dirty_state::9994733 | 2018-06-27 13:40:12.88981-08 | postgres | pg
我已经尝试执行 中建议的步骤,但它没有显示任何 pgid。
我也尝试过重新启动我的数据库,但锁定仍然存在。
谁能帮我弄清楚如何摆脱这个锁?
谢谢
以防万一,任何其他可怜的家伙都陷入类似的境地。这就是最终对我有用的东西。
PS:我不知道为什么锁没有像问题评论中提到的那样随着重启而消失。
ROLLBACK PREPARED (SELECT gid FROM pg_prepared_xacts);
解释:出于某种原因,即使在 PID 终止并重新启动 RDS 服务器后,准备好的事务也从未正确回滚(也许 RDS 做了一些有趣的重新启动而不是完全重新启动数据库?)。在我手动回滚准备好的事务后,事务终于被移除,并释放了锁。
Thomas C. G. de Vilhena in Postgresql DROP TABLE doesn't work的建议帮我解决了。
我们有一个任务卡住了,所以我使用 SELECT pg_cancel_backend(<pid of the process>)
终止了该任务。然而,任务持有的锁并没有消失,现在我的 table 之一被锁定了。
我正在尝试 运行 table 上的 COPY
命令,但它卡在了 wait_event_type = Lock
。
正在使用的系统:
Server: AWS RDS db.m4.xlarge
DB: PostgreSQL 9.6.6
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
select * from pg_prepared_xacts where transaction=24019935;
transaction | gid | prepared | owner | database
------------+------------------------------+------------------------------+----------+----------
24019935 | PGDIRTY:dirty_state::9994733 | 2018-06-27 13:40:12.88981-08 | postgres | pg
我已经尝试执行
我也尝试过重新启动我的数据库,但锁定仍然存在。
谁能帮我弄清楚如何摆脱这个锁?
谢谢
以防万一,任何其他可怜的家伙都陷入类似的境地。这就是最终对我有用的东西。
PS:我不知道为什么锁没有像问题评论中提到的那样随着重启而消失。
ROLLBACK PREPARED (SELECT gid FROM pg_prepared_xacts);
解释:出于某种原因,即使在 PID 终止并重新启动 RDS 服务器后,准备好的事务也从未正确回滚(也许 RDS 做了一些有趣的重新启动而不是完全重新启动数据库?)。在我手动回滚准备好的事务后,事务终于被移除,并释放了锁。
Thomas C. G. de Vilhena in Postgresql DROP TABLE doesn't work的建议帮我解决了。