Deadlock involving foreign key constraint
问题 I would like to understand better a mechanism of locking in postgres. Let's say that tree can have apples (via foreign key on apple table). It seems that when selecting a tree for update lock is obtained on an apple. However, the operation is not blocked even if someone else already holds a lock on this apple. Why is it so? p.s. Please don't suggest to remove "select for update". Scenario Transaction 1 Transaction 2 BEGIN . update apple; . . BEGIN . select tree for update; . update apple; . -