X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 228799DCB38 for ; Tue, 20 Dec 2005 17:48:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 73822-07 for ; Tue, 20 Dec 2005 17:48:04 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id C67839DCB0B for ; Tue, 20 Dec 2005 17:48:00 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jBKLilJM006543; Tue, 20 Dec 2005 16:44:47 -0500 (EST) To: "Jim C. Nasby" cc: Greg Stark , Cristian Prieto , pgsql-performance@postgresql.org Subject: Re: Any way to optimize GROUP BY queries? In-reply-to: <20051220194710.GJ28771@pervasive.com> References: <00d701c604c1$e6945d80$6500a8c0@gt.ClickDiario.local> <87wti0ak60.fsf@stark.xeocode.com> <20051220194710.GJ28771@pervasive.com> Comments: In-reply-to "Jim C. Nasby" message dated "Tue, 20 Dec 2005 13:47:10 -0600" Date: Tue, 20 Dec 2005 16:44:47 -0500 Message-ID: <6542.1135115087@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.024 required=5 tests=[AWL=0.024] X-Spam-Score: 0.024 X-Spam-Level: X-Archive-Number: 200512/514 X-Sequence-Number: 16335 "Jim C. Nasby" writes: > On Mon, Dec 19, 2005 at 03:47:35PM -0500, Greg Stark wrote: >> Increase your work_mem (or sort_mem in older postgres versions), you can do >> this for the server as a whole or just for this one session and set it back >> after this one query. You can increase it up until it starts causing swapping >> at which point it would be counter productive. > Just remember that work_memory is per-operation, so it's easy to push > the box into swapping if the workload increases. You didn't say how much > memory you have, but I'd be careful if work_memory * max_connections > gets very much larger than your total memory. It's considered good practice to have a relatively small default work_mem setting (in postgresql.conf), and then let individual sessions push up the value locally with "SET work_mem" if they are going to execute queries that need it. This works well as long as you only have one or a few such "heavy" sessions at a time. regards, tom lane