Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id A82592E002D for ; Fri, 2 May 2008 18:25:22 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 20134-06 for ; Fri, 2 May 2008 18:25:12 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from 27.mail-out.ovh.net (27.mail-out.ovh.net [91.121.30.210]) by developer.postgresql.org (Postfix) with SMTP id B21852E0031 for ; Fri, 2 May 2008 18:25:16 -0300 (ADT) Received: (qmail 6492 invoked by uid 503); 2 May 2008 23:17:26 -0000 Received: from gw2.ovh.net (HELO mail170.ha.ovh.net) (213.251.189.202) by 27.mail-out.ovh.net with SMTP; 2 May 2008 23:17:26 -0000 Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 2 May 2008 21:25:09 -0000 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO apollo13.peufeu.com) (88.161.102.87) by ns0.ovh.net with SMTP; 2 May 2008 21:25:08 -0000 Date: Fri, 02 May 2008 23:30:44 +0200 To: "Alexy Khrabrov" , "Craig James" Subject: Re: two memory-consuming postgres processes From: PFC Cc: pgsql-performance@postgresql.org Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <27A4D379-2553-496D-A96C-102F2A5E62C2@gmail.com> <21403.1209759217@sss.pgh.pa.us> <72E02D29-848B-467A-AE6B-401568010254@gmail.com> <481B8160.2090106@emolecules.com> Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/9.24 (Linux) X-Ovh-Tracer-Id: 9706383097952994839 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|H 0.5/N X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.667 tagged_above=0 required=5 tests=AWL=0.667 X-Spam-Level: X-Archive-Number: 200805/33 X-Sequence-Number: 30001 > I created several indices for the primary table, yes. Sure I can do a > table for a volatile column, but then I'll have to create a new such > table for each derived column -- that's why I tried to add a column to > the existing table. Yet seeing this is really slow, and I need to to > many derived analyses like this -- which are later scanned in other > computations, so should persist -- I indeed see no other way but to > procreate derived tables with the same key, one column per each... OK, so in that case, if you could do all of your derived column calculations in one query like this : CREATE TABLE derived AS SELECT ... FROM ... (perform all your derived calculations here) or : BEGIN; <-- this is important to avoid writing xlog CREATE TABLE derived AS ... INSERT INTO derived SELECT ... FROM ... (perform all your derived calculations here) COMMIT; Basically, updating the entire table several times to add a few simple columns is a bad idea. If you can compute all the data you need in one query, like above, it will be much faster. Especially if you join one large table to several smaller ones, and as long as the huge data set doesn't need to be sorted (check the query plan using EXPLAIN). Try to do as much as possible in one query to scan the large dataset only once. Note that the above will be faster than updating the entire table since it needs to write much less data : it doesn't need to delete the old rows, and it doesn't need to write the transaction log, since if the transaction rolls back, the table never existed anyway. Also since your newly created table doesn't have any indexes, they won't need to be updated. If you really need to update an entire table multiple times, you will need to : - Use hardware that can handle disk writes at a decent speed (that isn't a characteristic of a laptop drive) - use MyIsam, yes (but if you need to make complex queries on the data afterwards, it could suck).