Re: Incomplete freezing when truncating a relation during vacuum - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Incomplete freezing when truncating a relation during vacuum
Date
Msg-id 20131126232130.GK23284@alap2.anarazel.de
Whole thread Raw
In response to Incomplete freezing when truncating a relation during vacuum  (Andres Freund <andres@2ndquadrant.com>)
Responses Re: Incomplete freezing when truncating a relation during vacuum  (Heikki Linnakangas <hlinnakangas@vmware.com>)
List pgsql-hackers
On 2013-11-26 13:32:44 +0100, Andres Freund wrote:
> A longer period of staring revealed a likely reason, in lazy_vacuum_rel:
>     /* Do the vacuuming */
>     lazy_scan_heap(onerel, vacrelstats, Irel, nindexes, scan_all);
> ...
>     if (whatever)
>        lazy_truncate_heap(onerel, vacrelstats);
> ...
>     new_frozen_xid = FreezeLimit;
>     if (vacrelstats->scanned_pages < vacrelstats->rel_pages)
>         new_frozen_xid = InvalidTransactionId;
> but lazy_tuncate_heap() does, after it's finished truncating:
>     vacrelstats->rel_pages = new_rel_pages;
>
> Which means, we might consider a partial vacuum as a vacuum that has
> frozen all old rows if just enough pages have been truncated away.

repro.sql is a reproducer for the problem.

> This seems to be the case since
> b4b6923e03f4d29636a94f6f4cc2f5cf6298b8c8. I suggest we go back to using
> scan_all to determine whether we can set new_frozen_xid. That's a slight
> pessimization when we scan a relation fully without explicitly scanning
> it in its entirety, but given this isn't the first bug around
> scanned_pages/rel_pages I'd rather go that way. The aforementioned
> commit wasn't primarily concerned with that.
> Alternatively we could just compute new_frozen_xid et al before the
> lazy_truncate_heap.

I've gone for the latter in this preliminary patch. Not increasing
relfrozenxid after an initial data load seems like a bit of a shame.

I wonder if we should just do scan_all || vacrelstats->scanned_pages <
vacrelstats->rel_pages?

Greetings,

Andres Freund

--
 Andres Freund                       http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Attachment

pgsql-hackers by date:

Previous
From: Paul Ramsey
Date:
Subject: Re: Traffic jams in fn_extra
Next
From: Kevin Grittner
Date:
Subject: Re: [GENERAL] pg_upgrade ?deficiency