Re: [GENERAL] efficiently migrating 'old' data from one table to another - Mailing list pgsql-general

From David G. Johnston
Subject Re: [GENERAL] efficiently migrating 'old' data from one table to another
Date
Msg-id CAKFQuwbk4KgA4y+uNRJnB=LZqgrT1uKFOF0WMNnZMa3B53S4Qg@mail.gmail.com
Whole thread Raw
In response to Re: [GENERAL] efficiently migrating 'old' data from one table toanother  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
On Thu, Jan 12, 2017 at 2:45 PM, Adrian Klaver <adrian.klaver@aklaver.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.

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] efficiently migrating 'old' data from one table toanother
Next
From: Merlin Moncure
Date:
Subject: Re: [GENERAL] efficiently migrating 'old' data from one table to another