]> granicus.if.org Git - postgresql/commitdiff
Add -d/--dbname option to pg_dump.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 25 Feb 2013 17:39:04 +0000 (19:39 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 25 Feb 2013 17:39:04 +0000 (19:39 +0200)
You could already pass a database name just by passing it as the last
option, without -d. This is an alias for that, like the -d/--dbname option
in psql and many other client applications. For consistency.

doc/src/sgml/ref/pg_dump.sgml
src/bin/pg_dump/pg_dump.c

index 152edcbe6ed810966175089b1fa715ad36ced696..6d0f214d423a37639d2b596bc729c81365782175 100644 (file)
@@ -817,6 +817,26 @@ PostgreSQL documentation
     The following command-line options control the database connection parameters.
 
     <variablelist>
+     <varlistentry>
+      <term><option>-d <replaceable class="parameter">dbname</replaceable></></term>
+      <term><option>--dbname=<replaceable class="parameter">dbname</replaceable></></term>
+      <listitem>
+      <para>
+       Specifies the name of the database to connect to. This is
+       equivalent to specifying <replaceable
+       class="parameter">dbname</replaceable> as the first non-option
+       argument on the command line.
+      </para>
+      <para>
+       If this parameter contains an <symbol>=</symbol> sign or starts
+       with a valid <acronym>URI</acronym> prefix
+       (<literal>postgresql://</literal>
+       or <literal>postgres://</literal>), it is treated as a
+       <parameter>conninfo</parameter> string. See <xref linkend="libpq-connect"> for more information.
+      </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-h <replaceable class="parameter">host</replaceable></option></term>
       <term><option>--host=<replaceable class="parameter">host</replaceable></option></term>
index 43d571ca5bbe234644f2896b6a7e586b84dbc8f1..7903b79a323a70e1c392cf63febe73fbbcb53862 100644 (file)
@@ -307,6 +307,7 @@ main(int argc, char **argv)
                {"blobs", no_argument, NULL, 'b'},
                {"clean", no_argument, NULL, 'c'},
                {"create", no_argument, NULL, 'C'},
+               {"dbname", required_argument, NULL, 'd'},
                {"file", required_argument, NULL, 'f'},
                {"format", required_argument, NULL, 'F'},
                {"host", required_argument, NULL, 'h'},
@@ -387,7 +388,7 @@ main(int argc, char **argv)
                }
        }
 
-       while ((c = getopt_long(argc, argv, "abcCE:f:F:h:in:N:oOp:RsS:t:T:U:vwWxZ:",
+       while ((c = getopt_long(argc, argv, "abcCd:E:f:F:h:iK:n:N:oOp:RsS:t:T:U:vwWxZ:",
                                                        long_options, &optindex)) != -1)
        {
                switch (c)
@@ -408,6 +409,10 @@ main(int argc, char **argv)
                                outputCreateDB = 1;
                                break;
 
+                       case 'd':                       /* database name */
+                               dbname = pg_strdup(optarg);
+                               break;
+
                        case 'E':                       /* Dump encoding */
                                dumpencoding = pg_strdup(optarg);
                                break;
@@ -520,8 +525,11 @@ main(int argc, char **argv)
                }
        }
 
-       /* Get database name from command line */
-       if (optind < argc)
+       /*
+        * Non-option argument specifies database name as long as it wasn't
+        * already specified with -d / --dbname
+        */
+       if (optind < argc && dbname == NULL)
                dbname = argv[optind++];
 
        /* Complain if any arguments remain */
@@ -872,6 +880,7 @@ help(const char *progname)
                         "                               ALTER OWNER commands to set ownership\n"));
 
        printf(_("\nConnection options:\n"));
+       printf(_("  -d, --dbname=DBNAME      database to dump\n"));
        printf(_("  -h, --host=HOSTNAME      database server host or socket directory\n"));
        printf(_("  -p, --port=PORT          database server port number\n"));
        printf(_("  -U, --username=NAME      connect as specified database user\n"));