Per discussion on -hackers, the attached patch introduces an optional
parameter to pg_dumpall's -g (--globals-only) option to allow roles or
tablespaces to be dumped on their own.
eg.
pg_dumpall -g -- Dump roles and tablespaces per current behaviour
pg_dumpall -gr -- Dump roles only (or users and groups)
pg_dumpall -gt -- Dump tablespaces only
Regards, Dave.
Index: doc/src/sgml/ref/pg_dumpall.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v
retrieving revision 1.58
diff -c -r1.58 pg_dumpall.sgml
*** doc/src/sgml/ref/pg_dumpall.sgml 7 Oct 2006 20:59:04 -0000 1.58
--- doc/src/sgml/ref/pg_dumpall.sgml 12 Jan 2007 14:01:10 -0000
***************
*** 130,140 ****
</varlistentry>
<varlistentry>
! <term><option>-g</option></term>
! <term><option>--globals-only</option></term>
<listitem>
<para>
! Dump only global objects (users and groups), no databases.
</para>
</listitem>
</varlistentry>
--- 130,145 ----
</varlistentry>
<varlistentry>
! <term><option>-g[<replaceable
class="parameter">r</replaceable>|<replaceable
class="parameter">t</replaceable></option></term>
! <term><option>--globals-only[=<replaceable
class="parameter">r</replaceable>|<replaceable
class="parameter">t</replaceable></option></term>
<listitem>
<para>
! Dump only global objects (roles and/or tablespaces), no databases.
! The <replaceable class="parameter">r</replaceable> parameter will
! cause only roles to be dumped, and the
! <replaceable class="parameter">t</replaceable> parameter will cause
! only tablespaces to be dumped. If no parameter is specified, all
! global object types will be dumped.
</para>
</listitem>
</varlistentry>
Index: src/bin/pg_dump/pg_dumpall.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v
retrieving revision 1.86
diff -c -r1.86 pg_dumpall.c
*** src/bin/pg_dump/pg_dumpall.c 5 Jan 2007 22:19:48 -0000 1.86
--- src/bin/pg_dump/pg_dumpall.c 12 Jan 2007 14:01:12 -0000
***************
*** 78,83 ****
--- 78,85 ----
bool force_password = false;
bool data_only = false;
bool globals_only = false;
+ bool roles_only = false;
+ bool tablespaces_only = false;
bool schema_only = false;
PGconn *conn;
int encoding;
***************
*** 91,97 ****
{"inserts", no_argument, NULL, 'd'},
{"attribute-inserts", no_argument, NULL, 'D'},
{"column-inserts", no_argument, NULL, 'D'},
! {"globals-only", no_argument, NULL, 'g'},
{"host", required_argument, NULL, 'h'},
{"ignore-version", no_argument, NULL, 'i'},
{"oids", no_argument, NULL, 'o'},
--- 93,99 ----
{"inserts", no_argument, NULL, 'd'},
{"attribute-inserts", no_argument, NULL, 'D'},
{"column-inserts", no_argument, NULL, 'D'},
! {"globals-only", optional_argument, NULL, 'g'},
{"host", required_argument, NULL, 'h'},
{"ignore-version", no_argument, NULL, 'i'},
{"oids", no_argument, NULL, 'o'},
***************
*** 161,167 ****
pgdumpopts = createPQExpBuffer();
! while ((c = getopt_long(argc, argv, "acdDgh:ioOp:sS:U:vWxX:",
long_options, &optindex)) != -1)
{
switch (c)
{
--- 163,169 ----
pgdumpopts = createPQExpBuffer();
! while ((c = getopt_long(argc, argv, "acdDg::h:ioOp:sS:U:vWxX:",
long_options, &optindex)) != -1)
{
switch (c)
{
***************
*** 181,186 ****
--- 183,203 ----
case 'g':
globals_only = true;
+ if (optarg)
+ {
+ if (strcmp(optarg, "r") == 0)
+ roles_only = true;
+ else if (strcmp(optarg, "t") == 0)
+ tablespaces_only = true;
+ else
+ {
+ fprintf(stderr,
+ _("%s: invalid
-g option -- %s\n"),
+ progname,
optarg);
+ fprintf(stderr, _("Try \"%s
--help\" for more information.\n"), progname);
+ exit(1);
+ }
+ }
break;
case 'h':
***************
*** 332,349 ****
printf("SET escape_string_warning = 'off';\n");
printf("\n");
! /* Dump roles (users) */
! dumpRoles(conn);
! /* Dump role memberships --- need different method for pre-8.1
*/
! if (server_version >= 80100)
! dumpRoleMembership(conn);
! else
! dumpGroups(conn);
! /* Dump tablespaces */
! if (server_version >= 80000)
! dumpTablespaces(conn);
/* Dump CREATE DATABASE commands */
if (!globals_only)
--- 349,372 ----
printf("SET escape_string_warning = 'off';\n");
printf("\n");
! if (!tablespaces_only)
! {
! /* Dump roles (users) */
! dumpRoles(conn);
! /* Dump role memberships --- need different method for
pre-8.1 */
! if (server_version >= 80100)
! dumpRoleMembership(conn);
! else
! dumpGroups(conn);
! }
! if (!roles_only)
! {
! /* Dump tablespaces */
! if (server_version >= 80000)
! dumpTablespaces(conn);
! }
/* Dump CREATE DATABASE commands */
if (!globals_only)
***************
*** 381,387 ****
printf(_(" -c, --clean clean (drop) databases prior to
create\n"));
printf(_(" -d, --inserts dump data as INSERT, rather than
COPY, commands\n"));
printf(_(" -D, --column-inserts dump data as INSERT commands with
column names\n"));
! printf(_(" -g, --globals-only dump only global objects, no
databases\n"));
printf(_(" -o, --oids include OIDs in dump\n"));
printf(_(" -O, --no-owner skip restoration of object
ownership\n"));
printf(_(" -s, --schema-only dump only the schema, no data\n"));
--- 404,410 ----
printf(_(" -c, --clean clean (drop) databases prior to
create\n"));
printf(_(" -d, --inserts dump data as INSERT, rather than
COPY, commands\n"));
printf(_(" -D, --column-inserts dump data as INSERT commands with
column names\n"));
! printf(_(" -g, --globals-only=[r|t] dump only global objects, no
databases. Optionally restrict to roles or tablespaces\n"));
printf(_(" -o, --oids include OIDs in dump\n"));
printf(_(" -O, --no-owner skip restoration of object
ownership\n"));
printf(_(" -s, --schema-only dump only the schema, no data\n"));
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly