Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A1AEDB5DD5F for ; Mon, 12 Sep 2011 15:24:57 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 65641-01-6 for ; Mon, 12 Sep 2011 18:24:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mxtip01-umsystem-out.um.umsystem.edu (mxtip01-umsystem-out.um.umsystem.edu [209.106.229.49]) by mail.postgresql.org (Postfix) with ESMTP id 89550B5DE36 for ; Mon, 12 Sep 2011 15:22:53 -0300 (ADT) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4EAIBNbk7RauQY/2dsb2JhbABBp3B4gVIBAQU4QAEQCxgJFg8JAwIBAgFFBg0BBwEBtQeIf4ZuBIdtkGUJjBw Received: from um-tsmtpin2.um.umsystem.edu ([209.106.228.24]) by mxtip01-missouri-out.um.umsystem.edu with ESMTP; 12 Sep 2011 13:22:52 -0500 Received: from um-tsmtpout1.um.umsystem.edu ([209.106.228.23]) by um-tsmtpin2.um.umsystem.edu with Microsoft SMTPSVC(6.0.3790.4675); Mon, 12 Sep 2011 13:22:52 -0500 Received: from [128.206.129.163] ([128.206.129.163]) by um-tsmtpout1.um.umsystem.edu over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Mon, 12 Sep 2011 13:22:52 -0500 Message-ID: <4E6E4DFB.2070605@missouri.edu> Date: Mon, 12 Sep 2011 13:22:51 -0500 From: Robert Schnabel User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 To: "sthomas@peak6.com" CC: Andy Colson , pgsql-performance Subject: Re: Allow sorts to use more available memory References: <4E6E426D.7060405@missouri.edu> <4E6E45CA.20606@squeakycode.net> <4E6E4826.8050002@peak6.com> In-Reply-To: <4E6E4826.8050002@peak6.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 12 Sep 2011 18:22:52.0544 (UTC) FILETIME=[FC0A2800:01CC7178] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/153 X-Sequence-Number: 44929 On 9/12/2011 12:57 PM, Shaun Thomas wrote: > On 09/12/2011 12:47 PM, Andy Colson wrote: > >> work_mem is not the total a query can use. I believe each step can >> use that much, and each backend can use it for multiple bits. So if >> you had two backends, each doing 2 sorts, you'd use 2*2 = 4 * 2GB = >> 8GB. > Exactly. Find a big query somewhere in your system. Use EXPLAIN to > examine it. Chances are, that one query has one or more sorts. Each one > of those gets its own work_mem. Each sort. The query have four sorts? It > may use 4*work_mem. On a whim a while back, I doubled our 8MB setting to > 16MB on a test system. During a load test, the machine ran out of > memory, swapped out, and finally crashed after the OOM killer went nuts. > > Set this value *at your own risk* and only after *significant* testing. > Having it too high can have rather unexpected consequences. Setting it > to 1 or 2GB, unless you have VERY few threads, or a TON of memory, is a > very, very bad idea. > Yep, I know. But in the context of the data warehouse where *I'm the only user* and I have a query that does, say 4 large sorts like http://explain.depesz.com/s/BrAO and I have 32GB RAM I'm not worried about using 8GB or 16GB in the case of work_mem = 4GB. I realize the query above only used 1.9GB for the largest sort but I know I have other queries with 1 or 2 sorts that I've watched go to disk. Bob