pg_dumpall default database
| От | Dave Page |
|---|---|
| Тема | pg_dumpall default database |
| Дата | |
| Msg-id | 45AB854A.6000805@postgresql.org обсуждение исходный текст |
| Ответы |
Re: pg_dumpall default database
|
| Список | pgsql-patches |
Per discussion on -hackers, the attached patch allow the default
database to be specified on the pg_dumpall command line, eg.
pg_dumpall [options...] [dbname]
If dbname is not specified, postgres/template1 are used per current
behaviour. If a connection cannot be made to dbname, an error is
returned and pg_dumpall exits. I've also added a similar error handler
to catch failures to connect to postgres and pg_dumpall (currently, the
dump will still be attempted).
This patch should be applied on top of my previous patch
(pg_dumpall_global_objects2.diff)
Regards, Dave
diff -c -r pgsql.orig/doc/src/sgml/ref/pg_dumpall.sgml pgsql/doc/src/sgml/ref/pg_dumpall.sgml
*** pgsql.orig/doc/src/sgml/ref/pg_dumpall.sgml Mon Jan 15 13:26:07 2007
--- pgsql/doc/src/sgml/ref/pg_dumpall.sgml Mon Jan 15 13:34:31 2007
***************
*** 23,28 ****
--- 23,29 ----
<cmdsynopsis>
<command>pg_dumpall</command>
<arg rep="repeat"><replaceable>option</replaceable></arg>
+ <arg><replaceable>dbname</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
***************
*** 354,359 ****
--- 355,372 ----
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><replaceable class="parameter">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>
</variablelist>
</para>
</refsect1>
diff -c -r pgsql.orig/src/bin/pg_dump/pg_dumpall.c pgsql/src/bin/pg_dump/pg_dumpall.c
*** pgsql.orig/src/bin/pg_dump/pg_dumpall.c Mon Jan 15 13:26:07 2007
--- pgsql/src/bin/pg_dump/pg_dumpall.c Mon Jan 15 12:52:34 2007
***************
*** 75,80 ****
--- 75,81 ----
char *pghost = NULL;
char *pgport = NULL;
char *pguser = NULL;
+ char *pgdb = NULL;
bool force_password = false;
bool data_only = false;
bool globals_only = false;
***************
*** 299,304 ****
--- 300,312 ----
if (use_setsessauth)
appendPQExpBuffer(pgdumpopts, " --use-set-session-authorization");
+ /* If there is an argument left, assume it's a database name */
+ if (optind < argc)
+ {
+ pgdb = argv[optind];
+ optind++;
+ }
+
if (optind < argc)
{
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
***************
*** 337,351 ****
}
/*
! * First try to connect to database "postgres", and failing that
* "template1". "postgres" is the preferred choice for 8.1 and later
* servers, but it usually will not exist on older ones.
*/
! conn = connectDatabase("postgres", pghost, pgport, pguser,
force_password, false);
! if (!conn)
! conn = connectDatabase("template1", pghost, pgport, pguser,
! force_password, true);
/*
* Get the active encoding and the standard_conforming_strings setting, so
--- 345,384 ----
}
/*
! * 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
* servers, but it usually will not exist on older ones.
*/
! 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);
! if (!conn)
! conn = connectDatabase("template1", pghost, pgport, pguser,
! force_password, true);
!
! if (!conn)
! {
! fprintf(stderr, _("%s: could not connect to databases \"postgres\" or \"template1\". Please specify an
alternativedatabase\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
В списке pgsql-patches по дате отправления: