Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2BFCC1337B92 for ; Wed, 27 Apr 2011 11:48:58 -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 83629-06 for ; Wed, 27 Apr 2011 14:48:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 1B6701337B93 for ; Wed, 27 Apr 2011 11:48:45 -0300 (ADT) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QF62k-0007Sk-Jw for pgsql-admin@postgresql.org; Wed, 27 Apr 2011 16:48:42 +0200 Received: from frigga.summersault.com ([12.161.105.138]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 27 Apr 2011 16:48:42 +0200 Received: from mark by frigga.summersault.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 27 Apr 2011 16:48:42 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-admin@postgresql.org From: Mark Stosberg Subject: best practice for moving millions of rows to child table when setting up partitioning? Date: Wed, 27 Apr 2011 10:48:26 -0400 Lines: 41 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: frigga.summersault.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 X-Enigmail-Version: 1.1.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.595 tagged_above=-10 required=5 tests=BAYES_00=-1.9, SARE_MILLIONSOF=0.315, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/236 X-Sequence-Number: 37417 Hello, I'm working on moving a table with over 30 million to rows to be partitioned. The table seeing several inserts per second. It's essentially an activity log that only sees insert activity and is lightly used for reporting, such that queries against it can safely be disabled during a transition. I'm looking for recommendations for a way to do this that will be least disruptive to the flow of inserts statements that will continue to stream in. Here's the plan which seems best to me at the moment. Is it is reasonable? 1. Handling creating the empty/future partitions is easy. I have the code for this done already, and will make several partitions in advance of needing them. 2. To create the partitions that should have data moved from the parent, I'm thinking of creating them, and then before they are "live", using INSERT ... SELECT to fill them with data from the parent table. I'll run the INSERT first, and then add their indexes. 3. I will then install the trigger to redirect the inserts to the child table. 4. There will still be a relatively small number of new rows from the parent table to be deal with that came in after the INSERT from #2 was started, so a final INSERT .. SELECT statement will be made to copy the remaining rows. 5. Finally, I'll drop the indexes on the parent table and truncate it. Thanks for advice here. If there's a tutorial out there about this that I've missed, I'm happy to review it instead having it rehashed here. Thanks for the help! Mark