Re: Table maintenance: order of operations important? - Mailing list pgsql-admin

From Tom Lane
Subject Re: Table maintenance: order of operations important?
Date
Msg-id 3030.1085075532@sss.pgh.pa.us
Whole thread Raw
In response to Table maintenance: order of operations important?  (Jeff Boes <mur@qtm.net>)
Responses Re: Table maintenance: order of operations important?
List pgsql-admin
Jeff Boes <mur@qtm.net> writes:
>    DELETE FROM foo WHERE date_expires < now();
>    VACUUM ANALYZE foo;
>    CLUSTER foo;
>    REINDEX TABLE foo;

> How would you choose to order these (under 7.4.x) for fastest
> turn-around? Does it matter?

If you are going to CLUSTER then the VACUUM and the REINDEX are both
utterly redundant.  The ANALYZE is still useful but should be done after
CLUSTER since its physical-order-correlation stats will be quite wrong
if done beforehand.  In other words there is only one sane way to do
this and it is

    DELETE FROM foo WHERE date_expires < now();
    CLUSTER foo;
    ANALYZE foo;

You could possibly make a case for

    DELETE FROM foo WHERE date_expires < now();
    CLUSTER foo;
    VACUUM ANALYZE foo;

The VACUUM won't do anything useful in terms of reclaiming space (there
being none to reclaim just after a CLUSTER) but it would ensure that all
rows in the table are marked as committed-good, rather than leaving that
work to be done by the first transaction that happens to hit each row.

            regards, tom lane

pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: cannot connect to postgres db, strange error!
Next
From: Kris Kiger
Date:
Subject: Clustering Postgres