Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 3FA48133740B for ; Tue, 5 Apr 2011 16:27:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 79458-02 for ; Tue, 5 Apr 2011 19:27:35 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from hogranch.com (hogranch.com [75.101.82.47]) by mail.postgresql.org (Postfix) with ESMTP id 668E013364DE for ; Tue, 5 Apr 2011 16:27:34 -0300 (ADT) Received: from [127.0.0.1] (porker [192.168.0.2]) by hogranch.com (8.11.6/8.11.6) with ESMTP id p35JRRc11451 for ; Tue, 5 Apr 2011 12:27:27 -0700 Message-ID: <4D9B6D1F.9050406@hogranch.com> Date: Tue, 05 Apr 2011 12:27:27 -0700 From: John R Pierce User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: pgsql-general@postgresql.org Subject: Re: Out of memory References: <666FB8D75E95AE42965A0E76A5E5337E06DCC19F63@prdlsmmsg01.ad.linz.govt.nz> In-Reply-To: <666FB8D75E95AE42965A0E76A5E5337E06DCC19F63@prdlsmmsg01.ad.linz.govt.nz> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-HawgScanner-Information: Please contact the ISP for more information X-HawgScanner: Found to be clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/154 X-Sequence-Number: 174510 On 04/05/11 2:50 AM, Jeremy Palmer wrote: > I've been having repeated troubles trying to get a PostgreSQL app to play nicely on Ubuntu. I recently posted a message on this list about an out of memory error and got a resolution by reducing the work_mem setting. However I'm now getting further out of memory issues during the same stage of plpgsql function as mentioned before. > > The function itself is run as part of larger transaction which does the following: > > 1/ Maintains 104 tables (15 PostGIS tables), by loading and applying incremental table changes. A typical incremental load with maintain about 10,000 rows. > > 2/ When each one of these tables is updated an after trigger is fired that maintains an associated table revision table. > > 3/ After all of the tables are maintained a plpgsql function is called to build/maintain a set of de-normalised tables. These tables total about 20GB. Each one of these tables is compared against the previous table revision to determine its row changes. It's in this function that the out of memory exception is occurring. a few random questions... Does that all really have to be a single transaction? Do you really need to use triggers for your revision tracking, and can't rely on your daily update cycle to manually set the revision information? Is it really necessary to generate massive denormalized tables, rather than using view's to join the data? > shared_buffers = 512MB > maintenance_work_mem = 512MB > temp_buffers = 256MB > work_mem = 1MB > wal_buffers = 16MB > effective_cache_size = 4094MB > > The size of the database is 350GB. The typical number of users connected to the database is 1 or 2. This database is used for loading external data, managing revision table information and generating and outputting de-normalised datasets, so it does not have a high number of transactions running. Typically 1 large one per day. with only 1-2 connections, you certainly could increase the work_mem. Alternately, this single giant transaction could manually set a larger work_mem which would only apply to it. Personally, given your 8gb system and what you've described, I think I'd set the tuning parameters something like... shared_buffers = 1GB maintenance_work_mem = 128MB temp_buffers = 64MB work_mem = 16MB wal_buffers = 16MB effective_cache_size = 4094MB adjust effective_cache_size to somewhat less than the 'cached' value shown in `free -m` after your system has been running for awhile.