Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0Fmq-0003jd-8p for pgsql-bugs@arkaria.postgresql.org; Thu, 05 Oct 2017 23:42:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e0Fmo-0003GA-Hu for pgsql-bugs@arkaria.postgresql.org; Thu, 05 Oct 2017 23:42:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0Fmn-0003FJ-Ig for pgsql-bugs@postgresql.org; Thu, 05 Oct 2017 23:42:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0Fmk-0005Hi-Li for pgsql-bugs@postgresql.org; Thu, 05 Oct 2017 23:42:36 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v95NgUAr004564; Thu, 5 Oct 2017 19:42:30 -0400 From: Tom Lane To: Andres Freund cc: Michael Paquier , Ben Chobot , PostgreSQL mailing lists Subject: Re: pg_logical_slot_peek_changes crashes postgres when called from inside pl/pgsql In-reply-to: <20171005230105.qv2yrtadbkbc5y5r@alap3.anarazel.de> References: <73FBA179-C68C-4540-9473-71E865408B15@silentmedia.com> <8637.1507217920@sss.pgh.pa.us> <20171005211058.z5obk2c2e7zvauk6@alap3.anarazel.de> <32374.1507239819@sss.pgh.pa.us> <20171005230105.qv2yrtadbkbc5y5r@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Thu, 05 Oct 2017 16:01:05 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4562.1507246950.1@sss.pgh.pa.us> Date: Thu, 05 Oct 2017 19:42:30 -0400 Message-ID: <4563.1507246950@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Andres Freund writes: > On 2017-10-05 17:43:39 -0400, Tom Lane wrote: >> Nah, I take that back. The AbortCurrentTransaction call looks funny >> (and is sadly underdocumented) but it's not invalid to call it and >> then call RollbackAndReleaseCurrentSubTransaction. > It's not perfectly documented, but there's some: What I'm on about is that I think the AbortCurrentTransaction call needs a comment along the lines of * Roll back the current (sub)transaction. In the using_subtxn * case, we could leave it to RollbackAndReleaseCurrentSubTransaction * to do this, but we do it separately anyway because XYZ. It's the fact that XYZ isn't very obvious that makes this comment necessary. I'm guessing it's because ReorderBufferExecuteInvalidations either doesn't work or is less efficient if inside a still-valid transaction, but the fact that I need to guess is the problem. >> I'm not sure about a good way to fix #2 without re-introducing the memory >> leaks that call was added to fix (cf 7ec1c5a86). > I think I don't fully understand what 7ec1c5a86 is trying to > achieve. I dug around in the archives and found https://www.postgresql.org/message-id/26365.1162532453%40sss.pgh.pa.us The function shown there doesn't appear to leak any memory at all in HEAD, but if you dike out the memory context reset in question, it leaks like crazy. I didn't try to reconfirm my old estimate of 16KB per iteration, but it seemed to be in that ballpark still. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs