Re: full vacuum of a very large table

From: Bob Lunney <bob_lunney(at)yahoo(dot)com>
To: pgsql-admin(at)postgresql(dot)org, Nic Chidu <nic(at)chidu(dot)net>
Subject: Re: full vacuum of a very large table
Date: 2011-03-29 16:38:20
Message-ID: 967268.12623.qm@web39705.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin


--- On Tue, 3/29/11, Nic Chidu <nic(at)chidu(dot)net> wrote:

> From: Nic Chidu <nic(at)chidu(dot)net>
> Subject: [ADMIN] full vacuum of a very large table
> To: pgsql-admin(at)postgresql(dot)org
> Date: Tuesday, March 29, 2011, 11:56 AM
> Got a situation where a 130 mil rows
> (137GB) table needs to be brought down in size to  10
> mil records (most recent)
> with the least amount of downtime.
>
> Doing a full vacuum would be faster on:
> - 120 mil rows deleted and 10 mil active (delete most of
> them then full vacuum)
> - 10 mil deleted and 120 mil active. (delete small batches
> and full vacuum after each delete).
>
> Any other suggestions?
>
> Thanks,
>
> Nic
>
> --

Nic,

Since you know the where clause to delete the 120 mil rows why not use the converse of that to select the 10 mil rows to retain into another table, then drop the original table? No vacuum required!

Be sure to use the "create table as select..." syntax to avoid WAL during creation of the new table, and use a transaction to drop the original table and rename the new one. That way users will be querying the original table right up until the switch over, when they will start using the new table.

Foreign keys and other constraints may complicate things a bit, so check those out first. Also, don't forget to index and analyze the new table before the switch over.

Good luck!

Bob Lunney

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Shrinivas Devarkonda 2011-03-29 16:38:31 Re: full vacuum of a very large table
Previous Message Steve Crawford 2011-03-29 16:33:03 Re: full vacuum of a very large table