Re: Should pg 11 use a lot more memory building an spgist index?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Should pg 11 use a lot more memory building an spgist index?
Date: 2018-10-26 09:16:09
Message-ID: 24288.1540545369@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Bruno Wolff III <bruno(at)wolff(dot)to> writes:
> I have something that seems to produce it on rhel7. Fedora isn't working
> well either, but the difference may be due to postgresql.conf being
> different or some difference in the Fedora build.

Hmm, in my hands this produces the same size leak (~28GB) in either v10
or v11. In HEAD, somebody's made it even worse (~43GB). So this is
certainly pretty broken, but I'm not sure why it seems worse to you in
v11 than before.

The core of the problem I see is that check_exclusion_or_unique_constraint
does index_beginscan/index_rescan/index_endscan in a long-lived context,
while spgendscan seems to have employed dice while deciding which of
spgbeginscan's allocations it would bother to pfree. This is ancient,
though the specific case you have here can only be tested back to v10
because the inet SPGIST opclass wasn't there before.

A quick review of the other index AM endscan methods seems to indicate
that they all try to clean up their mess. So maybe we should just make
spgendscan do likewise. Alternatively, we could decide that requiring
endscan methods to free storage is not very safe, in which case it would
be incumbent on check_exclusion_or_unique_constraint to make a temporary
context to run the scan in. But if we're going to do the latter, I think
we oughta go full in and remove the retail pfree's from all the *endscan
functions. We'd also have to review other callers of
index_beginscan/index_endscan to see which ones might also need their own
temp contexts. So that would surely end up being more invasive than
just adding some pfree's to spgendscan would be. Maybe in the long run
it'd be worth it, but probably not in the short run, or for back-patching.

Thoughts?

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Munro 2018-10-26 09:26:11 Re: Postgresql issue: FATAL: dsa_allocate could not find 7 free pages
Previous Message Alexandre Assouad 2018-10-26 08:17:12 Re: Postgresql issue: FATAL: dsa_allocate could not find 7 free pages

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2018-10-26 09:39:13 Re: Should pg 11 use a lot more memory building an spgist index?
Previous Message Amit Langote 2018-10-26 07:42:30 Re: CVE-2017-7484-induced bugs, or, btree cmp functions are not leakproof?