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 1msYSP-00012v-I3 for pgsql-general@arkaria.postgresql.org; Wed, 01 Dec 2021 22:52:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1msYSO-0001eF-ED for pgsql-general@arkaria.postgresql.org; Wed, 01 Dec 2021 22:52:08 +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 1msYSO-0001e5-2a for pgsql-general@lists.postgresql.org; Wed, 01 Dec 2021 22:52:08 +0000 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1msYSL-0003TS-Dj for pgsql-general@lists.postgresql.org; Wed, 01 Dec 2021 22:52:07 +0000 Received: by mail-io1-xd2d.google.com with SMTP id v23so33011958iom.12 for ; Wed, 01 Dec 2021 14:52:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=fdYKee0F8qI9VOyMgePIi8GZtIExK2Fnwqp6qBLIWT8=; b=j9ss8ik2D1fu3FvrzcjhOWgv7mpoVra38C/h4iPlyWIysyZw4s8E8Ky9yjw2JXc6AB vGw9YfbXwGnBfnonRJNpGkijBjKcKKwVTIgiOk8L2DYhjWclfE16PsaIGTR6VrrkbNRV PVDUfqcfVwQ7tef+KY9BguHbyPfMfx6CHgmqUk/x8S4zgS109g8jOx0qqlB7Vo6PsOcd XmOjI/NVkSIMuMDSuBkLTDp0cNfD/Mn42WjkzXjD8jZW0A3hqfQM7TCV3qOAmnXHv+u/ LNCTdUkwi9KOe4tnN/+KmHG3iSw5fT1pLXru1YINlU/3OlwHARg258onhEhywuV4WYpj yyNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=fdYKee0F8qI9VOyMgePIi8GZtIExK2Fnwqp6qBLIWT8=; b=GoPrlk4SRzcRScchcJa66iwq1UYtFHS1miB+GH0ASi9K8PcenOMRC7JpVdtY1c3YeI Kmw+j0MrQtk/rVVClduekVrBrwE7HZAQE7OtHS1QoNcHdzJF+tCumhLt6c0YeSP4JGbb v7zTV4W2vFQwFoRbe5PAE+NqkmsVyVlEdyx1WVOX8Iwh3OMb7VCnWkESTlj081UZDyfi PC6r8PtXjPTss7cGLkkNV0GmDJCzKGSRFiOCWxR5Z43MIWAT+dcXoSRiNvPe73//lkVP 6tgQwrKAu+mltsvfd7Nmb1Zvbn94m14jfqabGrxqGZytVYMeqCIqLIrzJKOsRqVFDbWZ eXkw== X-Gm-Message-State: AOAM532vSOoIp4W2thYFM2aUd9unhpPcUb1VNQd/yizen6h1+ZBRuSdo IslIIL+r/IGmIGKDCniLn/sv6zd2i1g= X-Google-Smtp-Source: ABdhPJz1sMGpEIEImh4JFQPP0L8BuZtPX+HKm8sNErHkYlhVc2at73iRqaIU5mEjKr2xDvQQQxy8zg== X-Received: by 2002:a05:6638:2656:: with SMTP id n22mr14860880jat.35.1638399122660; Wed, 01 Dec 2021 14:52:02 -0800 (PST) Received: from [10.0.0.94] (c-73-63-59-118.hsd1.ut.comcast.net. [73.63.59.118]) by smtp.gmail.com with ESMTPSA id s3sm704866ilv.69.2021.12.01.14.52.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Dec 2021 14:52:02 -0800 (PST) Subject: Re: Max connections reached without max connections reached To: pgsql-general@lists.postgresql.org References: <4176160.1637681607@sss.pgh.pa.us> <67613.1637709271@sss.pgh.pa.us> <81460.1637720668@sss.pgh.pa.us> From: Rob Sargent Message-ID: <0fba028d-68da-349c-0996-e83f707824b7@gmail.com> Date: Wed, 1 Dec 2021 15:52:01 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------FB9521910F66F516FE311E1E" Content-Language: en-CA List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------FB9521910F66F516FE311E1E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 12/1/21 3:29 PM, James Sewell wrote: > > Looking again into the back trace[1], it appeared that the backend is > getting stuck while getting the subtransaction's parent information, > and that can only happen if the snapshot is getting marked as > overflowed.  So it seems that some of the scripts are using a lot of > sub-transaction (> 64) within a transaction and in such case, we can > not cache the sub-transaction information and the snapshot will be > marked overflowed.  After that, for checking the visibility of any > tuple we need to consult the SLRU to get TopMost transaction > information and if the subtransaction SLRU cache is full then it will > have to do the I/O.  So in this case it appeared that a lot of > parallel scans/new connections are trying to read the pg_subtrans and > due to limited cache size that is not even able to load the data in > the cache and getting frequently blocked.  So I assume that when you > say the startup is getting stuck forever, how long did you wait, maybe > it is moving but getting stuck again for the next tuple, so to confirm > that attach the process with gdb put breakpoint in XidInMVCCSnapshot() > and check whether it is hitting that breakpoint again or not.  Also, > check whether you are seeing "SubtransControlLock" in > pg_stat_activity.  There is one nice blog[2] explaining this issue so > you can refer to that as well. > > > Ah. Snap. This makes a lot of sense. The developers have a nasty habit > of using LOOP over rows which has never been stamped out. I bet they > have applied this to something with a lot of rows. > > Is there a way of seeing which statements / backends / processes have > greater than 64 stxns? I'd like to monitor this. > > - James > > ------------------------------------------------------------------------ > The contents of this email are confidential and may be subject to > legal or professional privilege and copyright. No representation is > made that this email is free of viruses or other defects. If you have > received this communication in error, you may not copy or distribute > any part of it or otherwise disclose its contents to anyone. Please > advise the sender of your incorrect receipt of this correspondence. Also be on the look-out for begin trans; begin trans; etc  I read Kumar's report as nested transactions.  If your gang is doing a transaction per row, they need a kick in the rear.  Anyone not closing those needs a pink slip. --------------FB9521910F66F516FE311E1E Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 12/1/21 3:29 PM, James Sewell wrote:

