Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 4012AB5DC0F for ; Mon, 27 Jun 2011 12:02:31 -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 63146-04 for ; Mon, 27 Jun 2011 15:02:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from server515.appriver.com (server515j.exghost.com [72.32.253.74]) by mail.postgresql.org (Postfix) with ESMTP id 2E6B4B5DCC2 for ; Mon, 27 Jun 2011 12:01:56 -0300 (ADT) X-Note-AR-ScanTimeLocal: 6/27/2011 9:58:59 AM X-Policy: GLOBAL - riskcontrollimited.com X-Primary: harry.mantheakis@riskcontrollimited.com X-Note: This Email was scanned by AppRiver SecureTide X-ALLOW: @riskcontrollimited.com ALLOWED X-Virus-Scan: V- X-Note: Spam Tests Failed: X-Country-Path: PRIVATE->PRIVATE->UNITED STATES->UNITED STATES X-Note-Sending-IP: 72.32.49.28 X-Note-Reverse-DNS: X-Note-WHTLIST: harry.mantheakis@riskcontrollimited.com X-Note: User Rule Hits: X-Note: Global Rule Hits: G200 G201 G202 G203 G207 G208 G219 G309 X-Note: Encrypt Rule Hits: X-Note: Mail Class: ALLOWEDSENDER X-Note: Headers Injected Received: from [72.32.49.28] (HELO FE4.exchange.rackspace.com) by server515.appriver.com (CommuniGate Pro SMTP 5.4.1c) with ESMTP id 278154160 for pgsql-performance@postgresql.org; Mon, 27 Jun 2011 09:58:59 -0500 Received: from FE4.exchange.rackspace.com ([10.244.5.57]) by FE4.exchange.rackspace.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 27 Jun 2011 10:01:54 -0500 Received: from [192.168.20.134] ([87.194.70.108]) by FE4.exchange.rackspace.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 27 Jun 2011 10:01:54 -0500 Message-ID: <4E089B6A.4000208@riskcontrollimited.com> Date: Mon, 27 Jun 2011 16:02:02 +0100 From: Harry Mantheakis User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Long Running Update - My Solution References: <4E035649.20007@riskcontrollimited.com> In-Reply-To: <4E035649.20007@riskcontrollimited.com> X-TagToolbar-Keys: D20110627160202509 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 27 Jun 2011 15:01:54.0517 (UTC) FILETIME=[27168050:01CC34DB] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201106/244 X-Sequence-Number: 44177 I am glad to report that the 'salami-slice' approach worked nicely - all done in about 2.5 hours. Instead of using an all-in-one-go statement, we executed 800 statements, each updating 100,000 records. On average it tool about 10-seconds for each statement to return. This is "thinking out of the box" solution, which others might not be able to emulate. The mystery remains, for me: why updating 100,000 records could complete in as quickly as 5 seconds, whereas an attempt to update a million records was still running after 25 minutes before we killed it? One thing remains crystal clear: I love Postgresql :-) Kind regards Harry Mantheakis London, UK On 23/06/2011 16:05, Harry Mantheakis wrote: > Hello > > I am attempting to run an update statement that copies two fields from > one table to another: > > > UPDATE > table_A > SET > ( > field_1 > , field_2 > ) = ( > table_B.field_1 > , table_B.field_2 > ) > FROM > table_B > WHERE > table_B.id = table_A.id > ; > > > Table "table_B" contains almost 75 million records, with IDs that > match those in "table_A". > > Both "field_1" and "field_2" are DOUBLE PRECISION. The ID fields are > SERIAL primary-key integers in both tables. > > I tested (the logic of) this statement with a very small sample, and > it worked correctly. > > The database runs on a dedicated Debian server in our office. > > I called both VACUUM and ANALYZE on the databased before invoking this > statement. > > The statement has been running for 18+ hours so far. > > TOP, FREE and VMSTAT utilities indicate that only about half of the > 6GB of memory is being used, so I have no reason to believe that the > server is struggling. > > My question is: can I reasonably expect a statement like this to > complete with such a large data-set, even if it takes several days? > > We do not mind waiting, but obviously we do not want to wait > unnecessarily. > > Many thanks. > > Harry Mantheakis > London, UK > > >