TODO: Split out pg_resetxlog output into pre- and post-sections
This patch implements the following TODO item:
Split out pg_resetxlog output into pre- and post-sections
http://archives.postgresql.org/pgsql-hackers/2010-08/msg02040.php
On execution of pg_resetxlog using the option -n
1. It will display values in two section.
2. First section will be called as "Current pg_control values or Guess pg_control values".
3. In first section, it will display all current (i.e. before change) values of control file or guessed values.
4. Second section will be called as "Values to be used after reset".
5. In second section, it will display new values of parameters to be reset as per user request.
Please provide your opinion or expectation out of this patch.
I will add the same to November commitFest.
Thanks and Regards,
Kumar Rajeev Rastogi
Attachments:
pg_resetxlogsection.patchapplication/octet-stream; name=pg_resetxlogsection.patchDownload
*** a/doc/src/sgml/ref/pg_resetxlog.sgml
--- b/doc/src/sgml/ref/pg_resetxlog.sgml
***************
*** 180,185 **** PostgreSQL documentation
--- 180,188 ----
<filename>pg_control</> and then exit without modifying anything.
This is mainly a debugging tool, but can be useful as a sanity check
before allowing <command>pg_resetxlog</command> to proceed for real.
+ Also if any of the other parameter given along with -n, then it will print values
+ in two sections. In first section it will print all original values and in next section
+ all values which will be on reset.
</para>
<para>
*** a/src/bin/pg_resetxlog/pg_resetxlog.c
--- b/src/bin/pg_resetxlog/pg_resetxlog.c
***************
*** 56,61 ****
--- 56,69 ----
#include "catalog/pg_control.h"
#include "common/fe_memutils.h"
+ /* Indicate which control file parameter going to be changed*/
+ #define DISPLAY_XIDEPOCH 1
+ #define DISPLAY_XLOGFILE 2
+ #define DISPLAY_MXID 4
+ #define DISPLAY_OID 8
+ #define DISPLAY_OFFSET 16
+ #define DISPLAY_XID 32
+
extern int optind;
extern char *optarg;
***************
*** 68,73 **** static const char *progname;
--- 76,82 ----
static bool ReadControlFile(void);
static void GuessControlValues(void);
static void PrintControlValues(bool guessed);
+ static void PrintNewControlValues(int changedParam);
static void RewriteControlFile(void);
static void FindEndOfXLOG(void);
static void KillExistingXLOG(void);
***************
*** 94,99 **** main(int argc, char *argv[])
--- 103,109 ----
char *endptr2;
char *DataDir;
int fd;
+ int changedParam = 0;
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_resetxlog"));
***************
*** 128,133 **** main(int argc, char *argv[])
--- 138,144 ----
case 'e':
set_xid_epoch = strtoul(optarg, &endptr, 0);
+ changedParam |= DISPLAY_XIDEPOCH;
if (endptr == optarg || *endptr != '\0')
{
fprintf(stderr, _("%s: invalid argument for option -e\n"), progname);
***************
*** 143,148 **** main(int argc, char *argv[])
--- 154,160 ----
case 'x':
set_xid = strtoul(optarg, &endptr, 0);
+ changedParam |= DISPLAY_XID;
if (endptr == optarg || *endptr != '\0')
{
fprintf(stderr, _("%s: invalid argument for option -x\n"), progname);
***************
*** 158,163 **** main(int argc, char *argv[])
--- 170,176 ----
case 'o':
set_oid = strtoul(optarg, &endptr, 0);
+ changedParam |= DISPLAY_OID;
if (endptr == optarg || *endptr != '\0')
{
fprintf(stderr, _("%s: invalid argument for option -o\n"), progname);
***************
*** 173,178 **** main(int argc, char *argv[])
--- 186,192 ----
case 'm':
set_mxid = strtoul(optarg, &endptr, 0);
+ changedParam |= DISPLAY_MXID;
if (endptr == optarg || *endptr != ',')
{
fprintf(stderr, _("%s: invalid argument for option -m\n"), progname);
***************
*** 207,212 **** main(int argc, char *argv[])
--- 221,227 ----
case 'O':
set_mxoff = strtoul(optarg, &endptr, 0);
+ changedParam |= DISPLAY_OFFSET;
if (endptr == optarg || *endptr != '\0')
{
fprintf(stderr, _("%s: invalid argument for option -O\n"), progname);
***************
*** 228,233 **** main(int argc, char *argv[])
--- 243,249 ----
exit(1);
}
XLogFromFileName(optarg, &minXlogTli, &minXlogSegNo);
+ changedParam |= DISPLAY_XLOGFILE;
break;
default:
***************
*** 301,306 **** main(int argc, char *argv[])
--- 317,326 ----
*/
FindEndOfXLOG();
+ /* print current control file parameter value if -n is given*/
+ if (noupdate)
+ PrintControlValues(guessed);
+
/*
* Adjust fields if required by switches. (Do this now so that printout,
* if any, includes these values.)
***************
*** 350,360 **** main(int argc, char *argv[])
if (minXlogSegNo > newXlogSegNo)
newXlogSegNo = minXlogSegNo;
/*
* 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)
--- 370,387 ----
if (minXlogSegNo > newXlogSegNo)
newXlogSegNo = minXlogSegNo;
+ /* Print only new values to be reset if -n is given*/
+ if (noupdate)
+ {
+ PrintNewControlValues(changedParam);
+ exit(0);
+ }
+
/*
* If we had to guess anything, and -f was not given, just print the
! * guessed values and exit.
*/
! if (guessed && !force)
{
PrintControlValues(guessed);
if (!noupdate)
***************
*** 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
--- 588,594 ----
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
***************
*** 631,636 **** PrintControlValues(bool guessed)
--- 658,721 ----
}
+ /*
+ * 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(int changedParam)
+ {
+ if (changedParam)
+ printf(_("\n\nValues to be used after reset:\n\n"));
+
+ if (changedParam & DISPLAY_XLOGFILE)
+ {
+ printf(_("First log file ID: %u\n"),
+ (uint32) ((newXlogSegNo) / XLogSegmentsPerXLogId));
+ printf(_("First log file segment: %u\n"),
+ (uint32) ((newXlogSegNo) % XLogSegmentsPerXLogId));
+ printf(_("TimeLineID: %u\n"),
+ ControlFile.checkPointCopy.ThisTimeLineID);
+ }
+
+ if (changedParam & DISPLAY_MXID)
+ {
+ printf(_("NextMultiXactId: %u\n"),
+ ControlFile.checkPointCopy.nextMulti);
+ printf(_("oldestMultiXid: %u\n"),
+ ControlFile.checkPointCopy.oldestMulti);
+ }
+
+ if (changedParam & DISPLAY_OFFSET)
+ {
+ printf(_("NextMultiOffset: %u\n"),
+ ControlFile.checkPointCopy.nextMultiOffset);
+ }
+
+ if (changedParam & DISPLAY_OID)
+ {
+ printf(_("NextOID: %u\n"),
+ ControlFile.checkPointCopy.nextOid);
+ }
+
+ if (changedParam & DISPLAY_XID)
+ {
+ printf(_("NextXID: %u\n"),
+ ControlFile.checkPointCopy.nextXid);
+ printf(_("oldestXID: %u\n"),
+ ControlFile.checkPointCopy.oldestXid);
+ }
+
+ if (changedParam & DISPLAY_XIDEPOCH)
+ {
+ printf(_("NextXID Epoch: %u\n"),
+ ControlFile.checkPointCopy.nextXidEpoch);
+ }
+ }
+
+
/*
* Write out the new pg_control file.
*/
***************
*** 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"));
--- 1124,1130 ----
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"));
On Tue, Nov 5, 2013 at 3:20 PM, Rajeev rastogi
<rajeev.rastogi@huawei.com> wrote:
On execution of pg_resetxlog using the option -n
1. It will display values in two section.
2. First section will be called as "Current pg_control
values or Guess pg_control values".3. In first section, it will display all current (i.e.
before change) values of control file or guessed values.4. Second section will be called as "Values to be used after
reset".5. In second section, it will display new values of
parameters to be reset as per user request.Please provide your opinion or expectation out of this patch.
Your approach in patch seems to be inline with Todo item. On a quick
glance, I observed few things which can make your patch better:
1. The purpose was to print pg_control values in one section and any
other reset values in different section, so in that
regard, should we display below in new section, as here
newXlogSegNo is not directly from pg_control.
PrintControlValues()
{
..
XLogFileName(fname, ControlFile.checkPointCopy.ThisTimeLineID, newXlogSegNo);
printf(_("First log segment after reset: %s\n"),
fname);
}
2. why to have extra flags for changedParam, can't we do without it.
For example, we already use set_xid value to check if user has provided xid.
3.
+ static void
+ PrintNewControlValues(int changedParam)
+ {
+ if (changedParam)
+ printf(_("\n\nValues to be used after reset:\n\n"));
Even after first if check fails, still you continue to check other
values, it is better if you can have check if (changedParam) before
calling this function
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Fri, 08 November 2013 09:47
On Tue, Nov 5, 2013 at 3:20 PM, Rajeev rastogi
<rajeev.rastogi@huawei.com> wrote:On execution of pg_resetxlog using the option -n
1. It will display values in two section.
2. First section will be called as "Current
pg_control
values or Guess pg_control values".
3. In first section, it will display all current (i.e.
before change) values of control file or guessed values.4. Second section will be called as "Values to be
used
after reset".
5. In second section, it will display new values of
parameters to be reset as per user request.Please provide your opinion or expectation out of this patch.
Your approach in patch seems to be inline with Todo item. On a quick
glance, I observed few things which can make your patch better:1. The purpose was to print pg_control values in one section and any
other reset values in different section, so in that
regard, should we display below in new section, as here newXlogSegNo
is not directly from pg_control.PrintControlValues()
{
..
XLogFileName(fname, ControlFile.checkPointCopy.ThisTimeLineID,
newXlogSegNo);printf(_("First log segment after reset: %s\n"),
fname);
}
Yes we can print newXlogSegNo.
2. why to have extra flags for changedParam, can't we do without it.
For example, we already use set_xid value to check if user has provided
xid.
You mean to say that we can print wherever values of control file parameter is
getting assigned.
If yes, then the problem is that every places will have to check the condition as
if(noupdate) and then print the corresponding value. E.g.
If (noupdate)
printf(_("NextMultiXactId:%u\n"), ControlFile.checkPointCopy.nextMulti);
3. + static void + PrintNewControlValues(int changedParam) { + if (changedParam) + printf(_("\n\nValues to be used after reset:\n\n"));Even after first if check fails, still you continue to check other
values, it is better if you can have check if (changedParam) before
calling this function
Yes you are correct.
But now this check will not be required because always at-least one value (i.e. of newXlogSegNo)
will be printed.
Please let me know if understanding of all comments are correct.
After that I will update the patch.
Thanks and Regards,
Kumar Rajeev Rastogi
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Fri, Nov 8, 2013 at 10:37 AM, Rajeev rastogi
<rajeev.rastogi@huawei.com> wrote:
On Fri, 08 November 2013 09:47
On Tue, Nov 5, 2013 at 3:20 PM, Rajeev rastogi
<rajeev.rastogi@huawei.com> wrote:On execution of pg_resetxlog using the option -n
Please provide your opinion or expectation out of this patch.
Your approach in patch seems to be inline with Todo item. On a quick
glance, I observed few things which can make your patch better:1. The purpose was to print pg_control values in one section and any
other reset values in different section, so in that
regard, should we display below in new section, as here newXlogSegNo
is not directly from pg_control.PrintControlValues()
{
..
XLogFileName(fname, ControlFile.checkPointCopy.ThisTimeLineID,
newXlogSegNo);printf(_("First log segment after reset: %s\n"),
fname);
}Yes we can print newXlogSegNo.
I think then your documentation also need updates.
2. why to have extra flags for changedParam, can't we do without it.
For example, we already use set_xid value to check if user has provided
xid.You mean to say that we can print wherever values of control file parameter is
getting assigned.If yes, then the problem is that every places will have to check the condition as
if(noupdate) and then print the corresponding value. E.g.
If (noupdate)
printf(_("NextMultiXactId:%u\n"), ControlFile.checkPointCopy.nextMulti);
No, not this way, may be making set_xid as file level parameters,
so that you can use them later as well.
Your current way also doesn't seem to be too unreasonable, however
it is better if you can do without it.
One more thing, I think as per this patch few parameters will be
displayed twice once in "pg_control values .." section and once in
"Values to be used after reset:", so by doing this I guess you want to
make it easier for user to refer both pg_control's original/guessed
value and new value after reset. Here I wonder if someone wants to
refer to original values, can't he directly use pg_controldata? Anyone
else have thoughts about how can we display values which can make
current situation better for user.
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers