summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2014-09-25 10:26:18 +0000
committerHeikki Linnakangas2014-09-25 10:37:19 +0000
commitb0d81adea650a4bc2b9391234345bb935b89a694 (patch)
tree38f431acc1f775adfae8db86d09cec72375b8b5b
parentafd1d95f5bf0cb48af77e5897eb4c356b5371c7b (diff)
Add -D option to specify data directory to pg_controldata and pg_resetxlog.
It was confusing that to other commands, like initdb and postgres, you would pass the data directory with "-D datadir", but pg_controldata and pg_resetxlog would take just plain path, without the "-D". With this patch, pg_controldata and pg_resetxlog also accept "-D datadir". Abhijit Menon-Sen, with minor kibitzing by me
-rw-r--r--doc/src/sgml/ref/pg_controldata.sgml2
-rw-r--r--doc/src/sgml/ref/pg_resetxlog.sgml2
-rw-r--r--src/bin/pg_controldata/pg_controldata.c2
-rw-r--r--src/bin/pg_resetxlog/pg_resetxlog.c16
4 files changed, 13 insertions, 9 deletions
diff --git a/doc/src/sgml/ref/pg_controldata.sgml b/doc/src/sgml/ref/pg_controldata.sgml
index fbf40fcf9d..4a360d61fd 100644
--- a/doc/src/sgml/ref/pg_controldata.sgml
+++ b/doc/src/sgml/ref/pg_controldata.sgml
@@ -23,7 +23,7 @@ PostgreSQL documentation
<cmdsynopsis>
<command>pg_controldata</command>
<arg choice="opt"><replaceable class="parameter">option</replaceable></arg>
- <arg choice="opt"><replaceable class="parameter">datadir</replaceable></arg>
+ <arg choice="opt"><arg choice="opt"><option>-D</option></arg> <replaceable class="parameter">datadir</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
diff --git a/doc/src/sgml/ref/pg_resetxlog.sgml b/doc/src/sgml/ref/pg_resetxlog.sgml
index 0b53bd6859..aba7185f35 100644
--- a/doc/src/sgml/ref/pg_resetxlog.sgml
+++ b/doc/src/sgml/ref/pg_resetxlog.sgml
@@ -30,7 +30,7 @@ PostgreSQL documentation
<arg choice="opt"><option>-m</option> <replaceable class="parameter">mxid</replaceable>,<replaceable class="parameter">mxid</replaceable></arg>
<arg choice="opt"><option>-O</option> <replaceable class="parameter">mxoff</replaceable></arg>
<arg choice="opt"><option>-l</option> <replaceable class="parameter">xlogfile</replaceable></arg>
- <arg choice="plain"><replaceable>datadir</replaceable></arg>
+ <arg choice="req"><arg choice="opt"><option>-D</option></arg> <replaceable class="parameter">datadir</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index f81502466e..118e653b79 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -33,7 +33,7 @@ usage(const char *progname)
{
printf(_("%s displays control information of a PostgreSQL database cluster.\n\n"), progname);
printf(_("Usage:\n"));
- printf(_(" %s [OPTION] [DATADIR]\n"), progname);
+ printf(_(" %s [OPTION] [[-D] DATADIR]\n"), progname);
printf(_("\nOptions:\n"));
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n"));
diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c
index 302d0054b2..028a1f0566 100644
--- a/src/bin/pg_resetxlog/pg_resetxlog.c
+++ b/src/bin/pg_resetxlog/pg_resetxlog.c
@@ -89,7 +89,7 @@ main(int argc, char *argv[])
MultiXactId set_oldestmxid = 0;
char *endptr;
char *endptr2;
- char *DataDir;
+ char *DataDir = NULL;
int fd;
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_resetxlog"));
@@ -111,10 +111,14 @@ main(int argc, char *argv[])
}
- while ((c = getopt(argc, argv, "fl:m:no:O:x:e:")) != -1)
+ while ((c = getopt(argc, argv, "D:fl:m:no:O:x:e:")) != -1)
{
switch (c)
{
+ case 'D':
+ DataDir = optarg;
+ break;
+
case 'f':
force = true;
break;
@@ -233,12 +237,14 @@ main(int argc, char *argv[])
}
}
- if (optind == argc)
+ if (DataDir == NULL && optind == argc)
{
fprintf(stderr, _("%s: no data directory specified\n"), progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
}
+ if (DataDir == NULL)
+ DataDir = argv[optind];
/*
* Don't allow pg_resetxlog to be run as root, to avoid overwriting the
@@ -257,8 +263,6 @@ main(int argc, char *argv[])
}
#endif
- DataDir = argv[optind];
-
if (chdir(DataDir) < 0)
{
fprintf(stderr, _("%s: could not change directory to \"%s\": %s\n"),
@@ -1077,7 +1081,7 @@ static void
usage(void)
{
printf(_("%s resets the PostgreSQL transaction log.\n\n"), progname);
- printf(_("Usage:\n %s [OPTION]... DATADIR\n\n"), progname);
+ printf(_("Usage:\n %s [OPTION]... {[-D] DATADIR}\n\n"), progname);
printf(_("Options:\n"));
printf(_(" -e XIDEPOCH set next transaction ID epoch\n"));
printf(_(" -f force update to be done\n"));