Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pfNEd-0003Yc-UU for pgsql-bugs@arkaria.postgresql.org; Thu, 23 Mar 2023 15:52:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pfNEc-0007Dy-Ib for pgsql-bugs@arkaria.postgresql.org; Thu, 23 Mar 2023 15:52:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pfNEc-0007Dp-AC for pgsql-bugs@lists.postgresql.org; Thu, 23 Mar 2023 15:52:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pfNEV-00052q-Nm for pgsql-bugs@lists.postgresql.org; Thu, 23 Mar 2023 15:52:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 32NFq5bg1827661; Thu, 23 Mar 2023 11:52:06 -0400 From: Tom Lane To: "=?gb18030?B?MTAyNA==?=" <453539222@qq.com> cc: "=?gb18030?B?cGdzcWwtYnVncw==?=" Subject: Re: An update deadlock bug In-reply-to: References: Comments: In-reply-to "=?gb18030?B?MTAyNA==?=" <453539222@qq.com> message dated "Thu, 23 Mar 2023 16:32:04 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1827659.1679586725.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 23 Mar 2023 11:52:05 -0400 Message-ID: <1827660.1679586725@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "=3D?gb18030?B?MTAyNA=3D=3D?=3D" <453539222@qq.com> writes: > Recently I found a parallel update bug=C2=A3=C2=ACThe steps to recurrenc= e 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 =3D 123 where b =3D '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 deadloc= k 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