Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0L4U-0001Rn-Tm for pgsql-bugs@arkaria.postgresql.org; Fri, 06 Oct 2017 05:21:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e0L4T-00032n-OM for pgsql-bugs@arkaria.postgresql.org; Fri, 06 Oct 2017 05:21:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0L4S-00031u-P2 for pgsql-bugs@postgresql.org; Fri, 06 Oct 2017 05:21:12 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e0L4O-0004A4-QP for pgsql-bugs@postgresql.org; Fri, 06 Oct 2017 05:21:12 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id DCB6820D50; Fri, 6 Oct 2017 01:21:06 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Fri, 06 Oct 2017 01:21:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=X9VGhpmlTQ4hvpyGba 6hVxX+prYbonezQjVE8DTbnE8=; b=IhaqklI2/Q54LJT6CZWMxz2CtNwHBdEkTT UE5X0UeURw+i1oN/3ohe86tGqcdBrb3hhh9qP+HbvazfLE2qyZVjn+KZ66U50oba /UmUhw7bp88jMZSNQslH+FosBhETvh9OOO+y4w512aiyCZGgqpA0bSNybTfz81hk wq0v8hmP5HX3gAVYZUJbi6Pzd9ambvSLCqeRb8527DVrtDxKZpmcHuGXkGh9x45Q ZPh9FKfWGzxinvUu9T7hm9UKIxwhXzQVWFRs8mWivHMct4ugoiOyIMEhUjP4wJ9v FAuqSJgwHKAq2/o8SAjJHjutsAajDOF8jOuo+6PrVBQpzadGVDFA== X-ME-Sender: X-Sasl-enc: WXQSsI6XbTdzcS+1bPA51/gA2vJIC+gKsow0dAM99H7P 1507267266 Received: from intern.anarazel.de (unknown [136.24.76.72]) by mail.messagingengine.com (Postfix) with ESMTPA id 895E624009; Fri, 6 Oct 2017 01:21:06 -0400 (EDT) Date: Thu, 5 Oct 2017 22:21:05 -0700 From: Andres Freund To: Tom Lane Cc: Michael Paquier , Ben Chobot , PostgreSQL mailing lists Subject: Re: pg_logical_slot_peek_changes crashes postgres when called from inside pl/pgsql Message-ID: <20171006052105.jfxllpi6lcu7q2a7@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> <4563.1507246950@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <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 On 2017-10-05 19:42:30 -0400, Tom Lane wrote: > >> 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. I knew that I disliked SPI, but I forgot how much I disliked it :(. I think one of these years we should really replace it - it quite frequently comes up as problematic. I was wondering if the appropriate fix here wouldn't be to just always do an SPI_connect()/finish() inside such subtransactions - that feels more correct. But it's not easy due to the way memory management's done in plpgsql (and presumably elsewhere) :(. So far your option of allowing to opt in into additional cleanup in the CATCH seems the least ugly I'm kinda surprised that this only causes problems with logical decoding and not elsewhere, this isn't a new issue. Greetings, Andres Freund -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs