diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/backend/commands/vacuumlazy.c | 22 | 
1 files changed, 18 insertions, 4 deletions
| diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c index 55889bf9a7c..78bf4212c06 100644 --- a/src/backend/commands/vacuumlazy.c +++ b/src/backend/commands/vacuumlazy.c @@ -166,7 +166,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,  	BlockNumber possibly_freeable;  	PGRUsage	ru0;  	TimestampTz starttime = 0; -	bool		scan_all; +	bool		scan_all;		/* should we scan all pages? */ +	bool		scanned_all;	/* did we actually scan all pages? */  	TransactionId freezeTableLimit;  	BlockNumber new_rel_pages;  	double		new_rel_tuples; @@ -210,6 +211,21 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,  	vac_close_indexes(nindexes, Irel, NoLock);  	/* +	 * Compute whether we actually scanned the whole relation. If we did, we +	 * can adjust relfrozenxid. +	 * +	 * NB: We need to check this before truncating the relation, because that +	 * will change ->rel_pages. +	 */ +	if (vacrelstats->scanned_pages < vacrelstats->rel_pages) +	{ +		Assert(!scan_all); +		scanned_all = false; +	} +	else +		scanned_all = true; + +	/*  	 * Optionally truncate the relation.  	 *  	 * Don't even think about it unless we have a shot at releasing a goodly @@ -245,9 +261,7 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,  		new_rel_tuples = vacrelstats->old_rel_tuples;  	} -	new_frozen_xid = FreezeLimit; -	if (vacrelstats->scanned_pages < vacrelstats->rel_pages) -		new_frozen_xid = InvalidTransactionId; +	new_frozen_xid = scanned_all ? FreezeLimit : InvalidTransactionId;  	vac_update_relstats(onerel,  						new_rel_pages, new_rel_tuples, | 
