Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZLOAA-0004hu-Pk for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Aug 2015 04:12:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZLOA9-0000Vi-Rn for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Aug 2015 04:12:45 +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) (envelope-from ) id 1ZLO9X-0008EI-4S for pgsql-bugs@postgresql.org; Sat, 01 Aug 2015 04:12:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZLO9N-0003Tp-Ds for pgsql-bugs@postgresql.org; Sat, 01 Aug 2015 04:12:04 +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 t714BtEr020723; Sat, 1 Aug 2015 00:11:55 -0400 From: Tom Lane To: brent_despain@selinc.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13530: sort receives "unexpected out-of-memory situation during sort" In-reply-to: <20150731220618.2987.1731@wrigleys.postgresql.org> References: <20150731220618.2987.1731@wrigleys.postgresql.org> Comments: In-reply-to brent_despain@selinc.com message dated "Fri, 31 Jul 2015 22:06:18 -0000" Date: Sat, 01 Aug 2015 00:11:55 -0400 Message-ID: <20722.1438402315@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) 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 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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs