我遇到死锁错误,现在想了解这种情况。
假设我有一个带有主键ID的表。 我有另一个表b,其列为parent_a_id,child_a_id。 外键约束是:
"b_parent_id_fkey" FOREIGN KEY (parent_a_id) REFERENCES a(id) ON DELETE CASCADE
"b_child_id_fkey" FOREIGN KEY (child_a_id) REFERENCES a(id) ON DELETE CASCADE
当我运行以下两个查询时,将出现死锁情况
update a set some_field = 0 where id = $1
delete from a where id = $1
这是postgres日志:
ERROR: deadlock detected
DETAIL: Process 28165 waits for ShareLock on transaction 112624590; blocked by process 20900.
Process 20900 waits for ShareLock on transaction 112624583; blocked by process 28165.
Process 28165: update a set some_field = 0 where id = $1
Process 20900: delete from a where id = $1