pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
An update deadlock bug
2+ messages / 2 participants
[nested] [flat]

* An update deadlock bug
@ 2023-03-23 08:32  1024 <453539222@qq.com>
  0 siblings, 1 reply; 2+ messages in thread

From: 1024 @ 2023-03-23 08:32 UTC (permalink / raw)
  To: pgsql-bugs <pgsql-bugs@lists.postgresql.org>

Hello everyone:


Recently I found a parallel update bug,The steps to recurrence&nbsp;are as follows:
1,create table t1(a int, b varchar(20));
&nbsp; &nbsp;insert into t1 values(generate_series(1,5), 'abc');
2, use pgbench to run parallel update:
&nbsp; &nbsp; pgbench -U postgres -p 5432 postgres -n -r -c 10 -j 1 -T 100 -P 1 -f test.sql


&nbsp; &nbsp; test.sql:&nbsp; update t1 set a = 123 where b = 'abc';
3, We will find "deadlock detected" in log file or terminal.


I want to figure out that if every update use sequence scan ,why deadlock happened?


I look forward to receiving your reply.


Thank you very much!

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: An update deadlock bug
@ 2023-03-23 15:52  Tom Lane <tgl@sss.pgh.pa.us>
  parent: 1024 <453539222@qq.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2023-03-23 15:52 UTC (permalink / raw)
  To: 1024 <453539222@qq.com>; +Cc: pgsql-bugs <pgsql-bugs@lists.postgresql.org>

"=?gb18030?B?MTAyNA==?=" <453539222@qq.com> writes:
> Recently I found a parallel update bug£¬The steps to recurrence are as follows:
> 1,create table t1(a int, b varchar(20));
>    insert into t1 values(generate_series(1,5), 'abc');
> 2, use pgbench to run parallel update:
>     pgbench -U postgres -p 5432 postgres -n -r -c 10 -j 1 -T 100 -P 1 -f test.sql
>     test.sql:  update t1 set a = 123 where b = 'abc';
> 3, We will find "deadlock detected" in log file or terminal.

I don't see any bug here.  You've got multiple clients all trying
to update the same set of rows in an unspecified order.  It's
unsurprising that some of them sometimes arrive at the same pair of
rows in a different order.

> I want to figure out that if every update use sequence scan ,why deadlock happened?

Even though they're all using seqscans, there will be different
updates committing at different instants, and the live rows and
available free space will soon become wildly scrambled.  If you
are expecting that "all the plans are seqscans" means "all the
sessions will operate in lockstep", you're mistaken.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-03-23 15:52 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23 08:32 An update deadlock bug 1024 <453539222@qq.com>
2023-03-23 15:52 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox