Re: Need to update all my 60 million rows at once without transactional integrity - Mailing list pgsql-general

From Pavan Deolasee
Subject Re: Need to update all my 60 million rows at once without transactional integrity
Date
Msg-id 2e78013d0804230248o58740a66l81363398758d6f37@mail.gmail.com
Whole thread Raw
In response to Re: Need to update all my 60 million rows at once without transactional integrity  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List pgsql-general
On Wed, Apr 23, 2008 at 1:52 PM, A. Kretschmer
<andreas.kretschmer@schollglas.com> wrote:
> am  Mon, dem 21.04.2008, um  0:19:34 +0200 mailte christian_behrens@gmx.net folgendes:
>
>  >
>  > If I do a batched loop like this:
>  > UPDATE table SET flag=0 where id>=0 and id <200;
>  > UPDATE table SET flag=0 where id>=200 and id <400;
>  > UPDATE table SET flag=0 where id>=400 and id <600;
>
>
>  Don't forget to VACUUM after every Update...
>

VACUUMing a large table so often could a problem. But if disk space is
the only limitation and you don't care much about IO and CPU usage,
its not a bad idea.

>
>  >
>  > Is there any other way to go?
>
>  Update to 8.3 and profit from the new HOT feature (wild guess: there is
>  no index on this flag-column)
>

HOT may not help a lot in this case. HOT needs free space in the same
block to put the new version. It can recycle the previously updated
rows and thus free up space, but only if the rows were updated in an
older (now committed) transaction. Now, if you are doing batch
updates, then there is a chance that HOT may be able recycle rows
updated in one of the previous batches. But if the updates are
happening sequential, then the blocks which were updated previously
would never be touched again and hence no space will be freed.

If you are updating one row at a time (in a separate transaction) or
if the batch updates are kind of scattered, then HOT can reuse the
dead tuples and limit the bloat.

Thanks,
Pavan

--
Pavan Deolasee
EnterpriseDB http://www.enterprisedb.com

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: initdb in 8.3
Next
From: Pascal Cohen
Date:
Subject: Deny creation of tables for a user