]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix concurrent locking of tuple update chain
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 26 Jul 2017 21:24:16 +0000 (17:24 -0400)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 26 Jul 2017 21:24:16 +0000 (17:24 -0400)
commit0d4604ad6cfeca55538804c454efcec7a40abab6
tree9e5125979f6e981eff79838f8c23d265dc44cd74
parent5146ca3525a8449b75513e1488ee02b67529abc7
Fix concurrent locking of tuple update chain

If several sessions are concurrently locking a tuple update chain with
nonconflicting lock modes using an old snapshot, and they all succeed,
it may happen that some of them fail because of restarting the loop (due
to a concurrent Xmax change) and getting an error in the subsequent pass
while trying to obtain a tuple lock that they already have in some tuple
version.

This can only happen with very high concurrency (where a row is being
both updated and FK-checked by multiple transactions concurrently), but
it's been observed in the field and can have unpleasant consequences
such as an FK check failing to see a tuple that definitely exists:
    ERROR:  insert or update on table "child_table" violates foreign key constraint "fk_constraint_name"
    DETAIL:  Key (keyid)=(123456) is not present in table "parent_table".
(where the key is observably present in the table).

Discussion: https://postgr.es/m/20170714210011.r25mrff4nxjhmf3g@alvherre.pgsql
src/backend/access/heap/heapam.c