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

lazy_truncate_heap()

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: lazy_truncate_heap()
Date: 2008-12-31 18:21:34
Message-ID: 1230747694.4032.72.camel@ebony.2ndQuadrant (view raw or flat)
Thread:
Lists: pgsql-hackers
While watching WAL records float by I noticed some AccessExclusiveLocks
occurring unnecessarily during VACUUMs.

This is caused by lines 186-189 in lazy_vacuum_rel(), vacuumlazy.c

  possibly_freeable = vacrelstats->rel_pages - 	
				vacrelstats->nonempty_pages;
  if (possibly_freeable >= REL_TRUNCATE_MINIMUM ||
      possibly_freeable >= vacrelstats->rel_pages /
					 REL_TRUNCATE_FRACTION)
		lazy_truncate_heap(onerel, vacrelstats);

If you look closely you'll see that if rel_pages is small then we will
attempt to truncate the heap even if possibly_freeable == 0. 

While looking at this some more, I notice there is another bug. When
VACUUM has nothing at all to do, then it appears that
vacrelstats->nonempty_pages is zero, so that possibly_freeable is always
set to vacrelstats->rel_pages. vacrelstats->nonempty_pages doesn't
appear to be used anywhere else, so nobody notices it is wrongly set.

Both of these bugs are minor, but the effect of either/both of them is
to cause more AccessExclusiveLocks than we might expect. 

For Hot Standby this means that many VACUUMs take AccessExclusiveLocks
on relations, which would potentially lead to having queries cancelled
for no reason at all.

Does anybody think any of the above is intentional? Can I fix?

-- 
 Simon Riggs           www.2ndQuadrant.com
 PostgreSQL Training, Services and Support


Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2008-12-31 18:25:34
Subject: Re: version() output vs. 32/64 bits
Previous:From: Pavel StehuleDate: 2008-12-31 18:13:03
Subject: Re: version() output vs. 32/64 bits

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