Re: Incomplete freezing when truncating a relation during vacuum

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Incomplete freezing when truncating a relation during vacuum
Date: 2013-11-26 23:21:30
Message-ID: 20131126232130.GK23284@alap2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
repro.sql text/plain 1.4 KB
0001-Don-t-sometimes-incorrectly-increase-relfrozenxid-in.patch text/x-patch 2.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2013-11-26 23:25:44 Re: [GENERAL] pg_upgrade ?deficiency
Previous Message Paul Ramsey 2013-11-26 23:15:42 Re: Traffic jams in fn_extra