Re: How to make lazy VACUUM of one table run in several transactions ?

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: How to make lazy VACUUM of one table run in several transactions ?
Дата
Msg-id 20050425124103.GB20404@dcc.uchile.cl
обсуждение исходный текст
Ответ на How to make lazy VACUUM of one table run in several transactions ?  (Hannu Krosing <hannu@tm.ee>)
Ответы Re: How to make lazy VACUUM of one table run in several transactions ?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Jochem van Dieten
Дата:
Сообщение: Re: possible TODO: read-only tables, select from indexes only.
Следующее
От: Tom Lane
Дата:
Сообщение: Re: How to make lazy VACUUM of one table run in several transactions ?