Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 914896326D0 for ; Thu, 7 Jan 2010 09:39:25 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 45669-04-5 for ; Thu, 7 Jan 2010 13:38:57 +0000 (UTC) X-Greylist: delayed 00:24:07.637842 by SQLgrey-1.7.6 Received: from ews43.everyware.ch (ews43.everyware.ch [212.71.111.43]) by mail.postgresql.org (Postfix) with ESMTP id 3792263384C for ; Thu, 7 Jan 2010 09:39:03 -0400 (AST) Received: from mars.lemaco.ch [212.71.105.68] by ews43.everyware.ch with ESMTP (SMTPD32-8.15) id AE4C6528014E; Thu, 07 Jan 2010 14:14:52 +0100 Message-ID: <4B45DE4C.4050606@beecom.ch> Date: Thu, 07 Jan 2010 14:14:52 +0100 From: Leo Mannhart User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Carlo Stonebanks CC: pgsql-performance@postgresql.org Subject: Re: Massive table (500M rows) update nightmare References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201001/84 X-Sequence-Number: 36964 Carlo Stonebanks wrote: > Our DB has an audit table which is 500M rows and growing. (FYI the > objects being audited are grouped semantically, not individual field > values). > > Recently we wanted to add a new feature and we altered the table to add > a new column. We are backfilling this varchar(255) column by writing a > TCL script to page through the rows (where every update is a UPDATE ... > WHERE id >= x AND id < x+10 and a commit is performed after every 1000 > updates statement, i.e. every 10000 rows.) > > We have 10 columns, six of which are indexed. Rough calculations suggest > that this will take two to three weeks to complete on an 8-core CPU with > more than enough memory. > > As a ballpark estimate - is this sort of performance for an 500M updates > what one would expect of PG given the table structure (detailed below) > or should I dig deeper to look for performance issues? > > As always, thanks! > > Carlo > If it is possible to lock this audit table exclusively (may be during off peak hours) I would look into - create new_audit_table as select col1, col2, col3 ... col9, 'new_col_value' from old_audit_table; - create all indexes - drop old_audit_table - rename new_audit_table to old_audit_table That is probably the fasted method you can do, even if you have to join the "new_col_value" from an extra helper-table with the correspondig id. Remeber, databases are born to join. You could also try to just update the whole table in one go, it is probably faster than you expect. just a thought Leo