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 1srGoe-000Dei-U6 for pgsql-general@arkaria.postgresql.org; Thu, 19 Sep 2024 13:03:25 +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 1srGoc-000lCr-US for pgsql-general@arkaria.postgresql.org; Thu, 19 Sep 2024 13:03:24 +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 1srGoc-000lCj-JF for pgsql-general@lists.postgresql.org; Thu, 19 Sep 2024 13:03:23 +0000 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1srGoW-0001Fv-6K for pgsql-general@lists.postgresql.org; Thu, 19 Sep 2024 13:03:23 +0000 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2f74e613a10so11560841fa.1 for ; Thu, 19 Sep 2024 06:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726750997; x=1727355797; 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=Y3hZtKgRUzyxGePj0SSY6g93dRnA9e3kMxLqMDm4B78=; b=FGjwgvOwbJZXdzPH7+yiOKFVOrpSxWhMDosyVFGzyqBIxUgZlVfjCcCAt0yNQAAzGL 6hl+VXPEFz6RY6feOVBtAUTYJ/F4PjmbinY00ejMfxTcKYyanHj4cBZn8arstX079gWD Nzij2fBcpJ9e3+bH68rBrbdM6Theftr3pfzCcIGiCtF1T5aQxiuckBmiXXaxG0+j1VAA 7hruP+zGSkGWhOaABIpuif9WRY9+S7gKvALreyskHsJ0w1W5L/0f32S+2ChvA3Nng7CN 9oVmGOJlqbIpq/fCsKI4w4pgK0iHyLAWVqnfD5HjSTS1U7oz0bYhwnEiIjHxoTe9X9ij WjXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726750997; x=1727355797; 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=Y3hZtKgRUzyxGePj0SSY6g93dRnA9e3kMxLqMDm4B78=; b=uZJf97nlLvZNHFGMhDlUtFTdP0IOEP9I0G9v+z4cEFqTRHuF1gMFK92pxfvpOmAkA5 5H8CHyB7MNYAyILJSDo3gomy7CRcaOa6tsvFiNjIw6MlTyiws1DNIEAxTlRAsGHvafTX pW2lrenuhmkAZdjz6e8TCIftDD9Wvely+A50PcU15oEktynbspdnCV3TRhmlrtZxDfn5 XuqZW7YDyv3hQ/YBeRiXhSJZC/kg3GEJZtAGzQNv0GMKXcUAXSV8aL3DucKv83lXZmeN aoE+GqvO82vY/8QmoW3o3P1EFYUcUnQlkY8ryMbdUfOWLZVyZCQgghpAAf4+mh5sJS0B ywRA== X-Forwarded-Encrypted: i=1; AJvYcCXLSJQASagNbVrYoo7DlgE/TuKshVwRd5FneEJl57O4AGyD562GHyzR+ZfFos3gjpiShPIWr5+IEHgTx9jn@lists.postgresql.org X-Gm-Message-State: AOJu0Yw1/931Jb+oT+KZoJOO5btamRpiGby7Ztaa3k/XiQoNp9h82H+E 2umHi2r/nBNrFoZHWtfCeAWdUprpNLBgZyyhoLS7sa6QIoaIygjST9wNsO8z6wcofgRdhfnLf/u +3iyezuTCtysZAgI3JQEfO1+YmLABBg== X-Google-Smtp-Source: AGHT+IG/x9Sb2aQaUkK3nS93Di+kjc/pXml3nW8U5kVN7LHXUEDmseKlcopnbXTq/d1V6Vzwi+wWxUf/DfDHDXySdvM= X-Received: by 2002:a05:6512:b29:b0:52c:d628:c77c with SMTP id 2adb3069b0e04-5367ff24bdcmr15956642e87.43.1726750995977; Thu, 19 Sep 2024 06:03:15 -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: Thu, 19 Sep 2024 18:33:04 +0530 Message-ID: Subject: Re: IO related waits To: Greg Sabino Mullane Cc: Adrian Klaver , Christophe Pettus , pgsql-general Content-Type: multipart/alternative; boundary="000000000000bb2b490622788bbc" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000bb2b490622788bbc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 19 Sept 2024 at 17:54, Greg Sabino Mullane wrote: > On Thu, Sep 19, 2024 at 5:17=E2=80=AFAM veem v wrot= e: > >> 2024-09-18 17:05:56 UTC:100.72.10.66(54582):USER1@TRANDB:[14537]:DETAIL: >> Process 14537 waits for ShareLock on transaction 220975629; blocked by >> process 14548. >> > > You need to find out exactly what commands, and in what order, all these > processes are doing. Deadlocks can be avoided by rearranging your > application logic. > > >> 2024-09-18 17:05:56 UTC:100.72.22.33(54582):USER1@TRANDB:[14537]:ERROR: >> current transaction is aborted, commands ignored until end of transacti= on >> block >> 2024-09-18 17:05:56 UTC:100.72.22.33(54582):USER1@TRANDB:[14537]:STATEME= NT: >> INSERT INTO TRANDB.EXCEP_TAB (...) >> 2024-09-18 17:05:56 UTC:100.72.22.33(54582):USER1@TRANDB:[14537]:ERROR: >> current transaction is aborted, commands ignored until end of transacti= on >> block >> 2024-09-18 17:05:56 UTC:100.72.22.33(54582):USER1@TRANDB:[14537]:STATEME= NT: >> >> 2024-09-18 17:05:56 UTC:100.72.22.33(36096):USER1@TRANDB:[14551]:ERROR: >> current transaction is aborted, commands ignored until end of transacti= on >> block >> > > Fix your application. It should be checking that each command completed > and not just blindly pushing on to the next statement while ignoring the > error. > > 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. > > > Thank you Greg. I was thinking there might be some oddity or difference in the behaviour here in postgres as compared to others, because I have seen deadlock due to UPDATES but never seen deadlocks with INSERT queries before in other databases (though here we have "insert on conflict do nothing"). But I am now thinking , here we have foreign keys and primary keys exist and if the same PK gets inserted from multiple sessions then one will wait if the other has not been committed and that might be creating a situation of locking first and subsequently deadlock. But also we are doing batch inserts from multiple sessions but each session will first insert into the parent and then into the child table for those related to PK and FK and it should not overlap across sessions. So I will check if there is a loophole there. Also another thing which we encountered here , if the session gets errors out with any error(may be deadlock etc) , it's not executing any further transactions and erroring out with "*current transaction aborted, command ignored until end of transaction block*". And it seems it will need explicit "rollback" and will not be the default rollback, which I was expecting it to do. Regards Veem --000000000000bb2b490622788bbc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, 19 Sept 2024 at 17:54, Greg S= abino Mullane <htamfids@gmail.com<= /a>> wrote:
<= div dir=3D"ltr">
2024-09-18 17:05:56 UTC:100.72.10.66(54582):USER1@TRANDB:[14537]:DET= AIL: =C2=A0Process 14537 waits for ShareLock on transaction 220975629; bloc= ked by process 14548.
You need to find out exactly what commands, and in what order, = all these processes are doing. Deadlocks can be avoided by rearranging your= application logic.
=C2=A0
2024-= 09-18 17:05:56 UTC:100.72.22.33(54582):USER1@TRANDB:[14537]:ERROR: =C2=A0cu= rrent transaction is aborted, commands ignored until end of transaction blo= ck
2024-09-18 17:05:56 UTC:100.72.22.33(54582):USER1@TRANDB:[14537]:STAT= EMENT: =C2=A0INSERT INTO TRANDB.EXCEP_TAB (...)
2024-09-18 17:05:56 UTC:= 100.72.22.33(54582):USER1@TRANDB:[14537]:ERROR: =C2=A0current transaction i= s aborted, commands ignored until end of transaction block
2024-09-18 17= :05:56 UTC:100.72.22.33(54582):USER1@TRANDB:[14537]:STATEMENT: =C2=A0
20= 24-09-18 17:05:56 UTC:100.72.22.33(36096):USER1@TRANDB:[14551]:ERROR: =C2= =A0current transaction is aborted, commands ignored until end of transactio= n block

