Updated patches attached.

-- Abhijit
>From b3bd465357f96ebf1953b3a98f25fb51bac5eb26 Mon Sep 17 00:00:00 2001
From: Abhijit Menon-Sen <a...@2ndquadrant.com>
Date: Wed, 24 Sep 2014 16:26:00 +0530
Subject: Make pg_controldata ignore a -D before DataDir

---
 doc/src/sgml/ref/pg_controldata.sgml    |  5 +++--
 src/bin/pg_controldata/pg_controldata.c | 13 +++++++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/doc/src/sgml/ref/pg_controldata.sgml b/doc/src/sgml/ref/pg_controldata.sgml
index fbf40fc..b4be660 100644
--- a/doc/src/sgml/ref/pg_controldata.sgml
+++ b/doc/src/sgml/ref/pg_controldata.sgml
@@ -40,8 +40,9 @@ PostgreSQL documentation
   <para>
    This utility can only be run by the user who initialized the cluster because
    it requires read access to the data directory.
-   You can specify the data directory on the command line, or use
-   the environment variable <envar>PGDATA</>.  This utility supports the options
+   You can specify the data directory on the command line, with or without
+   <option>-D</> or use the environment variable <envar>PGDATA</>.
+   This utility supports the options
    <option>-V</> and <option>--version</>, which print the
    <application>pg_controldata</application> version and exit.  It also
    supports options <option>-?</> and <option>--help</>, which output the
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index f815024..cfa6911 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -31,14 +31,19 @@
 static void
 usage(const char *progname)
 {
+	const char *pgdata;
+
+	pgdata = getenv("PGDATA");
+	if (!pgdata)
+		pgdata = "";
+
 	printf(_("%s displays control information of a PostgreSQL database cluster.\n\n"), progname);
 	printf(_("Usage:\n"));
 	printf(_("  %s [OPTION] [DATADIR]\n"), progname);
 	printf(_("\nOptions:\n"));
+	printf(_("  -D DATADIR     data directory (default: \"%s\")\n"), pgdata);
 	printf(_("  -V, --version  output version information, then exit\n"));
 	printf(_("  -?, --help     show this help, then exit\n"));
-	printf(_("\nIf no data directory (DATADIR) is specified, "
-			 "the environment variable PGDATA\nis used.\n\n"));
 	printf(_("Report bugs to <pgsql-b...@postgresql.org>.\n"));
 }
 
@@ -120,7 +125,11 @@ main(int argc, char *argv[])
 	}
 
 	if (argc > 1)
+	{
 		DataDir = argv[1];
+		if (strcmp(DataDir, "-D") == 0 && argc > 2)
+			DataDir = argv[2];
+	}
 	else
 		DataDir = getenv("PGDATA");
 	if (DataDir == NULL)
-- 
1.9.1

>From 51c651a24db4f3b977fa38c08177acc062a5fb56 Mon Sep 17 00:00:00 2001
From: Abhijit Menon-Sen <a...@2ndquadrant.com>
Date: Wed, 24 Sep 2014 16:48:36 +0530
Subject: Make pg_resetxlog also accept -D datadir

---
 doc/src/sgml/ref/pg_resetxlog.sgml  |  6 ++++--
 src/bin/pg_resetxlog/pg_resetxlog.c | 16 +++++++++++-----
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/doc/src/sgml/ref/pg_resetxlog.sgml b/doc/src/sgml/ref/pg_resetxlog.sgml
index 0b53bd6..7b2386a 100644
--- a/doc/src/sgml/ref/pg_resetxlog.sgml
+++ b/doc/src/sgml/ref/pg_resetxlog.sgml
@@ -22,6 +22,7 @@ PostgreSQL documentation
  <refsynopsisdiv>
   <cmdsynopsis>
    <command>pg_resetxlog</command>
+   <arg choice="opt"><option>-D</option> <replaceable class="parameter">datadir</replaceable></arg>
    <arg choice="opt"><option>-f</option></arg>
    <arg choice="opt"><option>-n</option></arg>
    <arg choice="opt"><option>-o</option> <replaceable class="parameter">oid</replaceable></arg>
@@ -30,7 +31,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="opt"><replaceable>datadir</replaceable></arg>
   </cmdsynopsis>
  </refsynopsisdiv>
 
@@ -55,7 +56,8 @@ PostgreSQL documentation
   <para>
    This utility can only be run by the user who installed the server, because
    it requires read/write access to the data directory.
-   For safety reasons, you must specify the data directory on the command line.
+   For safety reasons, you must specify the data directory on the command line
+   (with or without <option>-D</>).
    <command>pg_resetxlog</command> does not use the environment variable
    <envar>PGDATA</>.
   </para>
diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c
index 302d005..9364e49 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,7 +237,7 @@ 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);
@@ -257,7 +261,8 @@ main(int argc, char *argv[])
 	}
 #endif
 
-	DataDir = argv[optind];
+	if (DataDir == NULL)
+		DataDir = argv[optind];
 
 	if (chdir(DataDir) < 0)
 	{
@@ -1077,8 +1082,9 @@ 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]... [DATADIR]\n\n"), progname);
 	printf(_("Options:\n"));
+	printf(_("  -D DATADIR       data directory\n"));
 	printf(_("  -e XIDEPOCH      set next transaction ID epoch\n"));
 	printf(_("  -f               force update to be done\n"));
 	printf(_("  -l XLOGFILE      force minimum WAL starting location for new transaction log\n"));
-- 
1.9.1

>From 2bf16c3b09faec09120f832a92cc6c2cbe80a30d Mon Sep 17 00:00:00 2001
From: Abhijit Menon-Sen <a...@2ndquadrant.com>
Date: Wed, 24 Sep 2014 20:15:53 +0530
Subject: Use user, not env, as the default for -U

---
 src/bin/psql/help.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 4d11952..49b2fdd 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -132,7 +132,7 @@ usage(unsigned short int pager)
 	env = getenv("PGUSER");
 	if (!env)
 		env = user;
-	fprintf(output, _("  -U, --username=USERNAME  database user name (default: \"%s\")\n"), env);
+	fprintf(output, _("  -U, --username=USERNAME  database user name (default: \"%s\")\n"), user);
 	fprintf(output, _("  -w, --no-password        never prompt for password\n"));
 	fprintf(output, _("  -W, --password           force password prompt (should happen automatically)\n"));
 
-- 
1.9.1

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to