postgresql - Locking a newly created, uncommitted row in two concurrent READ COMMITTED database transactions -
if have 2 read committed postgresql database transactions both create new row same primary key , lock row, possible acquire both locks @ same time?
my instinct yes since these new rows both exist in individual transactions' scopes, curious if new rows , locking handled differently between transactions.
no.
primary keys implemented unique (currently only) b-tree index. happens when trying write index, per documentation:
if conflicting row has been inserted as-yet-uncommitted transaction, would-be inserter must wait see if transaction commits. if rolls there no conflict. if commits without deleting conflicting row again, there uniqueness violation. (in practice wait other transaction end , redo visibility check in toto.)
bold emphasis mine.
can try 2 open transactions (two different sessions) in parallel.
Comments
Post a Comment