I have problem with transactions in my app.
My first transaction:
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SELECT * FROM public.owner WHERE id = 15;
UPDATE public.owner SET current_cat = 2 WHERE id = 15;
COMMIT;
My second transaction:
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SELECT * FROM public.owner WHERE id = 16;
UPDATE public.owner SET current_cat = 4 WHERE id = 16;
COMMIT;
Rough example of my tables:
CREATE TABLE assortment.cat (
id int not null,
name varchar not null
);
CREATE TABLE assortment.owner (
id int not null,
fio varchar not null,
current_cat int not null
);
Owners can swap cats :) So, if begin two transactions step by step cancurrently (begin of first transaction -> begin of second transaction -> select of first transaction -> select of second transaction etc.) then first transaction ending is successful but second transaction will fail:
could not serialize access due to read/write dependencies among transactions. Reason code: Canceled on identification as a pivot, during commit attempt
Two transactions have changed different lines, why does blocking hapend? I expect both transactions to complete successfully.
I will be glag of any help! :)
P.S. I'm using PostgreSQL