Re: Bug in autovacuum.c?

Bruce Momjian <bruce@momjian.us>

From: Bruce Momjian <bruce@momjian.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Alvaro Herrera <alvherre@commandprompt.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2011-03-31T20:35:01Z
Lists: pgsql-hackers
Robert Haas wrote:
> >> > The effect is to map max xid + 1 to max xid -
> >> > FirstNormalTransactionId(3) + 1, which makes the xid look like it is
> >> > going backwards, less than max xid --- not good.
> >>
> >> The XID space is *circular*.
> >
> > Right but you would think that as the xid moves forward, the caculation
> > of how far back to vacuum should move only forward. ?In this case,
> > incrementing the xid by one would cause the vacuum horizon to move
> > backward by two.
> 
> I don't see how that would happen.   The XID immediately preceding
> FirstNormalTransactionId is 2^32-1, and that's exactly what this
> calculation produces.

OK, let me see if I understand --- the caculation is below:

    xidForceLimit = recentXid - autovacuum_freeze_max_age;
    if (xidForceLimit < FirstNormalTransactionId)
        xidForceLimit -= FirstNormalTransactionId;

The values:

	xidForceLimit	Result
	---------------------------
	max_xid-2	max_xid-2
	max_xid-1	max_xid-1
	max_xid		max_xid
	0		max_xid-3	<- backward here
	1		max_xid-2
	2		max_xid-1
	3		3

With the -= change to =, we get:

	xidForceLimit	Result
	---------------------------
	max_xid-2	max_xid-2
	max_xid-1	max_xid-1
	max_xid		max_xid
	0		3
	1		3
	2		3
	3		3

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +