Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id F041564FD2A for ; Wed, 20 Aug 2008 06:10:31 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 12282-05 for ; Wed, 20 Aug 2008 06:10:21 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from postrelay.edis.at (postrelay.edis.at [81.223.48.30]) by postgresql.org (Postfix) with ESMTP id F1D7C64FCE6 for ; Wed, 20 Aug 2008 06:10:24 -0300 (ADT) Received: from mailrelay.edis.at (postrelay.edis.at [81.223.48.30]) by postrelay.edis.at (Postfix) with ESMTP id 0DBD940180CD for ; Wed, 20 Aug 2008 11:10:22 +0200 (CEST) Received: from [91.83.13.128] ([::ffff:91.83.13.128]) (AUTH: CRAM-MD5 zb@cybertec.at, TLS: TLSv1/SSLv3,256bits,AES256-SHA) by mailrelay.edis.at with esmtp; Wed, 20 Aug 2008 11:10:21 +0200 id 00000000140473D6.0000000048ABDF7D.000072D1 Message-ID: <48ABDF7D.3040102@cybertec.at> Date: Wed, 20 Aug 2008 11:10:21 +0200 From: Zoltan Boszormenyi User-Agent: Thunderbird 2.0.0.16 (X11/20080723) MIME-Version: 1.0 To: Moritz Onken CC: pgsql-performance@postgresql.org Subject: Re: Slow query with a lot of data References: <90AA1B69-4E9C-4710-9D58-F65620DDA022@houseofdesign.de> <8EF0BB61-D8FE-47E8-97DD-1009F7EB5431@houseofdesign.de> <0BFF9855-F1FA-4A83-B8B2-622D7CE69F77@houseofdesign.de> <3663375B-7AC0-43F6-B6EC-D3EE572F3D34@houseofdesign.de> <24E3FBFF-E0B8-435E-ACE1-652E93FE2213@houseofdesign.de> <380CD097-4A33-4134-8C13-B9BF34EC6C63@houseofdesign.de> <979A6EAC-24DC-4D92-A4B6-F8702221C5EC@houseofdesign.de> <6F57A01F-F83F-477F-B86B-617D0F843FB1@houseofdesign.de> In-Reply-To: <6F57A01F-F83F-477F-B86B-617D0F843FB1@houseofdesign.de> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200808/211 X-Sequence-Number: 31092 Moritz Onken írta: > > Am 19.08.2008 um 17:23 schrieb Moritz Onken: > >> >> Am 19.08.2008 um 16:49 schrieb Scott Carey: >> >>> What is your work_mem set to? The default? >>> >>> Try increasing it significantly if you have the RAM and seeing if >>> that affects the explain plan. You may even want to set it to a >>> number larger than the RAM you have just to see what happens. In >>> all honesty, it may be faster to overflow to OS swap space than sort >>> too many rows, but ONLY if it changes the plan to a significantly >>> more efficient one. >>> >>> Simply type >>> 'SET work_mem = '500MB'; >>> before running your explain. Set it to even more RAM if you have >>> the space for this experiment. >>> >>> In my experience the performance of aggregates on large tables is >>> significantly affected by work_mem and the optimizer will chosse >>> poorly without enough of it. It will rule out plans that may be >>> fast enough when overflowing to disk in preference to colossal sized >>> sorts (which likely also overflow to disk but take hours or days). >> >> Thanks for that advice but the explain is not different :-( >> >> moritz >> >> -- > > Hi, > > I started the query with work_mem set to 3000MB. The explain output > didn't change but it runs now much faster (about 10 times). The swap > isn't used. How can you explain that? $ cat /proc/sys/vm/overcommit_memory 0 $ less linux/Documentation/filesystems/proc.txt ... overcommit_memory ----------------- Controls overcommit of system memory, possibly allowing processes to allocate (but not use) more memory than is actually available. 0 - Heuristic overcommit handling. Obvious overcommits of address space are refused. Used for a typical system. It ensures a seriously wild allocation fails while allowing overcommit to reduce swap usage. root is allowed to allocate slightly more memory in this mode. This is the default. 1 - Always overcommit. Appropriate for some scientific applications. 2 - Don't overcommit. The total address space commit for the system is not permitted to exceed swap plus a configurable percentage (default is 50) of physical RAM. Depending on the percentage you use, in most situations this means a process will not be killed while attempting to use already-allocated memory but will receive errors on memory allocation as appropriate. ... I guess you are running on 64-bit because "obvious overcommit" exceeds 3GB already. Or you're running 32-bit and overcommit_memory=1 on your system. Best regards, Zoltán Böszörményi -- ---------------------------------- Zoltán Böszörményi Cybertec Schönig & Schönig GmbH http://www.postgresql.at/