*** a/doc/src/sgml/ref/pg_resetxlog.sgml --- b/doc/src/sgml/ref/pg_resetxlog.sgml *************** *** 180,185 **** PostgreSQL documentation --- 180,189 ---- pg_control and then exit without modifying anything. This is mainly a debugging tool, but can be useful as a sanity check before allowing pg_resetxlog to proceed for real. + It will print values in two sections. In first section it will print all original/guessed values + and in second section all values to be used after reset. In second section filename will be + always printed as segment number will be at-least one more than current. Also if any other parameter + is given using appropriate switch, then those new values will be also printed. *** a/src/bin/pg_resetxlog/pg_resetxlog.c --- b/src/bin/pg_resetxlog/pg_resetxlog.c *************** *** 65,73 **** static XLogSegNo newXlogSegNo; /* new XLOG segment # */ --- 65,83 ---- 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_xid = 0; + static Oid set_oid = 0; + static MultiXactId set_mxid = 0; + static MultiXactOffset set_mxoff = (MultiXactOffset) -1; + static uint32 minXlogTli = 0; + static XLogSegNo minXlogSegNo = 0; + static XLogSegNo currentXlogSegNo = 0; /* current segment # from checkpoint */ + static bool ReadControlFile(void); static void GuessControlValues(void); static void PrintControlValues(bool guessed); + static void PrintNewControlValues(void); static void RewriteControlFile(void); static void FindEndOfXLOG(void); static void KillExistingXLOG(void); *************** *** 82,95 **** main(int argc, char *argv[]) int c; bool force = false; bool noupdate = false; - uint32 set_xid_epoch = (uint32) -1; - TransactionId set_xid = 0; - Oid set_oid = 0; - MultiXactId set_mxid = 0; MultiXactId set_oldestmxid = 0; - MultiXactOffset set_mxoff = (MultiXactOffset) -1; - uint32 minXlogTli = 0; - XLogSegNo minXlogSegNo = 0; char *endptr; char *endptr2; char *DataDir; --- 92,98 ---- *************** *** 302,307 **** main(int argc, char *argv[]) --- 305,317 ---- FindEndOfXLOG(); /* + * Print current control file parameters, if had to guess anything and -f + * was not given or -n is given. + */ + if ((guessed && !force) || noupdate) + PrintControlValues(guessed); + + /* * Adjust fields if required by switches. (Do this now so that printout, * if any, includes these values.) */ *************** *** 352,362 **** main(int argc, char *argv[]) /* * If we had to guess anything, and -f was not given, just print the ! * guessed values and exit. Also print if -n is given. */ if ((guessed && !force) || noupdate) { ! PrintControlValues(guessed); if (!noupdate) { printf(_("\nIf these values seem acceptable, use -f to force reset.\n")); --- 362,372 ---- /* * If we had to guess anything, and -f was not given, just print the ! * values to be reset and exit. Also print value to be reset if -n is given. */ if ((guessed && !force) || noupdate) { ! PrintNewControlValues(); if (!noupdate) { printf(_("\nIf these values seem acceptable, use -f to force reset.\n")); *************** *** 561,567 **** PrintControlValues(bool guessed) if (guessed) printf(_("Guessed pg_control values:\n\n")); else ! printf(_("pg_control values:\n\n")); /* * Format system_identifier separately to keep platform-dependent format --- 571,577 ---- if (guessed) printf(_("Guessed pg_control values:\n\n")); else ! printf(_("Current pg_control values:\n\n")); /* * Format system_identifier separately to keep platform-dependent format *************** *** 570,576 **** PrintControlValues(bool guessed) snprintf(sysident_str, sizeof(sysident_str), UINT64_FORMAT, ControlFile.system_identifier); ! XLogFileName(fname, ControlFile.checkPointCopy.ThisTimeLineID, newXlogSegNo); printf(_("First log segment after reset: %s\n"), fname); --- 580,586 ---- snprintf(sysident_str, sizeof(sysident_str), UINT64_FORMAT, ControlFile.system_identifier); ! XLogFileName(fname, ControlFile.checkPointCopy.ThisTimeLineID, currentXlogSegNo); printf(_("First log segment after reset: %s\n"), fname); *************** *** 632,637 **** PrintControlValues(bool guessed) --- 642,704 ---- /* + * Print the values to be changed after pg_resetxlog. + * + * NB: this display should be just for those fields that are + * going to change after reset. + */ + static void + PrintNewControlValues() + { + char fname[MAXFNAMELEN]; + + /* This will be always printed in order to keep format same. */ + printf(_("\n\nValues to be used after reset:\n\n")); + + XLogFileName(fname, ControlFile.checkPointCopy.ThisTimeLineID, newXlogSegNo); + printf(_("First log segment after reset: %s\n"), fname); + + if (set_mxid != 0) + { + printf(_("NextMultiXactId: %u\n"), + ControlFile.checkPointCopy.nextMulti); + printf(_("OldestMultiXid: %u\n"), + ControlFile.checkPointCopy.oldestMulti); + printf(_("OldestMulti's DB: %u\n"), + ControlFile.checkPointCopy.oldestMultiDB); + } + + if (set_mxoff != -1) + { + printf(_("NextMultiOffset: %u\n"), + ControlFile.checkPointCopy.nextMultiOffset); + } + + if (set_oid != 0) + { + printf(_("NextOID: %u\n"), + ControlFile.checkPointCopy.nextOid); + } + + if (set_xid != 0) + { + printf(_("NextXID: %u\n"), + ControlFile.checkPointCopy.nextXid); + printf(_("OldestXID: %u\n"), + ControlFile.checkPointCopy.oldestXid); + printf(_("OldestXID's DB: %u\n"), + ControlFile.checkPointCopy.oldestXidDB); + } + + if (set_xid_epoch != -1) + { + printf(_("NextXID Epoch: %u\n"), + ControlFile.checkPointCopy.nextXidEpoch); + } + } + + + /* * Write out the new pg_control file. */ static void *************** *** 753,758 **** FindEndOfXLOG(void) --- 820,826 ---- */ segs_per_xlogid = (UINT64CONST(0x0000000100000000) / ControlFile.xlog_seg_size); newXlogSegNo = ControlFile.checkPointCopy.redo / ControlFile.xlog_seg_size; + currentXlogSegNo = newXlogSegNo; /* * Scan the pg_xlog directory to find existing WAL segment files. We *************** *** 1039,1045 **** usage(void) printf(_(" -f force update to be done\n")); printf(_(" -l XLOGFILE force minimum WAL starting location for new transaction log\n")); printf(_(" -m MXID,MXID set next and oldest multitransaction ID\n")); ! printf(_(" -n no update, just show extracted control values (for testing)\n")); printf(_(" -o OID set next OID\n")); printf(_(" -O OFFSET set next multitransaction offset\n")); printf(_(" -V, --version output version information, then exit\n")); --- 1107,1113 ---- printf(_(" -f force update to be done\n")); printf(_(" -l XLOGFILE force minimum WAL starting location for new transaction log\n")); printf(_(" -m MXID,MXID set next and oldest multitransaction ID\n")); ! printf(_(" -n no update, just show extracted control values (for testing) and to be reset values of parameters(if given)\n")); printf(_(" -o OID set next OID\n")); printf(_(" -O OFFSET set next multitransaction offset\n")); printf(_(" -V, --version output version information, then exit\n"));