Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UMLrl-0000z3-6y for pgsql-bugs@arkaria.postgresql.org; Sun, 31 Mar 2013 17:16:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UMLrk-000713-IE for pgsql-bugs@arkaria.postgresql.org; Sun, 31 Mar 2013 17:16:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UMLri-00070v-Nl for pgsql-bugs@postgresql.org; Sun, 31 Mar 2013 17:16:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UMLra-0004Ig-EQ for pgsql-bugs@postgresql.org; Sun, 31 Mar 2013 17:16:22 +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 r2VHGDPq012428; Sun, 31 Mar 2013 13:16:13 -0400 (EDT) From: Tom Lane To: stiening@comcast.net cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8013: Memory leak In-reply-to: References: Comments: In-reply-to stiening@comcast.net message dated "Sat, 30 Mar 2013 14:01:27 -0000" Date: Sun, 31 Mar 2013 13:16:12 -0400 Message-ID: <12427.1364750172@sss.pgh.pa.us> X-Pg-Spam-Score: -4.2 (----) 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 stiening@comcast.net writes: > The query: > SELECT pts_key,count(*) > FROM tm_tm_pairs GROUP BY pts_key HAVING count(*) !=1 ORDER BY > pts_key > Which is executed as: > GroupAggregate (cost=108680937.80..119278286.60 rows=470993280 width=4) > Filter: (count(*) <> 1) > -> Sort (cost=108680937.80..109858421.00 rows=470993280 width=4) > Sort Key: pts_key > -> Seq Scan on tm_tm_pairs (cost=0.00..8634876.80 rows=470993280 > width=4) > uses all available memory (32GB). pts_key is an integer and the table > contains about 500 million rows. That query plan doesn't look like it should produce any undue memory consumption on the server side. How many distinct values of pts_key are there, and what are you using to collect the query result client-side? psql, for instance, would try to absorb the whole query result in-memory, so there'd be a lot of memory consumed by psql if there are a lot of pts_key values. (You can set FETCH_COUNT to alleviate that.) A different line of thought is that you might have set work_mem to an unreasonably large value --- the sort step will happily try to consume work_mem worth of memory. 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