Skip to content

Commit b0d81ad

Browse files
committed
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
1 parent afd1d95 commit b0d81ad

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

doc/src/sgml/ref/pg_controldata.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PostgreSQL documentation
2323
<cmdsynopsis>
2424
<command>pg_controldata</command>
2525
<arg choice="opt"><replaceable class="parameter">option</replaceable></arg>
26-
<arg choice="opt"><replaceable class="parameter">datadir</replaceable></arg>
26+
<arg choice="opt"><arg choice="opt"><option>-D</option></arg> <replaceable class="parameter">datadir</replaceable></arg>
2727
</cmdsynopsis>
2828
</refsynopsisdiv>
2929

doc/src/sgml/ref/pg_resetxlog.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ PostgreSQL documentation
3030
<arg choice="opt"><option>-m</option> <replaceable class="parameter">mxid</replaceable>,<replaceable class="parameter">mxid</replaceable></arg>
3131
<arg choice="opt"><option>-O</option> <replaceable class="parameter">mxoff</replaceable></arg>
3232
<arg choice="opt"><option>-l</option> <replaceable class="parameter">xlogfile</replaceable></arg>
33-
<arg choice="plain"><replaceable>datadir</replaceable></arg>
33+
<arg choice="req"><arg choice="opt"><option>-D</option></arg> <replaceable class="parameter">datadir</replaceable></arg>
3434
</cmdsynopsis>
3535
</refsynopsisdiv>
3636

src/bin/pg_controldata/pg_controldata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ usage(const char *progname)
3333
{
3434
printf(_("%s displays control information of a PostgreSQL database cluster.\n\n"), progname);
3535
printf(_("Usage:\n"));
36-
printf(_(" %s [OPTION] [DATADIR]\n"), progname);
36+
printf(_(" %s [OPTION] [[-D] DATADIR]\n"), progname);
3737
printf(_("\nOptions:\n"));
3838
printf(_(" -V, --version output version information, then exit\n"));
3939
printf(_(" -?, --help show this help, then exit\n"));

src/bin/pg_resetxlog/pg_resetxlog.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ main(int argc, char *argv[])
8989
MultiXactId set_oldestmxid = 0;
9090
char *endptr;
9191
char *endptr2;
92-
char *DataDir;
92+
char *DataDir = NULL;
9393
int fd;
9494

9595
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_resetxlog"));
@@ -111,10 +111,14 @@ main(int argc, char *argv[])
111111
}
112112

113113

114-
while ((c = getopt(argc, argv, "fl:m:no:O:x:e:")) != -1)
114+
while ((c = getopt(argc, argv, "D:fl:m:no:O:x:e:")) != -1)
115115
{
116116
switch (c)
117117
{
118+
case 'D':
119+
DataDir = optarg;
120+
break;
121+
118122
case 'f':
119123
force = true;
120124
break;
@@ -233,12 +237,14 @@ main(int argc, char *argv[])
233237
}
234238
}
235239

236-
if (optind == argc)
240+
if (DataDir == NULL && optind == argc)
237241
{
238242
fprintf(stderr, _("%s: no data directory specified\n"), progname);
239243
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
240244
exit(1);
241245
}
246+
if (DataDir == NULL)
247+
DataDir = argv[optind];
242248

243249
/*
244250
* Don't allow pg_resetxlog to be run as root, to avoid overwriting the
@@ -257,8 +263,6 @@ main(int argc, char *argv[])
257263
}
258264
#endif
259265

260-
DataDir = argv[optind];
261-
262266
if (chdir(DataDir) < 0)
263267
{
264268
fprintf(stderr, _("%s: could not change directory to \"%s\": %s\n"),
@@ -1077,7 +1081,7 @@ static void
10771081
usage(void)
10781082
{
10791083
printf(_("%s resets the PostgreSQL transaction log.\n\n"), progname);
1080-
printf(_("Usage:\n %s [OPTION]... DATADIR\n\n"), progname);
1084+
printf(_("Usage:\n %s [OPTION]... {[-D] DATADIR}\n\n"), progname);
10811085
printf(_("Options:\n"));
10821086
printf(_(" -e XIDEPOCH set next transaction ID epoch\n"));
10831087
printf(_(" -f force update to be done\n"));

0 commit comments

Comments
 (0)