@@ -907,34 +907,20 @@ get_all_vacuum_rels(int options)
907
907
}
908
908
909
909
/*
910
- * vacuum_set_xid_limits () -- compute OldestXmin and freeze cutoff points
910
+ * vacuum_get_cutoffs () -- compute OldestXmin and freeze cutoff points
911
911
*
912
912
* The target relation and VACUUM parameters are our inputs.
913
913
*
914
- * Our output parameters are:
915
- * - OldestXmin is the Xid below which tuples deleted by any xact (that
916
- * committed) should be considered DEAD, not just RECENTLY_DEAD.
917
- * - OldestMxact is the Mxid below which MultiXacts are definitely not
918
- * seen as visible by any running transaction.
919
- * - FreezeLimit is the Xid below which all Xids are definitely frozen or
920
- * removed during aggressive vacuums.
921
- * - MultiXactCutoff is the value below which all MultiXactIds are definitely
922
- * removed from Xmax during aggressive vacuums.
914
+ * Output parameters are the cutoffs that VACUUM caller should use.
923
915
*
924
916
* Return value indicates if vacuumlazy.c caller should make its VACUUM
925
917
* operation aggressive. An aggressive VACUUM must advance relfrozenxid up to
926
918
* FreezeLimit (at a minimum), and relminmxid up to MultiXactCutoff (at a
927
919
* minimum).
928
- *
929
- * OldestXmin and OldestMxact are the most recent values that can ever be
930
- * passed to vac_update_relstats() as frozenxid and minmulti arguments by our
931
- * vacuumlazy.c caller later on. These values should be passed when it turns
932
- * out that VACUUM will leave no unfrozen XIDs/MXIDs behind in the table.
933
920
*/
934
921
bool
935
- vacuum_set_xid_limits (Relation rel , const VacuumParams * params ,
936
- TransactionId * OldestXmin , MultiXactId * OldestMxact ,
937
- TransactionId * FreezeLimit , MultiXactId * MultiXactCutoff )
922
+ vacuum_get_cutoffs (Relation rel , const VacuumParams * params ,
923
+ struct VacuumCutoffs * cutoffs )
938
924
{
939
925
int freeze_min_age ,
940
926
multixact_freeze_min_age ,
@@ -954,6 +940,10 @@ vacuum_set_xid_limits(Relation rel, const VacuumParams *params,
954
940
freeze_table_age = params -> freeze_table_age ;
955
941
multixact_freeze_table_age = params -> multixact_freeze_table_age ;
956
942
943
+ /* Set pg_class fields in cutoffs */
944
+ cutoffs -> relfrozenxid = rel -> rd_rel -> relfrozenxid ;
945
+ cutoffs -> relminmxid = rel -> rd_rel -> relminmxid ;
946
+
957
947
/*
958
948
* Acquire OldestXmin.
959
949
*
@@ -965,14 +955,14 @@ vacuum_set_xid_limits(Relation rel, const VacuumParams *params,
965
955
* that only one vacuum process can be working on a particular table at
966
956
* any time, and that each vacuum is always an independent transaction.
967
957
*/
968
- * OldestXmin = GetOldestNonRemovableTransactionId (rel );
958
+ cutoffs -> OldestXmin = GetOldestNonRemovableTransactionId (rel );
969
959
970
960
if (OldSnapshotThresholdActive ())
971
961
{
972
962
TransactionId limit_xmin ;
973
963
TimestampTz limit_ts ;
974
964
975
- if (TransactionIdLimitedForOldSnapshots (* OldestXmin , rel ,
965
+ if (TransactionIdLimitedForOldSnapshots (cutoffs -> OldestXmin , rel ,
976
966
& limit_xmin , & limit_ts ))
977
967
{
978
968
/*
@@ -982,20 +972,48 @@ vacuum_set_xid_limits(Relation rel, const VacuumParams *params,
982
972
* frequency), but would still be a significant improvement.
983
973
*/
984
974
SetOldSnapshotThresholdTimestamp (limit_ts , limit_xmin );
985
- * OldestXmin = limit_xmin ;
975
+ cutoffs -> OldestXmin = limit_xmin ;
986
976
}
987
977
}
988
978
989
- Assert (TransactionIdIsNormal (* OldestXmin ));
979
+ Assert (TransactionIdIsNormal (cutoffs -> OldestXmin ));
990
980
991
981
/* Acquire OldestMxact */
992
- * OldestMxact = GetOldestMultiXactId ();
993
- Assert (MultiXactIdIsValid (* OldestMxact ));
982
+ cutoffs -> OldestMxact = GetOldestMultiXactId ();
983
+ Assert (MultiXactIdIsValid (cutoffs -> OldestMxact ));
994
984
995
985
/* Acquire next XID/next MXID values used to apply age-based settings */
996
986
nextXID = ReadNextTransactionId ();
997
987
nextMXID = ReadNextMultiXactId ();
998
988
989
+ /*
990
+ * Also compute the multixact age for which freezing is urgent. This is
991
+ * normally autovacuum_multixact_freeze_max_age, but may be less if we are
992
+ * short of multixact member space.
993
+ */
994
+ effective_multixact_freeze_max_age = MultiXactMemberFreezeThreshold ();
995
+
996
+ /*
997
+ * Almost ready to set freeze output parameters; check if OldestXmin or
998
+ * OldestMxact are held back to an unsafe degree before we start on that
999
+ */
1000
+ safeOldestXmin = nextXID - autovacuum_freeze_max_age ;
1001
+ if (!TransactionIdIsNormal (safeOldestXmin ))
1002
+ safeOldestXmin = FirstNormalTransactionId ;
1003
+ safeOldestMxact = nextMXID - effective_multixact_freeze_max_age ;
1004
+ if (safeOldestMxact < FirstMultiXactId )
1005
+ safeOldestMxact = FirstMultiXactId ;
1006
+ if (TransactionIdPrecedes (cutoffs -> OldestXmin , safeOldestXmin ))
1007
+ ereport (WARNING ,
1008
+ (errmsg ("cutoff for removing and freezing tuples is far in the past" ),
1009
+ errhint ("Close open transactions soon to avoid wraparound problems.\n"
1010
+ "You might also need to commit or roll back old prepared transactions, or drop stale replication slots." )));
1011
+ if (MultiXactIdPrecedes (cutoffs -> OldestMxact , safeOldestMxact ))
1012
+ ereport (WARNING ,
1013
+ (errmsg ("cutoff for freezing multixacts is far in the past" ),
1014
+ errhint ("Close open transactions soon to avoid wraparound problems.\n"
1015
+ "You might also need to commit or roll back old prepared transactions, or drop stale replication slots." )));
1016
+
999
1017
/*
1000
1018
* Determine the minimum freeze age to use: as specified by the caller, or
1001
1019
* vacuum_freeze_min_age, but in any case not more than half
@@ -1008,19 +1026,12 @@ vacuum_set_xid_limits(Relation rel, const VacuumParams *params,
1008
1026
Assert (freeze_min_age >= 0 );
1009
1027
1010
1028
/* Compute FreezeLimit, being careful to generate a normal XID */
1011
- * FreezeLimit = nextXID - freeze_min_age ;
1012
- if (!TransactionIdIsNormal (* FreezeLimit ))
1013
- * FreezeLimit = FirstNormalTransactionId ;
1029
+ cutoffs -> FreezeLimit = nextXID - freeze_min_age ;
1030
+ if (!TransactionIdIsNormal (cutoffs -> FreezeLimit ))
1031
+ cutoffs -> FreezeLimit = FirstNormalTransactionId ;
1014
1032
/* FreezeLimit must always be <= OldestXmin */
1015
- if (TransactionIdPrecedes (* OldestXmin , * FreezeLimit ))
1016
- * FreezeLimit = * OldestXmin ;
1017
-
1018
- /*
1019
- * Compute the multixact age for which freezing is urgent. This is
1020
- * normally autovacuum_multixact_freeze_max_age, but may be less if we are
1021
- * short of multixact member space.
1022
- */
1023
- effective_multixact_freeze_max_age = MultiXactMemberFreezeThreshold ();
1033
+ if (TransactionIdPrecedes (cutoffs -> OldestXmin , cutoffs -> FreezeLimit ))
1034
+ cutoffs -> FreezeLimit = cutoffs -> OldestXmin ;
1024
1035
1025
1036
/*
1026
1037
* Determine the minimum multixact freeze age to use: as specified by
@@ -1035,33 +1046,12 @@ vacuum_set_xid_limits(Relation rel, const VacuumParams *params,
1035
1046
Assert (multixact_freeze_min_age >= 0 );
1036
1047
1037
1048
/* Compute MultiXactCutoff, being careful to generate a valid value */
1038
- * MultiXactCutoff = nextMXID - multixact_freeze_min_age ;
1039
- if (* MultiXactCutoff < FirstMultiXactId )
1040
- * MultiXactCutoff = FirstMultiXactId ;
1049
+ cutoffs -> MultiXactCutoff = nextMXID - multixact_freeze_min_age ;
1050
+ if (cutoffs -> MultiXactCutoff < FirstMultiXactId )
1051
+ cutoffs -> MultiXactCutoff = FirstMultiXactId ;
1041
1052
/* MultiXactCutoff must always be <= OldestMxact */
1042
- if (MultiXactIdPrecedes (* OldestMxact , * MultiXactCutoff ))
1043
- * MultiXactCutoff = * OldestMxact ;
1044
-
1045
- /*
1046
- * Done setting output parameters; check if OldestXmin or OldestMxact are
1047
- * held back to an unsafe degree in passing
1048
- */
1049
- safeOldestXmin = nextXID - autovacuum_freeze_max_age ;
1050
- if (!TransactionIdIsNormal (safeOldestXmin ))
1051
- safeOldestXmin = FirstNormalTransactionId ;
1052
- safeOldestMxact = nextMXID - effective_multixact_freeze_max_age ;
1053
- if (safeOldestMxact < FirstMultiXactId )
1054
- safeOldestMxact = FirstMultiXactId ;
1055
- if (TransactionIdPrecedes (* OldestXmin , safeOldestXmin ))
1056
- ereport (WARNING ,
1057
- (errmsg ("cutoff for removing and freezing tuples is far in the past" ),
1058
- errhint ("Close open transactions soon to avoid wraparound problems.\n"
1059
- "You might also need to commit or roll back old prepared transactions, or drop stale replication slots." )));
1060
- if (MultiXactIdPrecedes (* OldestMxact , safeOldestMxact ))
1061
- ereport (WARNING ,
1062
- (errmsg ("cutoff for freezing multixacts is far in the past" ),
1063
- errhint ("Close open transactions soon to avoid wraparound problems.\n"
1064
- "You might also need to commit or roll back old prepared transactions, or drop stale replication slots." )));
1053
+ if (MultiXactIdPrecedes (cutoffs -> OldestMxact , cutoffs -> MultiXactCutoff ))
1054
+ cutoffs -> MultiXactCutoff = cutoffs -> OldestMxact ;
1065
1055
1066
1056
/*
1067
1057
* Finally, figure out if caller needs to do an aggressive VACUUM or not.
@@ -1113,13 +1103,13 @@ vacuum_set_xid_limits(Relation rel, const VacuumParams *params,
1113
1103
* mechanism to determine if its table's relfrozenxid and relminmxid are now
1114
1104
* dangerously far in the past.
1115
1105
*
1116
- * Input parameters are the target relation's relfrozenxid and relminmxid.
1117
- *
1118
1106
* When we return true, VACUUM caller triggers the failsafe.
1119
1107
*/
1120
1108
bool
1121
- vacuum_xid_failsafe_check (TransactionId relfrozenxid , MultiXactId relminmxid )
1109
+ vacuum_xid_failsafe_check (const struct VacuumCutoffs * cutoffs )
1122
1110
{
1111
+ TransactionId relfrozenxid = cutoffs -> relfrozenxid ;
1112
+ MultiXactId relminmxid = cutoffs -> relminmxid ;
1123
1113
TransactionId xid_skip_limit ;
1124
1114
MultiXactId multi_skip_limit ;
1125
1115
int skip_index_vacuum ;
0 commit comments