Looking again into the back trace[1], it appeared that the backend is
getting stuck while getting the subtransaction's parent information,
and that can only happen if the snapshot is getting marked as
overflowed.  So it seems that some of the scripts are using a lot of
sub-transaction (> 64) within a transaction and in such case, we can
not cache the sub-transaction information and the snapshot will be
marked overflowed.  After that, for checking the visibility of any
tuple we need to consult the SLRU to get TopMost transaction
information and if the subtransaction SLRU cache is full then it will
have to do the I/O.  So in this case it appeared that a lot of
parallel scans/new connections are trying to read the pg_subtrans and
due to limited cache size that is not even able to load the data in
the cache and getting frequently blocked.  So I assume that when you
say the startup is getting stuck forever, how long did you wait, maybe
it is moving but getting stuck again for the next tuple, so to confirm
that attach the process with gdb put breakpoint in XidInMVCCSnapshot()
and check whether it is hitting that breakpoint again or not.  Also,
check whether you are seeing "SubtransControlLock" in
pg_stat_activity.  There is one nice blog[2] explaining this issue so
you can refer to that as well.

Ah. Snap. This makes a lot of sense. The developers have a nasty habit of using LOOP over rows which has never been stamped out. I bet they have applied this to something with a lot of rows.

Is there a way of seeing which statements / backends / processes have greater than 64 stxns? I'd like to monitor this.

- James


The contents of this email are confidential and may be subject to legal or professional privilege and copyright. No representation is made that this email is free of viruses or other defects. If you have received this communication in error, you may not copy or distribute any part of it or otherwise disclose its contents to anyone. Please advise the sender of your incorrect receipt of this correspondence.
Also be on the look-out for begin trans; begin trans; etc  I read Kumar's report as nested transactions.  If your gang is doing a transaction per row, they need a kick in the rear.  Anyone not closing those needs a pink slip. 
--------------FB9521910F66F516FE311E1E--