Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd37881f

Browse files
committed
Allow pg_dumpall to specify a database name rather than the default
'template1'.Dave Page
1 parent5ce94b2 commitd37881f

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

‎doc/src/sgml/ref/pg_dumpall.sgml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.60 2007/01/25 02:30:32 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.61 2007/01/25 02:46:33 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -313,6 +313,7 @@ PostgreSQL documentation
313313
<variablelist>
314314
<varlistentry>
315315
<term>-h <replaceable>host</replaceable></term>
316+
<term>--host=<replaceable>host</replaceable></term>
316317
<listitem>
317318
<para>
318319
Specifies the host name of the machine on which the database
@@ -323,9 +324,23 @@ PostgreSQL documentation
323324
</para>
324325
</listitem>
325326
</varlistentry>
327+
328+
<varlistentry>
329+
<term>-l <replaceable>dbname</replaceable></term>
330+
<term>--database=<replaceable>dbname</replaceable></term>
331+
<listitem>
332+
<para>
333+
Specifies the name of the database to connect to to dump global
334+
objects and discover what other databases should be dumped. If
335+
not specified, the <quote>postgres</quote> database will be used,
336+
and if that does not exist, <quote>template1</quote> will be used.
337+
</para>
338+
</listitem>
339+
</varlistentry>
326340

327341
<varlistentry>
328342
<term>-p <replaceable>port</replaceable></term>
343+
<term>--port=<replaceable>port</replaceable></term>
329344
<listitem>
330345
<para>
331346
Specifies the TCP port or local Unix domain socket file
@@ -338,6 +353,7 @@ PostgreSQL documentation
338353

339354
<varlistentry>
340355
<term>-U <replaceable>username</replaceable></term>
356+
<term>--username=<replaceable>username</replaceable></term>
341357
<listitem>
342358
<para>
343359
Connect as the given user.
@@ -347,6 +363,7 @@ PostgreSQL documentation
347363

348364
<varlistentry>
349365
<term>-W</term>
366+
<term>--password</term>
350367
<listitem>
351368
<para>
352369
Force a password prompt. This should happen automatically if

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.87 2007/01/25 02:30:32 momjian Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.88 2007/01/25 02:46:33 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -75,6 +75,7 @@ main(int argc, char *argv[])
7575
char*pghost=NULL;
7676
char*pgport=NULL;
7777
char*pguser=NULL;
78+
char*pgdb=NULL;
7879
boolforce_password= false;
7980
booldata_only= false;
8081
boolglobals_only= false;
@@ -96,6 +97,7 @@ main(int argc, char *argv[])
9697
{"globals-only",no_argument,NULL,'g'},
9798
{"host",required_argument,NULL,'h'},
9899
{"ignore-version",no_argument,NULL,'i'},
100+
{"database",required_argument,NULL,'l'},
99101
{"oids",no_argument,NULL,'o'},
100102
{"no-owner",no_argument,NULL,'O'},
101103
{"port",required_argument,NULL,'p'},
@@ -165,7 +167,7 @@ main(int argc, char *argv[])
165167

166168
pgdumpopts=createPQExpBuffer();
167169

168-
while ((c=getopt_long(argc,argv,"acdDgh:ioOp:rsS:tU:vWxX:",long_options,&optindex))!=-1)
170+
while ((c=getopt_long(argc,argv,"acdDgh:il:oOp:rsS:tU:vWxX:",long_options,&optindex))!=-1)
169171
{
170172
switch (c)
171173
{
@@ -201,6 +203,10 @@ main(int argc, char *argv[])
201203
ignoreVersion= true;
202204
appendPQExpBuffer(pgdumpopts," -i");
203205
break;
206+
207+
case'l':
208+
pgdb=optarg;
209+
break;
204210

205211
case'o':
206212
appendPQExpBuffer(pgdumpopts," -o");
@@ -337,15 +343,40 @@ main(int argc, char *argv[])
337343
}
338344

339345
/*
340-
* First try to connect to database "postgres", and failing that
346+
* If there was a database specified on the command line, use that,
347+
* otherwise try to connect to database "postgres", and failing that
341348
* "template1". "postgres" is the preferred choice for 8.1 and later
342349
* servers, but it usually will not exist on older ones.
343350
*/
344-
conn=connectDatabase("postgres",pghost,pgport,pguser,
351+
if (pgdb)
352+
{
353+
conn=connectDatabase(pgdb,pghost,pgport,pguser,
354+
force_password, false);
355+
356+
if (!conn)
357+
{
358+
fprintf(stderr,_("%s: could not connect to database \"%s\"\n"),
359+
progname,pgdb);
360+
exit(1);
361+
}
362+
}
363+
else
364+
{
365+
conn=connectDatabase("postgres",pghost,pgport,pguser,
345366
force_password, false);
346-
if (!conn)
347-
conn=connectDatabase("template1",pghost,pgport,pguser,
348-
force_password, true);
367+
if (!conn)
368+
conn=connectDatabase("template1",pghost,pgport,pguser,
369+
force_password, true);
370+
371+
if (!conn)
372+
{
373+
fprintf(stderr,_("%s: could not connect to databases \"postgres\" or \"template1\". Please specify an alternative database\n"),
374+
progname);
375+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
376+
progname);
377+
exit(1);
378+
}
379+
}
349380

350381
/*
351382
* Get the active encoding and the standard_conforming_strings setting, so
@@ -444,6 +475,7 @@ help(void)
444475

445476
printf(_("\nConnection options:\n"));
446477
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
478+
printf(_(" -l, --database=dbname specify an alternate default database\n"));
447479
printf(_(" -p, --port=PORT database server port number\n"));
448480
printf(_(" -U, --username=NAME connect as specified database user\n"));
449481
printf(_(" -W, --password force password prompt (should happen automatically)\n"));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp