Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1srkX5-004D9V-Mk for pgsql-general@arkaria.postgresql.org; Fri, 20 Sep 2024 20:47:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1srkX3-00CVXi-JR for pgsql-general@arkaria.postgresql.org; Fri, 20 Sep 2024 20:47:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1srkX3-00CVXZ-7R for pgsql-general@lists.postgresql.org; Fri, 20 Sep 2024 20:47:14 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1srkX2-000ESh-3T for pgsql-general@lists.postgresql.org; Fri, 20 Sep 2024 20:47: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 48KKl89U2587193; Fri, 20 Sep 2024 16:47:08 -0400 From: Tom Lane To: veem v cc: Adrian Klaver , Greg Sabino Mullane , Christophe Pettus , pgsql-general Subject: Re: IO related waits In-reply-to: References: <3dddea5e-52ab-4075-970d-a87b0c921ae7@aklaver.com> <225d1bc1-5117-4c72-85a1-bac6355fb659@aklaver.com> <586d988d-978b-4b08-84b4-ef3ebb8736a8@aklaver.com> Comments: In-reply-to veem v message dated "Sat, 21 Sep 2024 01:31:23 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2587191.1726865228.1@sss.pgh.pa.us> Date: Fri, 20 Sep 2024 16:47:08 -0400 Message-ID: <2587192.1726865228@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk veem v writes: > Able to reproduce this deadlock graph as below. Now my question is , this > is a legitimate scenario in which the same ID can get inserted from > multiple sessions and in such cases it's expected to skip that (thus "On > conflict Do nothing" is used) row. But as we see it's breaking the code > with deadlock error during race conditions where a lot of parallel threads > are operating. So how should we handle this scenario? Do you have to batch multiple insertions into a single transaction? If so, can you arrange to order them consistently across transactions (eg, sort by primary key before inserting)? regards, tom lane