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 1kziz3-0006L8-1u for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Jan 2021 16:26:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kziz1-0005nE-FP for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Jan 2021 16:26:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kziz1-0005n7-9Z for pgsql-bugs@lists.postgresql.org; Wed, 13 Jan 2021 16:26:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kziyw-00041c-8q for pgsql-bugs@lists.postgresql.org; Wed, 13 Jan 2021 16:26:54 +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 10DGQd1K1283729; Wed, 13 Jan 2021 11:26:40 -0500 From: Tom Lane To: abcxiaod@126.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16820: PG will have a deadlock when multiple rows are updated concurrently In-reply-to: <16820-2f08e0bd1687ee34@postgresql.org> References: <16820-2f08e0bd1687ee34@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 13 Jan 2021 07:43:43 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1283727.1610555199.1@sss.pgh.pa.us> Date: Wed, 13 Jan 2021 11:26:39 -0500 Message-ID: <1283728.1610555199@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > (1) As long as the data of a single update exceeds 1 row, a deadlock will > occur: > update zxin_cardcapacity set usecapacity = usecapacity - 2 where a >2; I see no particular bug here. If you want to have multiple transactions updating the same rows concurrently, it's up to you to ensure that each transaction touches the rows in the same order, otherwise of course there will be a deadlock. regards, tom lane