Re: efficiently migrating 'old' data from one table to another

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Jonathan Vanasco <postgres(at)2xlp(dot)com>, pgsql-general general <pgsql-general(at)postgresql(dot)org>
Subject: Re: efficiently migrating 'old' data from one table to another
Date: 2017-01-12 22:50:53
Message-ID: CAKFQuwbk4KgA4y+uNRJnB=LZqgrT1uKFOF0WMNnZMa3B53S4Qg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jan 12, 2017 at 2:45 PM, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

>
> > so our migration is then based on that `is_migrate` column:
> >
> > BEGIN;
> > UPDATE table_a__live SET is_migrate = TRUE WHERE record_timestamp
> < transaction_timestamp() AT TIME ZONE 'UTC' - INTERVAL '1 month';
> > INSERT INTO table_a__archive (column_1, column_2,
> record_timestamp) SELECT column_1, column_2, record_timestamp FROM
> table_a__live WHERE is_migrate IS TRUE;
> > DELETE FROM table_a__live WHERE is_migrate IS TRUE;
> > COMMIT;
> >
> > The inserts & deletes are blazing fast, but the UPDATE is a bit slow
> from postgres re-writing all the rows.
>
> Maybe I am missing something, but why do the UPDATE?
>

​Not to mention doubling the amount of I/O vacuum is going to chew up.

​David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2017-01-12 22:52:05 Re: efficiently migrating 'old' data from one table to another
Previous Message Adrian Klaver 2017-01-12 21:45:32 Re: efficiently migrating 'old' data from one table to another