Skip site navigation (1) Skip section navigation (2)

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

From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Hannu Krosing <hannu(at)tm(dot)ee>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: How to make lazy VACUUM of one table run in several transactions ?
Date: 2005-04-25 12:41:03
Message-ID: 20050425124103.GB20404@dcc.uchile.cl (view raw or flat)
Thread:
Lists: 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[(at)]dcc(dot)uchile(dot)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)

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2005-04-25 15:11:45
Subject: Re: How to make lazy VACUUM of one table run in several transactions ?
Previous:From: Jochem van DietenDate: 2005-04-25 11:43:07
Subject: Re: possible TODO: read-only tables, select from indexes only.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group