Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id B0F7F1337B80 for ; Mon, 2 May 2011 01:00:49 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 36434-04 for ; Mon, 2 May 2011 04:00:31 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.8]) by mail.postgresql.org (Postfix) with ESMTP id 66E821337990 for ; Mon, 2 May 2011 01:00:31 -0300 (ADT) Received: from [192.168.1.6] (mail.highperformancepostgresql.com [71.179.240.8]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0M7Wjr-1Ptawr0Vgl-00xIvC; Mon, 02 May 2011 06:00:30 +0200 Message-ID: <4DBE2CB7.7020208@2ndQuadrant.com> Date: Mon, 02 May 2011 00:01:59 -0400 From: Greg Smith User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20110307 Icedove/3.0.11 MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: Re: Re: best practice for moving millions of rows to child table when setting up partitioning? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:bhFgFhsyp/+INDNg4CJ6PKpkXs8IDAriAxjrowghEP/ FJ1IEbccKOfKDE/WRfsvyKj2956pApLJPac62z0tlLEc+ArByK D4YgXvMtwSI+yyvn+7jKbNgoqAy1C5IzDPUWKBrThet5UvXkR1 CydRoB4lQiE2uGJQ47X0T3uhJGiVODqBt0JaXui6wP2YQRg/zr x1N++wmHxCa/OZlw/z0SKmnjw0/ja+PMz/gZdyli5o= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.585 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SARE_MILLIONSOF=0.315 X-Spam-Level: X-Archive-Number: 201105/4 X-Sequence-Number: 37441 On 04/27/2011 03:35 PM, Mark Stosberg wrote: > In particular, I wanted to check whether the UPDATE statement would > alter all the rows automatically, or if the underlying trigger would > cause all the rows processed a row at a time. > > It appears from my test that the result of the UPDATE was going to > appear all at once. I'm worried about the resource implications of > inserting mullions of rows all at once. > You can put a LIMIT on an UPDATE, same as any other type of query. No reason that style of migration must happen all at once, you can just target a smaller number of rows at a time and slowly siphon rows over to the children by iteration. I don't see anything inherently wrong with the approach you're proposing. CREATE INDEX CONCURRENTLY does something similar to the logic you've outlined--mark where data was inserted at, move over all older data, then just copy over the new rows at the end. The main downsides of that is complexity and the need for downtime to get an atomic swap to using the child tables. You can't add them to the parent until the original is gone, if you've inserted duplicate data into them. I'm not sure what all that complexity buys you, compared to just adding all the children, putting a limit on the UPDATE, and looping over that with some delay after each iteration until it's finished if you want to further control the rate. There's usually no reason you have to be in a rush to moving data over. Relying on the database's transactional scheme to avoid making any mistakes here--making it so a goof will ROLLBACK--and avoiding any need for downtime are normally higher priorities in a partition migration than making the move happen as fast as possible. -- Greg Smith 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us "PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books