Simplify vacuum_set_xid_limits() signature.
Pass VACUUM parameters (VacuumParams state) to vacuum_set_xid_limits() directly, rather than passing most individual VacuumParams fields as separate arguments. Also make vacuum_set_xid_limits() output parameter symbol names match those used by its vacuumlazy.c caller. Author: Peter Geoghegan <pg@bowt.ie> Discussion: https://postgr.es/m/CAH2-Wz=TE7gW5DgSahDkf0UEZigFGAoHNNN6EvSrdzC=Kn+hrA@mail.gmail.com
This commit is contained in:
parent
02d647bbf0
commit
b6074846ce
@ -360,12 +360,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
|
|||||||
* an aggressive VACUUM then lazy_scan_heap cannot leave behind unfrozen
|
* an aggressive VACUUM then lazy_scan_heap cannot leave behind unfrozen
|
||||||
* XIDs < FreezeLimit (all MXIDs < MultiXactCutoff also need to go away).
|
* XIDs < FreezeLimit (all MXIDs < MultiXactCutoff also need to go away).
|
||||||
*/
|
*/
|
||||||
aggressive = vacuum_set_xid_limits(rel,
|
aggressive = vacuum_set_xid_limits(rel, params, &OldestXmin, &OldestMxact,
|
||||||
params->freeze_min_age,
|
|
||||||
params->multixact_freeze_min_age,
|
|
||||||
params->freeze_table_age,
|
|
||||||
params->multixact_freeze_table_age,
|
|
||||||
&OldestXmin, &OldestMxact,
|
|
||||||
&FreezeLimit, &MultiXactCutoff);
|
&FreezeLimit, &MultiXactCutoff);
|
||||||
|
|
||||||
skipwithvm = true;
|
skipwithvm = true;
|
||||||
|
@ -823,6 +823,7 @@ copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
|
|||||||
Form_pg_class relform;
|
Form_pg_class relform;
|
||||||
TupleDesc oldTupDesc PG_USED_FOR_ASSERTS_ONLY;
|
TupleDesc oldTupDesc PG_USED_FOR_ASSERTS_ONLY;
|
||||||
TupleDesc newTupDesc PG_USED_FOR_ASSERTS_ONLY;
|
TupleDesc newTupDesc PG_USED_FOR_ASSERTS_ONLY;
|
||||||
|
VacuumParams params;
|
||||||
TransactionId OldestXmin,
|
TransactionId OldestXmin,
|
||||||
FreezeXid;
|
FreezeXid;
|
||||||
MultiXactId OldestMxact,
|
MultiXactId OldestMxact,
|
||||||
@ -914,7 +915,8 @@ copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
|
|||||||
* Since we're going to rewrite the whole table anyway, there's no reason
|
* Since we're going to rewrite the whole table anyway, there's no reason
|
||||||
* not to be aggressive about this.
|
* not to be aggressive about this.
|
||||||
*/
|
*/
|
||||||
vacuum_set_xid_limits(OldHeap, 0, 0, 0, 0, &OldestXmin, &OldestMxact,
|
memset(¶ms, 0, sizeof(VacuumParams));
|
||||||
|
vacuum_set_xid_limits(OldHeap, ¶ms, &OldestXmin, &OldestMxact,
|
||||||
&FreezeXid, &MultiXactCutoff);
|
&FreezeXid, &MultiXactCutoff);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -929,51 +929,55 @@ get_all_vacuum_rels(int options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vacuum_set_xid_limits() -- compute oldestXmin and freeze cutoff points
|
* vacuum_set_xid_limits() -- compute OldestXmin and freeze cutoff points
|
||||||
*
|
*
|
||||||
* Input parameters are the target relation, applicable freeze age settings.
|
* The target relation and VACUUM parameters are our inputs.
|
||||||
*
|
*
|
||||||
* The output parameters are:
|
* Our output parameters are:
|
||||||
* - oldestXmin is the Xid below which tuples deleted by any xact (that
|
* - OldestXmin is the Xid below which tuples deleted by any xact (that
|
||||||
* committed) should be considered DEAD, not just RECENTLY_DEAD.
|
* committed) should be considered DEAD, not just RECENTLY_DEAD.
|
||||||
* - oldestMxact is the Mxid below which MultiXacts are definitely not
|
* - OldestMxact is the Mxid below which MultiXacts are definitely not
|
||||||
* seen as visible by any running transaction.
|
* seen as visible by any running transaction.
|
||||||
* - freezeLimit is the Xid below which all Xids are definitely replaced by
|
* - FreezeLimit is the Xid below which all Xids are definitely frozen or
|
||||||
* FrozenTransactionId during aggressive vacuums.
|
* removed during aggressive vacuums.
|
||||||
* - multiXactCutoff is the value below which all MultiXactIds are definitely
|
* - MultiXactCutoff is the value below which all MultiXactIds are definitely
|
||||||
* removed from Xmax during aggressive vacuums.
|
* removed from Xmax during aggressive vacuums.
|
||||||
*
|
*
|
||||||
* Return value indicates if vacuumlazy.c caller should make its VACUUM
|
* Return value indicates if vacuumlazy.c caller should make its VACUUM
|
||||||
* operation aggressive. An aggressive VACUUM must advance relfrozenxid up to
|
* operation aggressive. An aggressive VACUUM must advance relfrozenxid up to
|
||||||
* FreezeLimit (at a minimum), and relminmxid up to multiXactCutoff (at a
|
* FreezeLimit (at a minimum), and relminmxid up to MultiXactCutoff (at a
|
||||||
* minimum).
|
* minimum).
|
||||||
*
|
*
|
||||||
* oldestXmin and oldestMxact are the most recent values that can ever be
|
* OldestXmin and OldestMxact are the most recent values that can ever be
|
||||||
* passed to vac_update_relstats() as frozenxid and minmulti arguments by our
|
* passed to vac_update_relstats() as frozenxid and minmulti arguments by our
|
||||||
* vacuumlazy.c caller later on. These values should be passed when it turns
|
* vacuumlazy.c caller later on. These values should be passed when it turns
|
||||||
* out that VACUUM will leave no unfrozen XIDs/MXIDs behind in the table.
|
* out that VACUUM will leave no unfrozen XIDs/MXIDs behind in the table.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
vacuum_set_xid_limits(Relation rel,
|
vacuum_set_xid_limits(Relation rel, const VacuumParams *params,
|
||||||
int freeze_min_age,
|
TransactionId *OldestXmin, MultiXactId *OldestMxact,
|
||||||
int multixact_freeze_min_age,
|
TransactionId *FreezeLimit, MultiXactId *MultiXactCutoff)
|
||||||
int freeze_table_age,
|
|
||||||
int multixact_freeze_table_age,
|
|
||||||
TransactionId *oldestXmin,
|
|
||||||
MultiXactId *oldestMxact,
|
|
||||||
TransactionId *freezeLimit,
|
|
||||||
MultiXactId *multiXactCutoff)
|
|
||||||
{
|
{
|
||||||
|
int freeze_min_age,
|
||||||
|
multixact_freeze_min_age,
|
||||||
|
freeze_table_age,
|
||||||
|
multixact_freeze_table_age,
|
||||||
|
effective_multixact_freeze_max_age;
|
||||||
TransactionId nextXID,
|
TransactionId nextXID,
|
||||||
safeOldestXmin,
|
safeOldestXmin,
|
||||||
aggressiveXIDCutoff;
|
aggressiveXIDCutoff;
|
||||||
MultiXactId nextMXID,
|
MultiXactId nextMXID,
|
||||||
safeOldestMxact,
|
safeOldestMxact,
|
||||||
aggressiveMXIDCutoff;
|
aggressiveMXIDCutoff;
|
||||||
int effective_multixact_freeze_max_age;
|
|
||||||
|
/* Use mutable copies of freeze age parameters */
|
||||||
|
freeze_min_age = params->freeze_min_age;
|
||||||
|
multixact_freeze_min_age = params->multixact_freeze_min_age;
|
||||||
|
freeze_table_age = params->freeze_table_age;
|
||||||
|
multixact_freeze_table_age = params->multixact_freeze_table_age;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Acquire oldestXmin.
|
* Acquire OldestXmin.
|
||||||
*
|
*
|
||||||
* We can always ignore processes running lazy vacuum. This is because we
|
* We can always ignore processes running lazy vacuum. This is because we
|
||||||
* use these values only for deciding which tuples we must keep in the
|
* use these values only for deciding which tuples we must keep in the
|
||||||
@ -983,14 +987,14 @@ vacuum_set_xid_limits(Relation rel,
|
|||||||
* that only one vacuum process can be working on a particular table at
|
* that only one vacuum process can be working on a particular table at
|
||||||
* any time, and that each vacuum is always an independent transaction.
|
* any time, and that each vacuum is always an independent transaction.
|
||||||
*/
|
*/
|
||||||
*oldestXmin = GetOldestNonRemovableTransactionId(rel);
|
*OldestXmin = GetOldestNonRemovableTransactionId(rel);
|
||||||
|
|
||||||
if (OldSnapshotThresholdActive())
|
if (OldSnapshotThresholdActive())
|
||||||
{
|
{
|
||||||
TransactionId limit_xmin;
|
TransactionId limit_xmin;
|
||||||
TimestampTz limit_ts;
|
TimestampTz limit_ts;
|
||||||
|
|
||||||
if (TransactionIdLimitedForOldSnapshots(*oldestXmin, rel,
|
if (TransactionIdLimitedForOldSnapshots(*OldestXmin, rel,
|
||||||
&limit_xmin, &limit_ts))
|
&limit_xmin, &limit_ts))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -1000,15 +1004,15 @@ vacuum_set_xid_limits(Relation rel,
|
|||||||
* frequency), but would still be a significant improvement.
|
* frequency), but would still be a significant improvement.
|
||||||
*/
|
*/
|
||||||
SetOldSnapshotThresholdTimestamp(limit_ts, limit_xmin);
|
SetOldSnapshotThresholdTimestamp(limit_ts, limit_xmin);
|
||||||
*oldestXmin = limit_xmin;
|
*OldestXmin = limit_xmin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert(TransactionIdIsNormal(*oldestXmin));
|
Assert(TransactionIdIsNormal(*OldestXmin));
|
||||||
|
|
||||||
/* Acquire oldestMxact */
|
/* Acquire OldestMxact */
|
||||||
*oldestMxact = GetOldestMultiXactId();
|
*OldestMxact = GetOldestMultiXactId();
|
||||||
Assert(MultiXactIdIsValid(*oldestMxact));
|
Assert(MultiXactIdIsValid(*OldestMxact));
|
||||||
|
|
||||||
/* Acquire next XID/next MXID values used to apply age-based settings */
|
/* Acquire next XID/next MXID values used to apply age-based settings */
|
||||||
nextXID = ReadNextTransactionId();
|
nextXID = ReadNextTransactionId();
|
||||||
@ -1025,13 +1029,13 @@ vacuum_set_xid_limits(Relation rel,
|
|||||||
freeze_min_age = Min(freeze_min_age, autovacuum_freeze_max_age / 2);
|
freeze_min_age = Min(freeze_min_age, autovacuum_freeze_max_age / 2);
|
||||||
Assert(freeze_min_age >= 0);
|
Assert(freeze_min_age >= 0);
|
||||||
|
|
||||||
/* Compute freezeLimit, being careful to generate a normal XID */
|
/* Compute FreezeLimit, being careful to generate a normal XID */
|
||||||
*freezeLimit = nextXID - freeze_min_age;
|
*FreezeLimit = nextXID - freeze_min_age;
|
||||||
if (!TransactionIdIsNormal(*freezeLimit))
|
if (!TransactionIdIsNormal(*FreezeLimit))
|
||||||
*freezeLimit = FirstNormalTransactionId;
|
*FreezeLimit = FirstNormalTransactionId;
|
||||||
/* freezeLimit must always be <= oldestXmin */
|
/* FreezeLimit must always be <= OldestXmin */
|
||||||
if (TransactionIdPrecedes(*oldestXmin, *freezeLimit))
|
if (TransactionIdPrecedes(*OldestXmin, *FreezeLimit))
|
||||||
*freezeLimit = *oldestXmin;
|
*FreezeLimit = *OldestXmin;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute the multixact age for which freezing is urgent. This is
|
* Compute the multixact age for which freezing is urgent. This is
|
||||||
@ -1052,16 +1056,16 @@ vacuum_set_xid_limits(Relation rel,
|
|||||||
effective_multixact_freeze_max_age / 2);
|
effective_multixact_freeze_max_age / 2);
|
||||||
Assert(multixact_freeze_min_age >= 0);
|
Assert(multixact_freeze_min_age >= 0);
|
||||||
|
|
||||||
/* Compute multiXactCutoff, being careful to generate a valid value */
|
/* Compute MultiXactCutoff, being careful to generate a valid value */
|
||||||
*multiXactCutoff = nextMXID - multixact_freeze_min_age;
|
*MultiXactCutoff = nextMXID - multixact_freeze_min_age;
|
||||||
if (*multiXactCutoff < FirstMultiXactId)
|
if (*MultiXactCutoff < FirstMultiXactId)
|
||||||
*multiXactCutoff = FirstMultiXactId;
|
*MultiXactCutoff = FirstMultiXactId;
|
||||||
/* multiXactCutoff must always be <= oldestMxact */
|
/* MultiXactCutoff must always be <= OldestMxact */
|
||||||
if (MultiXactIdPrecedes(*oldestMxact, *multiXactCutoff))
|
if (MultiXactIdPrecedes(*OldestMxact, *MultiXactCutoff))
|
||||||
*multiXactCutoff = *oldestMxact;
|
*MultiXactCutoff = *OldestMxact;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Done setting output parameters; check if oldestXmin or oldestMxact are
|
* Done setting output parameters; check if OldestXmin or OldestMxact are
|
||||||
* held back to an unsafe degree in passing
|
* held back to an unsafe degree in passing
|
||||||
*/
|
*/
|
||||||
safeOldestXmin = nextXID - autovacuum_freeze_max_age;
|
safeOldestXmin = nextXID - autovacuum_freeze_max_age;
|
||||||
@ -1070,12 +1074,12 @@ vacuum_set_xid_limits(Relation rel,
|
|||||||
safeOldestMxact = nextMXID - effective_multixact_freeze_max_age;
|
safeOldestMxact = nextMXID - effective_multixact_freeze_max_age;
|
||||||
if (safeOldestMxact < FirstMultiXactId)
|
if (safeOldestMxact < FirstMultiXactId)
|
||||||
safeOldestMxact = FirstMultiXactId;
|
safeOldestMxact = FirstMultiXactId;
|
||||||
if (TransactionIdPrecedes(*oldestXmin, safeOldestXmin))
|
if (TransactionIdPrecedes(*OldestXmin, safeOldestXmin))
|
||||||
ereport(WARNING,
|
ereport(WARNING,
|
||||||
(errmsg("cutoff for removing and freezing tuples is far in the past"),
|
(errmsg("cutoff for removing and freezing tuples is far in the past"),
|
||||||
errhint("Close open transactions soon to avoid wraparound problems.\n"
|
errhint("Close open transactions soon to avoid wraparound problems.\n"
|
||||||
"You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
|
"You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
|
||||||
if (MultiXactIdPrecedes(*oldestMxact, safeOldestMxact))
|
if (MultiXactIdPrecedes(*OldestMxact, safeOldestMxact))
|
||||||
ereport(WARNING,
|
ereport(WARNING,
|
||||||
(errmsg("cutoff for freezing multixacts is far in the past"),
|
(errmsg("cutoff for freezing multixacts is far in the past"),
|
||||||
errhint("Close open transactions soon to avoid wraparound problems.\n"
|
errhint("Close open transactions soon to avoid wraparound problems.\n"
|
||||||
|
@ -286,15 +286,11 @@ extern void vac_update_relstats(Relation relation,
|
|||||||
bool *frozenxid_updated,
|
bool *frozenxid_updated,
|
||||||
bool *minmulti_updated,
|
bool *minmulti_updated,
|
||||||
bool in_outer_xact);
|
bool in_outer_xact);
|
||||||
extern bool vacuum_set_xid_limits(Relation rel,
|
extern bool vacuum_set_xid_limits(Relation rel, const VacuumParams *params,
|
||||||
int freeze_min_age,
|
TransactionId *OldestXmin,
|
||||||
int multixact_freeze_min_age,
|
MultiXactId *OldestMxact,
|
||||||
int freeze_table_age,
|
TransactionId *FreezeLimit,
|
||||||
int multixact_freeze_table_age,
|
MultiXactId *MultiXactCutoff);
|
||||||
TransactionId *oldestXmin,
|
|
||||||
MultiXactId *oldestMxact,
|
|
||||||
TransactionId *freezeLimit,
|
|
||||||
MultiXactId *multiXactCutoff);
|
|
||||||
extern bool vacuum_xid_failsafe_check(TransactionId relfrozenxid,
|
extern bool vacuum_xid_failsafe_check(TransactionId relfrozenxid,
|
||||||
MultiXactId relminmxid);
|
MultiXactId relminmxid);
|
||||||
extern void vac_update_datfrozenxid(void);
|
extern void vac_update_datfrozenxid(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user