mirror of
https://github.com/postgres/postgres.git
synced 2025-06-10 09:21:54 +03:00
Allow pg_dumpall to specify a database name rather than the default
'template1'. Dave Page
This commit is contained in:
parent
5ce94b28cc
commit
d37881fd90
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.60 2007/01/25 02:30:32 momjian Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.61 2007/01/25 02:46:33 momjian Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -313,6 +313,7 @@ PostgreSQL documentation
|
|||||||
<variablelist>
|
<variablelist>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>-h <replaceable>host</replaceable></term>
|
<term>-h <replaceable>host</replaceable></term>
|
||||||
|
<term>--host=<replaceable>host</replaceable></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Specifies the host name of the machine on which the database
|
Specifies the host name of the machine on which the database
|
||||||
@ -323,9 +324,23 @@ PostgreSQL documentation
|
|||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>-l <replaceable>dbname</replaceable></term>
|
||||||
|
<term>--database=<replaceable>dbname</replaceable></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Specifies the name of the database to connect to to dump global
|
||||||
|
objects and discover what other databases should be dumped. If
|
||||||
|
not specified, the <quote>postgres</quote> database will be used,
|
||||||
|
and if that does not exist, <quote>template1</quote> will be used.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>-p <replaceable>port</replaceable></term>
|
<term>-p <replaceable>port</replaceable></term>
|
||||||
|
<term>--port=<replaceable>port</replaceable></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Specifies the TCP port or local Unix domain socket file
|
Specifies the TCP port or local Unix domain socket file
|
||||||
@ -338,6 +353,7 @@ PostgreSQL documentation
|
|||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>-U <replaceable>username</replaceable></term>
|
<term>-U <replaceable>username</replaceable></term>
|
||||||
|
<term>--username=<replaceable>username</replaceable></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Connect as the given user.
|
Connect as the given user.
|
||||||
@ -347,6 +363,7 @@ PostgreSQL documentation
|
|||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>-W</term>
|
<term>-W</term>
|
||||||
|
<term>--password</term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Force a password prompt. This should happen automatically if
|
Force a password prompt. This should happen automatically if
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.87 2007/01/25 02:30:32 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.88 2007/01/25 02:46:33 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -75,6 +75,7 @@ main(int argc, char *argv[])
|
|||||||
char *pghost = NULL;
|
char *pghost = NULL;
|
||||||
char *pgport = NULL;
|
char *pgport = NULL;
|
||||||
char *pguser = NULL;
|
char *pguser = NULL;
|
||||||
|
char *pgdb = NULL;
|
||||||
bool force_password = false;
|
bool force_password = false;
|
||||||
bool data_only = false;
|
bool data_only = false;
|
||||||
bool globals_only = false;
|
bool globals_only = false;
|
||||||
@ -96,6 +97,7 @@ main(int argc, char *argv[])
|
|||||||
{"globals-only", no_argument, NULL, 'g'},
|
{"globals-only", no_argument, NULL, 'g'},
|
||||||
{"host", required_argument, NULL, 'h'},
|
{"host", required_argument, NULL, 'h'},
|
||||||
{"ignore-version", no_argument, NULL, 'i'},
|
{"ignore-version", no_argument, NULL, 'i'},
|
||||||
|
{"database", required_argument, NULL, 'l'},
|
||||||
{"oids", no_argument, NULL, 'o'},
|
{"oids", no_argument, NULL, 'o'},
|
||||||
{"no-owner", no_argument, NULL, 'O'},
|
{"no-owner", no_argument, NULL, 'O'},
|
||||||
{"port", required_argument, NULL, 'p'},
|
{"port", required_argument, NULL, 'p'},
|
||||||
@ -165,7 +167,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
pgdumpopts = createPQExpBuffer();
|
pgdumpopts = createPQExpBuffer();
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "acdDgh:ioOp:rsS:tU:vWxX:", long_options, &optindex)) != -1)
|
while ((c = getopt_long(argc, argv, "acdDgh:il:oOp:rsS:tU:vWxX:", long_options, &optindex)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
@ -201,6 +203,10 @@ main(int argc, char *argv[])
|
|||||||
ignoreVersion = true;
|
ignoreVersion = true;
|
||||||
appendPQExpBuffer(pgdumpopts, " -i");
|
appendPQExpBuffer(pgdumpopts, " -i");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
pgdb = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
appendPQExpBuffer(pgdumpopts, " -o");
|
appendPQExpBuffer(pgdumpopts, " -o");
|
||||||
@ -337,15 +343,40 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First try to connect to database "postgres", and failing that
|
* If there was a database specified on the command line, use that,
|
||||||
|
* otherwise try to connect to database "postgres", and failing that
|
||||||
* "template1". "postgres" is the preferred choice for 8.1 and later
|
* "template1". "postgres" is the preferred choice for 8.1 and later
|
||||||
* servers, but it usually will not exist on older ones.
|
* servers, but it usually will not exist on older ones.
|
||||||
*/
|
*/
|
||||||
conn = connectDatabase("postgres", pghost, pgport, pguser,
|
if (pgdb)
|
||||||
|
{
|
||||||
|
conn = connectDatabase(pgdb, pghost, pgport, pguser,
|
||||||
|
force_password, false);
|
||||||
|
|
||||||
|
if (!conn)
|
||||||
|
{
|
||||||
|
fprintf(stderr, _("%s: could not connect to database \"%s\"\n"),
|
||||||
|
progname, pgdb);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
conn = connectDatabase("postgres", pghost, pgport, pguser,
|
||||||
force_password, false);
|
force_password, false);
|
||||||
if (!conn)
|
if (!conn)
|
||||||
conn = connectDatabase("template1", pghost, pgport, pguser,
|
conn = connectDatabase("template1", pghost, pgport, pguser,
|
||||||
force_password, true);
|
force_password, true);
|
||||||
|
|
||||||
|
if (!conn)
|
||||||
|
{
|
||||||
|
fprintf(stderr, _("%s: could not connect to databases \"postgres\" or \"template1\". Please specify an alternative database\n"),
|
||||||
|
progname);
|
||||||
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the active encoding and the standard_conforming_strings setting, so
|
* Get the active encoding and the standard_conforming_strings setting, so
|
||||||
@ -444,6 +475,7 @@ help(void)
|
|||||||
|
|
||||||
printf(_("\nConnection options:\n"));
|
printf(_("\nConnection options:\n"));
|
||||||
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
|
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
|
||||||
|
printf(_(" -l, --database=dbname specify an alternate default database\n"));
|
||||||
printf(_(" -p, --port=PORT database server port number\n"));
|
printf(_(" -p, --port=PORT database server port number\n"));
|
||||||
printf(_(" -U, --username=NAME connect as specified database user\n"));
|
printf(_(" -U, --username=NAME connect as specified database user\n"));
|
||||||
printf(_(" -W, --password force password prompt (should happen automatically)\n"));
|
printf(_(" -W, --password force password prompt (should happen automatically)\n"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user