Fix your appl= ication. It should be checking that each command completed and not just bli= ndly pushing on to the next statement while=C2=A0ignoring the error.
<= div>
This is really difficult to diagnose from afar with only= snippets of logs and half-complete descriptions of your business logic. Pu= ll everyone involved into a room with a whiteboard, and produce a document = describing exactly what your application does, and how it is doing it. Swit= ch from reactive to proactive.



Thank you Greg.

I was thinking there might be some oddity or difference in the behaviour = here in postgres as compared to others, because I have seen deadlock due to= UPDATES but never seen deadlocks with INSERT queries before in other datab= ases (though here we have "insert on conflict do nothing"). But I= am now thinking , here we have foreign keys and primary keys exist and if = the same PK gets inserted from multiple sessions then one will wait if the = other has not been committed and that might be creating a situation of lock= ing first and subsequently deadlock.=C2=A0

But als= o we are doing batch inserts from multiple sessions but each session will f= irst insert into the parent and then into the child table for those related= to PK and FK and it should not overlap across sessions. So I will check if= there is a loophole there.

Also another thing whi= ch we encountered here , if the session gets errors out with any error(may = be deadlock etc) , it's not executing any further transactions and erro= ring out with "current transaction aborted, command ignored until e= nd of transaction block". And it seems it will need explicit "= ;rollback" and will not be the default rollback, which I was expecting= it to do.

Regards
Veem
--000000000000bb2b490622788bbc--