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 1srjoy-0049CI-Rn for pgsql-general@arkaria.postgresql.org; Fri, 20 Sep 2024 20:01:41 +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 1srjow-00C8yp-UV for pgsql-general@arkaria.postgresql.org; Fri, 20 Sep 2024 20:01:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1srjow-00C8yf-GO for pgsql-general@lists.postgresql.org; Fri, 20 Sep 2024 20:01:39 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1srjot-000EtG-Ma for pgsql-general@lists.postgresql.org; Fri, 20 Sep 2024 20:01:39 +0000 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a7a81bd549eso292173166b.3 for ; Fri, 20 Sep 2024 13:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726862495; x=1727467295; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SZ/cAzUHvMoaDql42pnbdSv/zJt40k2vxSDtTUZce4w=; b=lShoatjzN2yuv6otqV2QV+WqzCJoxpwthl3XWKiuNNvCyvVP2OsyhQYiTkBaXFWxnR 2EGwb/33X3i9hN1Xjt430cqKBKvyA5qduM87pc4qsVl4yLWwyVPM6vT7ACyZ6Cc9Vaa1 XNRdgW9ajNdE/KeBtiqP6cP6WxyRnqiszzAHl+sgsJzE4o1AvBMY0EDfI1gj8P4lhxMv yPi1rGpyd/CFxULFrKOX2UoAJeW3AHMltBtvrbKosxPk1RVZA9xPffZ1ZhejhMq5JnvP GSvbE9+RUo4lH+LyOVFpmzdPBhbcN/sYcTcAn5mw80Y4pgbrEncYpSi9he3RWrolxjRJ 5LLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726862495; x=1727467295; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SZ/cAzUHvMoaDql42pnbdSv/zJt40k2vxSDtTUZce4w=; b=JKHRvjmVWcuYEzwIfMOIpu6pFb+8ef7z8ZUWxcmthAA6+E7BfPREARRhkQma7mQf9a ugnSFrQNGmfC5m9BCWSO/KkzgFNGXbzyT/cvr6oOo7q0pNLn/UVhpLQYU1KshwRz7vKb rUi2WDes5ZmTnpAltscqJhL0GRvucN2EevMxaA9YovG7xjzCXFHxw3PxdaKhMrK+hZXe ih+hcE8gknDwOPPbl0v4WobA6xHFjxBKYc2jzNRXjZ/FypJBy10IdMK59PJN+lVAdY6+ udr9NA/BreHL6ZzrGcuMZUKvGlqYnRzpFvJB0K+Suu0MZIYBrkF5xfIipt/NkRElfEuI l1Mg== X-Forwarded-Encrypted: i=1; AJvYcCUz2UIDCCHz+uz0PwmrL9AHRps5PrAl26PZy93OC9kzn3fnWaFHR83gXsq8tZxv+ZL07tEF/TkGFmTw5Buf@lists.postgresql.org X-Gm-Message-State: AOJu0YzNjxlnCNH1/HCAMIAOEDAxh+GB75AKZXWTbTI8x5SP24hhiyWG W+MGbxeJC2U8/Y30l3j8jVYghTssadPXGQkTQUoysqXknpWHVFNoZVbg2PsagWz23/MozFgisbl g4CN93U4xv6U7nwfxHnY2OnhLzTY= X-Google-Smtp-Source: AGHT+IG23kjp6oELUe3fQNzkLpyZnOiybfrvZ8PzojKWJ0bP+3Ts41Y0Y3/B7uXC7Heij3IpedK9q3YM3v2WmnzEVNE= X-Received: by 2002:a17:907:f79d:b0:a8a:8d81:97b1 with SMTP id a640c23a62f3a-a90d501abd3mr329287866b.27.1726862495110; Fri, 20 Sep 2024 13:01:35 -0700 (PDT) MIME-Version: 1.0 References: <3dddea5e-52ab-4075-970d-a87b0c921ae7@aklaver.com> <225d1bc1-5117-4c72-85a1-bac6355fb659@aklaver.com> <586d988d-978b-4b08-84b4-ef3ebb8736a8@aklaver.com> In-Reply-To: From: veem v Date: Sat, 21 Sep 2024 01:31:23 +0530 Message-ID: Subject: Re: IO related waits To: Adrian Klaver Cc: Greg Sabino Mullane , Christophe Pettus , pgsql-general Content-Type: multipart/alternative; boundary="00000000000098ddcb06229281f4" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000098ddcb06229281f4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 19 Sept, 2024, 8:40 pm Adrian Klaver, wrote: > On 9/19/24 05:24, Greg Sabino Mullane wrote: > > On Thu, Sep 19, 2024 at 5:17=E2=80=AFAM veem v > > This is really difficult to diagnose from afar with only snippets of > > logs and half-complete descriptions of your business logic. Pull > > everyone involved into a room with a whiteboard, and produce a document > > describing exactly what your application does, and how it is doing it. > > Switch from reactive to proactive. > > 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? Will setting the "lock_timeout" parameter at session level will help us anyway here? Create table t1(id numeric primary key); Session 1:- Begin Insert into table1 values(1) on conflict(id) do nothing; Session 2: Begin Insert into table1 values(2) on conflict(id) do nothing; session 1:- Insert into table1 values (2) on conflict(id) do nothing; It got hung as it waits for the session-2 to commit/rollback the transactio= n Session-2:- Insert into table1 values(1) on conflict(id) do nothing; deadlock detected... and this session terminated. Regards Veem --00000000000098ddcb06229281f4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Thu, 19 Sept, = 2024, 8:40 pm Adrian Klaver, <adrian.klaver@aklaver.co= m> wrote:
On 9/19/24 05:24, Greg Sabino Mullane wrote:
> On Thu, Sep 19, 2024 at 5:17=E2=80=AFAM veem v <veema0000@gmail.com

> This is really difficult to diagnose from afar with only snippets of <= br> > logs and half-complete descriptions of your business logic. Pull
> everyone involved into a room with a whiteboard, and produce a documen= t
> describing exactly what your application does, and how it is doing it.=
> Switch from reactive to proactive.


=
Able to reproduce this deadlock graph as below.=C2=A0 Now= my question is , this is a legitimate=C2=A0scenario in which the same ID c= an get inserted from multiple sessions and in such cases it's expected = to skip that (thus "On conflict Do=C2=A0nothing" is used) row. Bu= t as we see it's breaking the code with deadlock error during race=C2= =A0conditions where a lot of parallel threads are operating. So how should = we handle this scenario? Will setting the "lock_timeout" paramete= r at session level will help us anyway here?

Create table t1(id numeric primary k= ey);

Session 1:-
Begin
Insert into table1 values(1) on conflict(id) = do nothing;

Session 2:
Begi= n
Insert into table1 values(2) on conflict(id) do nothing;
<= div>
session 1:-
Insert into table1 values (2) on c= onflict(id) do nothing;

It got hung as it waits fo= r the session-2 to commit/rollback the transaction

Session-2:-
Insert into table1 values(1) on conflict(id) do noth= ing;

deadlock detected..= . and this session=C2=A0terminated.

Regards
Veem

=C2=A0 --00000000000098ddcb06229281f4--