Re: BUG #13530: sort receives "unexpected out-of-memory situation during sort" - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #13530: sort receives "unexpected out-of-memory situation during sort"
Date
Msg-id 20722.1438402315@sss.pgh.pa.us
Whole thread Raw
In response to BUG #13530: sort receives "unexpected out-of-memory situation during sort"  (brent_despain@selinc.com)
Responses Re: BUG #13530: sort receives "unexpected out-of-memory situation during sort"  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
brent_despain@selinc.com writes:
> We are occasionally receiving "unexpected out-of-memory situation during
> sort".

Hmm.  Looking at the code here, it suddenly strikes me that it's assuming
that LACKMEM() wasn't true to begin with, and that this is not guaranteed,
because we adjust the memory consumption counter *before* we call
puttuple_common.  So it would fail only if we exhausted allowedMem on
the same tuple that would cause an enlargement of the memtuples[] array,
which would be unusual enough to explain why this isn't terribly
reproducible.

Could you try something like this at the head of grow_memtuples() to
see if it makes things better?

    /* Forget it if we've already maxed out memtuples, per comment above */
    if (!state->growmemtuples)
        return false;
+    /* Forget it if we already exhausted memory */
+    if (LACKMEM(state))
+        return false;


            regards, tom lane

pgsql-bugs by date:

Previous
From: brent_despain@selinc.com
Date:
Subject: BUG #13530: sort receives "unexpected out-of-memory situation during sort"
Next
From: "Peter J. Holzer"
Date:
Subject: Re: 9.5alpha1: Partial index not used