mirror of
https://github.com/postgres/postgres.git
synced 2025-07-17 06:41:09 +03:00
Move the tuple freezing point in CLUSTER to a point further back in the past,
to avoid losing useful Xid information in not-so-old tuples. This makes CLUSTER behave the same as VACUUM as far a tuple-freezing behavior goes (though CLUSTER does not yet advance the table's relfrozenxid). While at it, move the actual freezing operation in rewriteheap.c to a more appropriate place, and document it thoroughly. This part of the patch from Tom Lane.
This commit is contained in:
@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.159 2007/04/08 01:26:28 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.160 2007/05/17 15:28:29 alvherre Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -29,6 +29,7 @@
|
||||
#include "catalog/namespace.h"
|
||||
#include "catalog/toasting.h"
|
||||
#include "commands/cluster.h"
|
||||
#include "commands/vacuum.h"
|
||||
#include "miscadmin.h"
|
||||
#include "storage/procarray.h"
|
||||
#include "utils/acl.h"
|
||||
@ -657,6 +658,7 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
|
||||
HeapTuple tuple;
|
||||
bool use_wal;
|
||||
TransactionId OldestXmin;
|
||||
TransactionId FreezeXid;
|
||||
RewriteState rwstate;
|
||||
|
||||
/*
|
||||
@ -688,11 +690,16 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
|
||||
/* use_wal off requires rd_targblock be initially invalid */
|
||||
Assert(NewHeap->rd_targblock == InvalidBlockNumber);
|
||||
|
||||
/* Get the cutoff xmin we'll use to weed out dead tuples */
|
||||
OldestXmin = GetOldestXmin(OldHeap->rd_rel->relisshared, true);
|
||||
/*
|
||||
* compute xids used to freeze and weed out dead tuples. We use -1
|
||||
* freeze_min_age to avoid having CLUSTER freeze tuples earlier than
|
||||
* a plain VACUUM would.
|
||||
*/
|
||||
vacuum_set_xid_limits(-1, OldHeap->rd_rel->relisshared,
|
||||
&OldestXmin, &FreezeXid);
|
||||
|
||||
/* Initialize the rewrite operation */
|
||||
rwstate = begin_heap_rewrite(NewHeap, OldestXmin, use_wal);
|
||||
rwstate = begin_heap_rewrite(NewHeap, OldestXmin, FreezeXid, use_wal);
|
||||
|
||||
/*
|
||||
* Scan through the OldHeap in OldIndex order and copy each tuple into the
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.350 2007/04/16 18:29:50 alvherre Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.351 2007/05/17 15:28:29 alvherre Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -566,7 +566,7 @@ get_rel_oids(List *relids, const RangeVar *vacrel, const char *stmttype)
|
||||
* vacuum_set_xid_limits() -- compute oldest-Xmin and freeze cutoff points
|
||||
*/
|
||||
void
|
||||
vacuum_set_xid_limits(VacuumStmt *vacstmt, bool sharedRel,
|
||||
vacuum_set_xid_limits(int freeze_min_age, bool sharedRel,
|
||||
TransactionId *oldestXmin,
|
||||
TransactionId *freezeLimit)
|
||||
{
|
||||
@ -588,12 +588,12 @@ vacuum_set_xid_limits(VacuumStmt *vacstmt, bool sharedRel,
|
||||
Assert(TransactionIdIsNormal(*oldestXmin));
|
||||
|
||||
/*
|
||||
* Determine the minimum freeze age to use: as specified in the vacstmt,
|
||||
* Determine the minimum freeze age to use: as specified by the caller,
|
||||
* or vacuum_freeze_min_age, but in any case not more than half
|
||||
* autovacuum_freeze_max_age, so that autovacuums to prevent XID
|
||||
* wraparound won't occur too frequently.
|
||||
*/
|
||||
freezemin = vacstmt->freeze_min_age;
|
||||
freezemin = freeze_min_age;
|
||||
if (freezemin < 0)
|
||||
freezemin = vacuum_freeze_min_age;
|
||||
freezemin = Min(freezemin, autovacuum_freeze_max_age / 2);
|
||||
@ -1154,7 +1154,7 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
|
||||
i;
|
||||
VRelStats *vacrelstats;
|
||||
|
||||
vacuum_set_xid_limits(vacstmt, onerel->rd_rel->relisshared,
|
||||
vacuum_set_xid_limits(vacstmt->freeze_min_age, onerel->rd_rel->relisshared,
|
||||
&OldestXmin, &FreezeLimit);
|
||||
|
||||
/*
|
||||
|
@ -36,7 +36,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.88 2007/04/30 03:23:48 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.89 2007/05/17 15:28:29 alvherre Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -158,7 +158,7 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
|
||||
else
|
||||
elevel = DEBUG2;
|
||||
|
||||
vacuum_set_xid_limits(vacstmt, onerel->rd_rel->relisshared,
|
||||
vacuum_set_xid_limits(vacstmt->freeze_min_age, onerel->rd_rel->relisshared,
|
||||
&OldestXmin, &FreezeLimit);
|
||||
|
||||
vacrelstats = (LVRelStats *) palloc0(sizeof(LVRelStats));
|
||||
|
Reference in New Issue
Block a user