Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZLb0w-000422-4x for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Aug 2015 17:56:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZLb0v-0003lP-3X for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Aug 2015 17:56:05 +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 1ZLb0t-0003kz-Gk for pgsql-bugs@postgresql.org; Sat, 01 Aug 2015 17:56:03 +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 1ZLb0m-00028Z-2g for pgsql-bugs@postgresql.org; Sat, 01 Aug 2015 17:56:02 +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 t71HtrRH006978; Sat, 1 Aug 2015 13:55:54 -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: <20722.1438402315@sss.pgh.pa.us> References: <20150731220618.2987.1731@wrigleys.postgresql.org> <20722.1438402315@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sat, 01 Aug 2015 00:11:55 -0400" Date: Sat, 01 Aug 2015 13:55:53 -0400 Message-ID: <6977.1438451753@sss.pgh.pa.us> X-Pg-Spam-Score: -3.0 (---) 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 I wrote: > 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. In the light of day that theory doesn't hold up, because if LACKMEM were true on entry (ie, availMem < 0) then we'd compute a grow_ratio less than one, so that the "Must enlarge array by at least one element" check would trigger, and we'd never get to the code that's failing. Another idea that occurred to me is that the "memory chunk overhead won't increase" assumption could fail if sizeof(SortTuple) weren't a multiple of MAXALIGN (because repalloc internally rounds the request up to a MAXALIGN boundary) but that doesn't seem plausible either. I'd expect that struct to be 16 bytes on 32-bit or 24 bytes on 64-bit, so it should be maxaligned on any hardware I know about. So I'm about out of ideas. Could you modify your copy of the code to log interesting details when you get this error, like the old and new memtupsize and chunk space measurements? That might give us a clue what's the problem. 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