Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 2BA7B1A8BC81 for ; Fri, 27 Jul 2012 02:47:30 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SudOY-0001M3-KA for pgsql-bugs@postgresql.org; Fri, 27 Jul 2012 05:47:29 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q6R5l61l025327; Fri, 27 Jul 2012 01:47:07 -0400 (EDT) From: Tom Lane To: Craig Ringer cc: luben karavelov , pgsql-bugs@postgresql.org Subject: Re: BUG #6763: Severe memory leak with arrays and hstore In-reply-to: <50120966.4030903@ringerc.id.au> References: <5010FD0F.4020400@ringerc.id.au> <10398EEF-03DE-405E-B276-06F73ABF9E3A@mail.bg> <5011FD5D.3040503@ringerc.id.au> <5011FDEE.1010008@ringerc.id.au> <50120966.4030903@ringerc.id.au> Comments: In-reply-to Craig Ringer message dated "Fri, 27 Jul 2012 11:22:14 +0800" Date: Fri, 27 Jul 2012 01:47:05 -0400 Message-ID: <25326.1343368025@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/217 X-Sequence-Number: 33693 Craig Ringer writes: > OK, it's certainly leaking, but not in the same drastic way I was able > to reproduce manually a couple of times earlier. Self-contained test > case attached. Using HEAD with stock parameters, I don't see any significant change in allocated address space (VSZ): it sits right around 170MB. The reported resident set size (RSS) starts from very little and rises to about 140MB, but I think that's just an artifact of the process touching more and more of the shared-buffers array as it runs. The actual backend memory consumption seems to be just a few meg. I can get it to blow out memory if I set work_mem large enough to persuade the planner to use hash aggregation (whereupon it tries to run all the array_agg aggregates in parallel). However, that requires work_mem set to a couple of GB, and I don't think it's really a bug when the backend goes ahead and uses a couple of GB after I told it it could. It's possible that the OP's problem boiled down to the planner making a drastic underestimate of the number of GROUP BY groups, which could mislead it into applying hash aggregation when there's not room; or if the space used per aggregate was a lot more than the 8K that the planner assumes when dealing with array_agg. But neither of those errors seems to be happening in this example case. regards, tom lane