Re: How to make lazy VACUUM of one table run in several transactions ? - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: How to make lazy VACUUM of one table run in several transactions ?
Date
Msg-id 20050425124103.GB20404@dcc.uchile.cl
Whole thread Raw
In response to How to make lazy VACUUM of one table run in several transactions ?  (Hannu Krosing <hannu@tm.ee>)
Responses Re: How to make lazy VACUUM of one table run in several transactions ?
List pgsql-hackers
On Sun, Apr 24, 2005 at 12:02:37PM +0300, Hannu Krosing wrote:

> to check for some time/page_cnt limit after each heap page (near the
> start of main loop in lazy_scan_heap() ), and if it is reached then
> stop, clean up indexes, and return the blkno of next page needing to
> be vacuumed, and replacing the call to lazy_vacuum_rel(onerel,
> vacstmt); in vacuum.c with the following loop.
> 
>     next_page_to_vacuum = 0;
>     while (next_page_to_vacuum < RelationGetNumberOfBlocks(onerel)) {
>         StartTransactionCommand();
>         ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
> 
>         next_page_to_vacuum = lazy_vacuum_rel(onerel, vacstmt);
> 
>         CommitTransactionCommand();
>     }
> 
> Must some locks also be released an reaquired inside this loop, or is
> there something else I should keep in mind when trying to do this ?

There is "session lock" on the table.  You must release that.

However, after releasing and reacquiring that lock, all you know about
the table must be rechecked.  In particular the table can be dropped :-)
or truncated, or vacuumed by some other process; etc.  So you'd need to
start the vacuum "from scratch."  (I guess you'd skip the first N
pages.)

One thing to keep in mind is whether the Xmin calculations are right
after such a thing ... e.g. if you truncated the clog with the wrong
parameters, you could lose data.

-- 
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
"Doing what he did amounts to sticking his fingers under the hood of the
implementation; if he gets his fingers burnt, it's his problem."  (Tom Lane)


pgsql-hackers by date:

Previous
From: Jochem van Dieten
Date:
Subject: Re: possible TODO: read-only tables, select from indexes only.
Next
From: Tom Lane
Date:
Subject: Re: How to make lazy VACUUM of one table run in several transactions ?