Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 89DBD9FB318 for ; Sun, 28 Jan 2007 18:11:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 94965-07-2 for ; Sun, 28 Jan 2007 18:11:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mx00.pub.collaborativefusion.com (mx00.pub.collaborativefusion.com [206.210.89.199]) by postgresql.org (Postfix) with ESMTP id 762719FB31E for ; Sun, 28 Jan 2007 18:11:20 -0400 (AST) Received: from working (c-71-60-174-60.hsd1.pa.comcast.net [71.60.174.60]) (AUTH: LOGIN wmoran, TLS: TLSv1/SSLv3,256bits,AES256-SHA) by wingspan with esmtp; Sun, 28 Jan 2007 17:11:19 -0500 id 00056417.45BD1F87.000004F8 Date: Sun, 28 Jan 2007 17:11:18 -0500 From: Bill Moran To: "Campbell, Lance" Cc: pgsql-performance@postgresql.org Subject: Re: work_mem Message-Id: <20070128171118.03fa29db.wmoran@collaborativefusion.com> In-Reply-To: References: Organization: Collaborative Fusion Inc. X-Mailer: Sylpheed version 2.2.10 (GTK+ 2.10.6; i386-portbld-freebsd6.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/396 X-Sequence-Number: 22997 "Campbell, Lance" wrote: > > I have been researching how to improve my overall performance of > postgres. I am a little confused on the reasoning for how work_mem is > used in the postgresql.conf file. The way I understand the > documentation is you define with work_mem how much memory you want to > allocate per search. Couldn't you run out of memory? This approach > seems kind of odd to me. How do you tell the system not to allocate too > much memory if you all of the sudden got hit with a heavier number of > queries? work_mem tells PostgreSQL how much memory to use for each sort/join. If a sort/join exceeds that amount, PostgreSQL uses temp files on the disk instead of memory to do the work. If you want a query to complete, you've got to allow Postgres to finish it. The work_mem setting gives Postgres information on how to go about doing that in the best way. If you want to guarantee that individual processes can't suck up tons of memory, use your operating system's ulimit or equivalent functionality. That's one of the advantages of the forking model, it allows the operating system to enforce a certain amount of policy an a per-connection basis. HTH, Bill