francs=> begin; BEGIN francs=> select * from test_1 where id=2; id | name ----+------ 2 | a (1 row) francs=> update test_1 setname='aaa' where id=2; UPDATE 1
2.2 session B
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
francs=> begin; BEGIN francs=> select * from test_1 where id=2; id | name ----+------ 2 | a (1 row) francs=> select * from test_1 where id=3; id | name ----+------ 3 | a (1 row) francs=> update test_1 setname='aaa3' where id=3; UPDATE 1 francs=> update test_1 setname='aaaa' where id=2; < hang >
2.3 再次回到 session A
1 2 3 4 5
francs=> update test_1 setname='aaa3333' where id=3; ERROR: deadlock detected DETAIL: Process 25454 waits for ShareLock on transaction 1995; blocked by process 25508. Process 25508 waits for ShareLock on transaction 1994; blocked by process 25454. HINT: See server log for query details.