Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 81F3F2E003B for ; Fri, 2 May 2008 18:02:33 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 60978-07 for ; Fri, 2 May 2008 18:02:27 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from relay-1.mail.nethere.net (relay-1.mail.nethere.net [66.63.128.161]) by developer.postgresql.org (Postfix) with ESMTP id 2EACE2E0045 for ; Fri, 2 May 2008 18:02:30 -0300 (ADT) Received: from scan-1.mail.nethere.net (scan-1.mail.nethere.net [66.63.128.132]) by relay-1.mail.nethere.net (Postfix) with ESMTP id 2CAB528BA1 for ; Fri, 2 May 2008 14:02:26 -0700 (PDT) Received: from mta-2.mail.nethere.net by scan-1.mail.nethere.net with LMTP id 4gw2jtsYirG9; Fri, 2 May 2008 14:02:26 -0700 (PDT) Received: from lisa-james-computer.local (wsip-68-224-174-233.sd.sd.cox.net [68.224.174.233]) by mta-2.mail.nethere.net (Postfix) with ESMTP id 0C174130C22 for ; Fri, 2 May 2008 14:02:26 -0700 (PDT) Message-ID: <481B8160.2090106@emolecules.com> Date: Fri, 02 May 2008 14:02:24 -0700 From: Craig James User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: two memory-consuming postgres processes References: <27A4D379-2553-496D-A96C-102F2A5E62C2@gmail.com> <21403.1209759217@sss.pgh.pa.us> <72E02D29-848B-467A-AE6B-401568010254@gmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/30 X-Sequence-Number: 29998 On Fri, May 2, 2008 at 2:26 PM, Alexy Khrabrov wrote: > I naively thought that if I have a 100,000,000 row table, of the form > (integer,integer,smallint,date), and add a real coumn to it, it will scroll > through the memory reasonably fast. In Postgres, an update is the same as a delete/insert. That means that changing the data in one column rewrites ALL of the columns for that row, and you end up with a table that's 50% dead space, which you then have to vacuum. Sometimes if you have a "volatile" column that goes with several "static" columns, you're far better off to create a second table for the volatile data, duplicating the primary key in both tables. In your case, it would mean the difference between 10^8 inserts of (int, float), very fast, compared to what you're doing now, which is 10^8 insert and 10^8 deletes of (int, int, smallint, date, float), followed by a big vacuum/analyze (also slow). The down side of this design is that later on, it requires a join to fetch all the data for each key. You do have a primary key on your data, right? Or some sort of index? Craig