Updating child row locks parent row in PostgreSQL (foreign key, 9.1) -
i have problem transaction isolation, let's considering 2 transactions:
first transaction 1 update in row on table 1, , then, transaction 2 update in row child table references pk table 1 updated in transaction 1, analysing transactions can see lock, transaction 2 locked until transaction 1 committed or rollebacked, there way avoid lock? transaction 1 not affect table 2, because update in specific column. p.s. postgresql version 9.1, have checked postgressql 9.6 , not happen, there workaround?
you've identified how fix it: upgrade. postgresql 9.6 has feature, for key share
locks, used foreign keys avoid locking whole row when child row being inserted/updated. feature not in 9.1.
alternately, can drop
foreign key
constraint , rely on application maintain consistency. postgresql no longer take for share
row lock on parent row when child row inserted/updated, since there's no longer formal foreign key relationship.
Comments
Post a Comment