Re: Re: best practice for moving millions of rows to child table when setting up partitioning? - Mailing list pgsql-admin

From Scott Marlowe
Subject Re: Re: best practice for moving millions of rows to child table when setting up partitioning?
Date
Msg-id BANLkTimihm0e4DewUxkSZ_YNs4wkK8VpZA@mail.gmail.com
Whole thread Raw
In response to Re: best practice for moving millions of rows to child table when setting up partitioning?  (Mark Stosberg <mark@summersault.com>)
Responses Re: Re: best practice for moving millions of rows to child table when setting up partitioning?  (Scott Marlowe <scott.marlowe@gmail.com>)
List pgsql-admin
I had a similar problem about a year ago,  The parent table had about
1.5B rows each with a unique ID from a bigserial.  My approach was to
create all the child tables needed for the past and the next month or
so.  Then, I simple did something like:

begin;
insert into table select * from only table where id between 1 and 10000000;
delete from only table where id between 1 and 10000000;
-- first few times check to make sure it's working of course
commit;
begin;
insert into table select * from only table where id between 10000001
and 20000000;
delete from only table where id between 10000001 and 20000000;
commit;

and so on.  New entries were already going into the child tables as
they showed up, old entries were migrating 10M rows at a time.  This
kept the moves small enough so as not to run the machine out of any
resource involved in moving 1.5B rows at once.

pgsql-admin by date:

Previous
From: "ktm@rice.edu"
Date:
Subject: Re: Re: best practice for moving millions of rows to child table when setting up partitioning?
Next
From: Scott Marlowe
Date:
Subject: Re: Re: best practice for moving millions of rows to child table when setting up partitioning?