Re: pg_logical_slot_peek_changes crashes postgres when called from inside pl/pgsql

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Ben Chobot <bench(at)silentmedia(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: pg_logical_slot_peek_changes crashes postgres when called from inside pl/pgsql
Date: 2017-10-06 05:21:05
Message-ID: 20171006052105.jfxllpi6lcu7q2a7@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Noah Misch 2017-10-06 05:50:20 Re: BUG #14794: Installation failure if user specify French password
Previous Message Michael Paquier 2017-10-06 03:57:59 Re: BUG #14843: CREATE TABLE churns through all memory, crashes db