Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 046E01337C25 for ; Wed, 27 Apr 2011 17:04:01 -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 97015-02 for ; Wed, 27 Apr 2011 20:03:52 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from web39708.mail.mud.yahoo.com (web39708.mail.mud.yahoo.com [209.191.106.54]) by mail.postgresql.org (Postfix) with SMTP id 8AB951338011 for ; Wed, 27 Apr 2011 16:37:49 -0300 (ADT) Received: (qmail 83558 invoked by uid 60001); 27 Apr 2011 19:37:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1303933068; bh=IMirH/zja5wHtPgCMw3gt3trF5c3UAnlXlEIC1GzraQ=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=AJJrY+oAsOTTpR6Q4CbBSu+Bxj9ZTEWzkFDVfcjgUniqoxliIZg393C0Dv1+pZ2uCbbkg2IKjdeYF+5cgabuf+Lhuw4j6btLpI2kYTqs6NXXvIsLTzh9ykztVMLMKH//5Z0vJQ1KdCmJ8jHgH3IeewwxceF7LhFlUDd2UG1CP8E= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=3l+j5x721qpVKrcfzj1qxAmMDJLvARqJp6mKP9+4JjRjIDx4m7fnuo+N3yuWAQxf6Wh7ldyFguYteF4Zy8aSsiK1rIuAaeDXNt56GHKCUWjZ5HU4O/97eNrd5qb7FcWgoeLL+is9ddZuC+5CY+IE3/cow75ffCzdFLit2Lv8Fks=; Message-ID: <659395.83416.qm@web39708.mail.mud.yahoo.com> X-YMail-OSG: K14HyoYVM1nlIQY6OwQfc5yUXwL3oM9iN0Skr1Um34Nk_Uz xon2qyra0qREbiuWo0JP10o3F1WkNx72VLA6W2YHvMZzDHYS1D5NspVOOGcM OYUiPs6gH1o1zBSZgOudQMQLoiSxJMUSWnR02r0VFEZnFix0k2g0EMvKJBDZ FfXsGwZR0O1Dohh.nePfkNOANPIwgH3_5taipgp8lf2u3mI6PNVZ5hl6gOXe Pu_jGAbrA2jco4pGYuKbAkIlx4dX7pGMo.9AP8KeTcyvyVOh_IL9Wlnfu_k1 RzJgZN1_GHvGqWNKqINJLhWs2xvrakF7GQSyeGyjXB0VRc8PMKtAFTZN5skF hgPaC.5KSiRL7Yyf.4Be04ldznMz4.SgFGFo3xAGalX7cbX4wSUIP5dF2_Ix JTNdDqcYe82zC Received: from [64.126.29.122] by web39708.mail.mud.yahoo.com via HTTP; Wed, 27 Apr 2011 12:37:48 PDT X-Mailer: YahooMailClassic/12.0.2 YahooMailWebService/0.8.110.299900 Date: Wed, 27 Apr 2011 12:37:48 -0700 (PDT) From: Bob Lunney Subject: Re: best practice for moving millions of rows to child table when setting up partitioning? To: pgsql-admin@postgresql.org, Mark Stosberg In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.593 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RFC_ABUSE_POST=0.001, SARE_MILLIONSOF=0.315, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/241 X-Sequence-Number: 37422 Mark,=0A=0AComments inline below for items 2 and 3. What you are planning = should work like a charm.=0A=0ABob Lunney=0A=0A--- On Wed, 4/27/11, Mark St= osberg wrote:=0A=0A> From: Mark Stosberg =0A> Subject: [ADMIN] best practice for moving millions of rows = to child table when setting up partitioning?=0A> To: pgsql-admin@postgresql= .org=0A> Date: Wednesday, April 27, 2011, 10:48 AM=0A> =0A> Hello,=0A> =0A>= I'm working on moving a table with over 30 million to rows=0A> to be=0A> p= artitioned. The table seeing several inserts per second.=0A> It's=0A> essen= tially an activity log that only sees insert activity=0A> and is=0A> lightl= y used for reporting, such that queries against it=0A> can safely be=0A> di= sabled during a transition.=0A> =0A> I'm looking for recommendations for a = way to do this that=0A> will be least=0A> disruptive to the flow of inserts= statements that will=0A> continue to=0A> stream in.=0A> =0A> Here's the pl= an which seems best to me at the moment. Is it=0A> is=0A> reasonable?=0A> = =0A> 1. Handling creating the empty/future partitions is easy. I=0A> have t= he=0A> code for this done already, and will make several=0A> partitions in = advance=0A> of needing them.=0A> =0A> 2. To create the partitions that shou= ld have data moved=0A> from the parent,=0A> I'm thinking of creating them, = and then before they are=0A> "live",=0A> using INSERT ... SELECT to fill th= em with data from the=0A> parent table.=0A> I'll run the INSERT first, and = then add their indexes.=0A> =0A=0AUse "create table as select ..." (CTAS) i= nstead of creating the table, then inserting. Since the table is created a= nd populated atomically there is no need to log the inserts in WAL, and the= operation is much faster.=0A=0A> 3. I will then install the trigger to red= irect the inserts=0A> to the child=0A> table.=0A> =0A=0AIf possible, its be= tter to have the code simply do inserts directly into the child table - aft= er all, if the partitioning is based on date, both the code and database kn= ow the date, so the code knows to which child table it should write at any = given moment.=0A=0A> 4. There will still be a relatively small number of ne= w=0A> rows from the=0A> parent table to be deal with that came in after the= INSERT=0A> from #2 was=0A> started, so a final INSERT .. SELECT statement = will be made=0A> to copy the=0A> remaining rows.=0A> =0A> 5. Finally, I'll = drop the indexes on the parent table and=0A> truncate it.=0A> =0A> Thanks f= or advice here. If there's a tutorial out there=0A> about this that=0A> I'v= e missed, I'm happy to review it instead having it=0A> rehashed here.=0A> = =0A> Thanks for the help!=0A> =0A> =A0 =A0 Mark=0A> =0A> =0A> -- =0A> Sent = via pgsql-admin mailing list (pgsql-admin@postgresql.org)=0A> To make chang= es to your subscription:=0A> http://www.postgresql.org/mailpref/pgsql-admin= =0A>