Re: Allow dumping of roles or tablespaces - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: Allow dumping of roles or tablespaces
Date
Msg-id 200701250230.l0P2UhQ21498@momjian.us
Whole thread Raw
In response to Re: Allow dumping of roles or tablespaces  (Dave Page <dpage@postgresql.org>)
List pgsql-patches
Patch applied.  Thanks.

---------------------------------------------------------------------------

Dave Page wrote:
> Tom Lane wrote:
> > Dave Page <dpage@postgresql.org> writes:
> >> 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
> >
> > This seems a bit ugly, mainly because (1) it doesn't have a natural
> > translation to long-form switches, and (2) it screws up the usual
> > habit of merging multiple single-letter switches into one argument.
> > Perhaps something like
> >
> >     --roles-only
> >     --tablespaces-only
> >     --globals-only
> >
> > Not sure if there are free single-letter codes for the first two,
> > but on the whole I'm more interested in having sane long-form names
> > than sane short ones ...
>
> Revised patch attached - it now has
>
> -r --roles-only
> -t --tablespaces-only
> -g --globals-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    15 Jan 2007 09:10:31 -0000
> ***************
> *** 134,140 ****
>         <term><option>--globals-only</option></term>
>         <listitem>
>          <para>
> !         Dump only global objects (users and groups), no databases.
>          </para>
>         </listitem>
>        </varlistentry>
> --- 134,140 ----
>         <term><option>--globals-only</option></term>
>         <listitem>
>          <para>
> !         Dump only global objects (roles and tablespaces), no databases.
>          </para>
>         </listitem>
>        </varlistentry>
> ***************
> *** 194,199 ****
> --- 194,209 ----
>        </varlistentry>
>
>        <varlistentry>
> +       <term><option>-r</option></term>
> +       <term><option>--roles-only</option></term>
> +       <listitem>
> +        <para>
> +         Dump only roles, no databases or tablespaces.
> +        </para>
> +       </listitem>
> +      </varlistentry>
> +
> +      <varlistentry>
>         <term><option>-s</option></term>
>         <term><option>--schema-only</option></term>
>         <listitem>
> ***************
> *** 217,222 ****
> --- 227,242 ----
>        </varlistentry>
>
>        <varlistentry>
> +       <term><option>-t</option></term>
> +       <term><option>--tablespaces-only</option></term>
> +       <listitem>
> +        <para>
> +         Dump only tablespaces, no databases or roles.
> +        </para>
> +       </listitem>
> +      </varlistentry>
> +
> +      <varlistentry>
>         <term><option>-v</></term>
>         <term><option>--verbose</></term>
>         <listitem>
> 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    15 Jan 2007 09:10:33 -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;
> ***************
> *** 97,107 ****
>           {"oids", no_argument, NULL, 'o'},
>           {"no-owner", no_argument, NULL, 'O'},
>           {"port", required_argument, NULL, 'p'},
> !         {"password", no_argument, NULL, 'W'},
>           {"schema-only", no_argument, NULL, 's'},
>           {"superuser", required_argument, NULL, 'S'},
>           {"username", required_argument, NULL, 'U'},
>           {"verbose", no_argument, NULL, 'v'},
>           {"no-privileges", no_argument, NULL, 'x'},
>           {"no-acl", no_argument, NULL, 'x'},
>
> --- 99,111 ----
>           {"oids", no_argument, NULL, 'o'},
>           {"no-owner", no_argument, NULL, 'O'},
>           {"port", required_argument, NULL, 'p'},
> !         {"roles-only", no_argument, NULL, 'r'},
>           {"schema-only", no_argument, NULL, 's'},
>           {"superuser", required_argument, NULL, 'S'},
> +         {"tablespaces-only", no_argument, NULL, 't'},
>           {"username", required_argument, NULL, 'U'},
>           {"verbose", no_argument, NULL, 'v'},
> +         {"password", no_argument, NULL, 'W'},
>           {"no-privileges", no_argument, NULL, 'x'},
>           {"no-acl", no_argument, NULL, 'x'},
>
> ***************
> *** 161,167 ****
>
>       pgdumpopts = createPQExpBuffer();
>
> !     while ((c = getopt_long(argc, argv, "acdDgh:ioOp:sS:U:vWxX:", long_options, &optindex)) != -1)
>       {
>           switch (c)
>           {
> --- 165,171 ----
>
>       pgdumpopts = createPQExpBuffer();
>
> !     while ((c = getopt_long(argc, argv, "acdDgh:ioOp:rsS:tU:vWxX:", long_options, &optindex)) != -1)
>       {
>           switch (c)
>           {
> ***************
> *** 214,219 ****
> --- 218,227 ----
>                   appendPQExpBuffer(pgdumpopts, " -p \"%s\"", pgport);
>   #endif
>                   break;
> +
> +             case 'r':
> +                 roles_only = true;
> +                 break;
>
>               case 's':
>                   schema_only = true;
> ***************
> *** 227,232 ****
> --- 235,244 ----
>                   appendPQExpBuffer(pgdumpopts, " -S \"%s\"", optarg);
>   #endif
>                   break;
> +
> +             case 't':
> +                 tablespaces_only = true;
> +                 break;
>
>               case 'U':
>                   pguser = optarg;
> ***************
> *** 295,300 ****
> --- 307,340 ----
>                   progname);
>           exit(1);
>       }
> +
> +     /* Make sure the user hasn't specified a mix of globals-only options */
> +     if (globals_only && roles_only)
> +     {
> +         fprintf(stderr, _("%s: --globals-only and --roles-only cannot be used together\n"),
> +                 progname);
> +         fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
> +                 progname);
> +         exit(1);
> +     }
> +
> +     if (globals_only && tablespaces_only)
> +     {
> +         fprintf(stderr, _("%s: --globals-only and --tablespaces-only cannot be used together\n"),
> +                 progname);
> +         fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
> +                 progname);
> +         exit(1);
> +     }
> +
> +     if (roles_only && tablespaces_only)
> +     {
> +         fprintf(stderr, _("%s: --roles-only and --tablespaces-only cannot be used together\n"),
> +                 progname);
> +         fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
> +                 progname);
> +         exit(1);
> +     }
>
>       /*
>        * First try to connect to database "postgres", and failing that
> ***************
> *** 332,356 ****
>               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)
>               dumpCreateDB(conn);
>       }
>
> !     if (!globals_only)
>           dumpDatabases(conn);
>
>       PQfinish(conn);
> --- 372,402 ----
>               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 && !roles_only && !tablespaces_only)
>               dumpCreateDB(conn);
>       }
>
> !     if (!globals_only && !roles_only && !tablespaces_only)
>           dumpDatabases(conn);
>
>       PQfinish(conn);
> ***************
> *** 381,391 ****
>       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"));
>       printf(_("  -S, --superuser=NAME     specify the superuser user name to use in the dump\n"));
>       printf(_("  -x, --no-privileges      do not dump privileges (grant/revoke)\n"));
>       printf(_("  --disable-dollar-quoting\n"
>                "                           disable dollar quoting, use SQL standard quoting\n"));
> --- 427,439 ----
>       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(_("  -r, --roles-only         dump only roles, no databases or tablespaces.\n"));
>       printf(_("  -s, --schema-only        dump only the schema, no data\n"));
>       printf(_("  -S, --superuser=NAME     specify the superuser user name to use in the dump\n"));
> +     printf(_("  -t, --tablespaces-only   dump only tablespaces, no databases or roles.\n"));
>       printf(_("  -x, --no-privileges      do not dump privileges (grant/revoke)\n"));
>       printf(_("  --disable-dollar-quoting\n"
>                "                           disable dollar quoting, use SQL standard quoting\n"));

>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings

--
  Bruce Momjian   bruce@momjian.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [PATCHES] COPY with no WAL, v2
Next
From: Bruce Momjian
Date:
Subject: Re: pg_dumpall default database