Re: BUG #13723: "duplicate key" error occurs when update delete and insert the same row concurrently

From: chenhj <chjischj(at)163(dot)com>
To: "Jeff Janes" <jeff(dot)janes(at)gmail(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #13723: "duplicate key" error occurs when update delete and insert the same row concurrently
Date: 2015-10-26 17:47:42
Message-ID: 796c1a02.44e.150a5434cf6.Coremail.chjischj@163.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

>Can you reproduce the problem under a higher transaction isolation level?
>
>Cheers,
>
>Jeff

Under higher transaction isolation level(REPEATABLE READ or SERIALIZABLE),
only one transaction's UPDATE could be executed, the second transaction's UPDATE will be blocked util the first transaction committed and then throw "could not serialize access due to concurrent update" error.

[postgres(at)localhost ~]$ cat test5.sql
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
update tb1 set c=2 where id=1
delete from tb1 where id=1;
insert into tb1 values(1,2);
commit;
[postgres(at)localhost ~]$ pgbench -n -c 2 -j 2 -t 2 -f test5.sql
client 0 aborted in state 1: ERROR: could not serialize access due to concurrent update
...
---------------------------
2015-10-25 22:55:25.717 EDT 2203 0 LOG: connection received: host=[local]
2015-10-25 22:55:25.718 EDT 2203 0 LOG: connection authorized: user=postgres database=postgres
2015-10-25 22:55:25.722 EDT 2205 0 LOG: connection received: host=[local]
2015-10-25 22:55:25.723 EDT 2206 0 LOG: connection received: host=[local]
2015-10-25 22:55:25.723 EDT 2205 0 LOG: connection authorized: user=postgres database=postgres
2015-10-25 22:55:25.724 EDT 2206 0 LOG: connection authorized: user=postgres database=postgres
2015-10-25 22:55:25.726 EDT 2205 0 LOG: statement: BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
2015-10-25 22:55:25.726 EDT 2206 0 LOG: statement: BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
2015-10-25 22:55:25.726 EDT 2206 0 LOG: statement: update tb1 set c=2 where id=1
2015-10-25 22:55:25.727 EDT 2205 0 LOG: statement: update tb1 set c=2 where id=1
2015-10-25 22:55:25.728 EDT 2206 79520 LOG: statement: delete from tb1 where id=1;
2015-10-25 22:55:25.728 EDT 2206 79520 LOG: statement: insert into tb1 values(1,2);
2015-10-25 22:55:25.728 EDT 2206 79520 LOG: statement: commit;
2015-10-25 22:55:25.729 EDT 2206 0 LOG: statement: BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
2015-10-25 22:55:25.729 EDT 2205 79521 ERROR: could not serialize access due to concurrent update
2015-10-25 22:55:25.729 EDT 2205 79521 STATEMENT: update tb1 set c=2 where id=1
2015-10-25 22:55:25.730 EDT 2206 0 LOG: statement: update tb1 set c=2 where id=1
2015-10-25 22:55:25.730 EDT 2206 79522 LOG: statement: delete from tb1 where id=1;
2015-10-25 22:55:25.730 EDT 2206 79522 LOG: statement: insert into tb1 values(1,2);
2015-10-25 22:55:25.730 EDT 2206 79522 LOG: statement: commit;

Best Regards,
Chen Huajun

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message colin.knox 2015-10-26 18:58:40 BUG #13735: pg_get_serial_sequence can be incorrect
Previous Message Jeff Janes 2015-10-26 16:20:05 Re: BUG #13723: "duplicate key" error occurs when update delete and insert the same row concurrently