summaryrefslogtreecommitdiff
path: root/src/bin/pg_resetwal/pg_resetwal.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2021-07-26 22:38:14 -0400
committerBruce Momjian <bruce@momjian.us>2021-07-26 22:38:14 -0400
commit71121450e8f42b21665ee9c8f70b701f7a16c801 (patch)
tree0d5c233c778c037f836013ea06a5b215285ca1a4 /src/bin/pg_resetwal/pg_resetwal.c
parent4372f0685de164e769e895dbada18cad792192b2 (diff)
pg_resetxlog: add option to set oldest xid & use by pg_upgrade
Add pg_resetxlog -u option to set the oldest xid in pg_control. Previously -x set this value be -2 billion less than the -x value. However, this causes the server to immediately scan all relation's relfrozenxid so it can advance pg_control's oldest xid to be inside the autovacuum_freeze_max_age range, which is inefficient and might disrupt diagnostic recovery. pg_upgrade will use this option to better create the new cluster to match the old cluster. Reported-by: Jason Harvey, Floris Van Nee Discussion: https://postgr.es/m/20190615183759.GB239428@rfd.leadboat.com, 87da83168c644fd9aae38f546cc70295@opammb0562.comp.optiver.com Author: Bertrand Drouvot Backpatch-through: 9.6
Diffstat (limited to 'src/bin/pg_resetwal/pg_resetwal.c')
-rw-r--r--src/bin/pg_resetwal/pg_resetwal.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index 0e6d790246f..b3827931888 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -62,6 +62,7 @@ static XLogSegNo newXlogSegNo; /* new XLOG segment # */
static bool guessed = false; /* T if we had to guess at any values */
static const char *progname;
static uint32 set_xid_epoch = (uint32) -1;
+static TransactionId set_oldest_xid = 0;
static TransactionId set_xid = 0;
static TransactionId set_oldest_commit_ts_xid = 0;
static TransactionId set_newest_commit_ts_xid = 0;
@@ -115,7 +116,7 @@ main(int argc, char *argv[])
}
- while ((c = getopt(argc, argv, "c:D:e:fl:m:no:O:x:")) != -1)
+ while ((c = getopt(argc, argv, "c:D:e:fl:m:no:O:u:x:")) != -1)
{
switch (c)
{
@@ -148,6 +149,21 @@ main(int argc, char *argv[])
}
break;
+ case 'u':
+ set_oldest_xid = strtoul(optarg, &endptr, 0);
+ if (endptr == optarg || *endptr != '\0')
+ {
+ fprintf(stderr, _("invalid argument for option %s"), "-u");
+ fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+ exit(1);
+ }
+ if (!TransactionIdIsNormal(set_oldest_xid))
+ {
+ fprintf(stderr, _("oldest transaction ID (-u) must be greater or equal to %u"), FirstNormalTransactionId);
+ exit(1);
+ }
+ break;
+
case 'x':
set_xid = strtoul(optarg, &endptr, 0);
if (endptr == optarg || *endptr != '\0')
@@ -369,23 +385,15 @@ main(int argc, char *argv[])
if (set_xid_epoch != -1)
ControlFile.checkPointCopy.nextXidEpoch = set_xid_epoch;
- if (set_xid != 0)
+ if (set_oldest_xid != 0)
{
- ControlFile.checkPointCopy.nextXid = set_xid;
-
- /*
- * For the moment, just set oldestXid to a value that will force
- * immediate autovacuum-for-wraparound. It's not clear whether adding
- * user control of this is useful, so let's just do something that's
- * reasonably safe. The magic constant here corresponds to the
- * maximum allowed value of autovacuum_freeze_max_age.
- */
- ControlFile.checkPointCopy.oldestXid = set_xid - 2000000000;
- if (ControlFile.checkPointCopy.oldestXid < FirstNormalTransactionId)
- ControlFile.checkPointCopy.oldestXid += FirstNormalTransactionId;
+ ControlFile.checkPointCopy.oldestXid = set_oldest_xid;
ControlFile.checkPointCopy.oldestXidDB = InvalidOid;
}
+ if (set_xid != 0)
+ ControlFile.checkPointCopy.nextXid = set_xid;
+
if (set_oldest_commit_ts_xid != 0)
ControlFile.checkPointCopy.oldestCommitTsXid = set_oldest_commit_ts_xid;
if (set_newest_commit_ts_xid != 0)
@@ -1239,6 +1247,7 @@ usage(void)
printf(_(" -n no update, just show what would be done (for testing)\n"));
printf(_(" -o OID set next OID\n"));
printf(_(" -O OFFSET set next multitransaction offset\n"));
+ printf(_(" -u XID set oldest transaction ID\n"));
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -x XID set next transaction ID\n"));
printf(_(" -?, --help show this help, then exit\n"));