【发布时间】:2020-03-03 00:53:18
【问题描述】:
运行 postgresql 11.2
我有 3 个表,表 1、表 2 和表 3。
Table2 和 Table3 链接到 Table1。
因此,两者都有一个外键和一个字段:
"fk38dc51d86836z0e5" FOREIGN KEY (table1_id) REFERENCES table1(id)
我最近在这两个表上遇到了死锁,尽管所涉及的查询没有使用外键字段。
Process 19819 waits for ShareLock on transaction 254244062; blocked by process 19930.
Process 19930 waits for ShareLock on transaction 254244063; blocked by process 19819.
Process 19819: update Table1 set lastUpdated=$1, user_id=$2 where id=$3
Process 19930: update Table2 set lastUpdated=$1, version=$2, content=$3, extra=$4 where id=$5 and version=$6
这两个表之间的唯一链接是它们与 Table1 的链接。它们之间没有直接联系。
但是这两个查询都没有使用 Table1 的外键作为查询的一部分。
这里发生了什么?为什么会出现僵局?
【问题讨论】:
-
冲突锁可能已被同一事务中较早的其他语句占用。
标签: database postgresql database-deadlocks