OSDN Git Service

This patch adds the following options to pg_dumpall, to be passed to
authorBruce Momjian <bruce@momjian.us>
Mon, 12 Jul 2004 14:35:45 +0000 (14:35 +0000)
committerBruce Momjian <bruce@momjian.us>
Mon, 12 Jul 2004 14:35:45 +0000 (14:35 +0000)
pg_dump:

-S, --superuser=NAME

-O, --no-owner

-X disable-dollar-quoting, --disable-dollar-quoting

-X disable-triggers, --disable-triggers

Christopher Kings-Lynne

doc/src/sgml/ref/pg_dumpall.sgml
src/bin/pg_dump/pg_dumpall.c

index befd73b..efc35f7 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.44 2004/06/07 20:35:57 momjian Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.45 2004/07/12 14:35:43 momjian Exp $
 PostgreSQL documentation
 -->
 
@@ -177,6 +177,25 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
+      <term><option>-O</></term>
+      <term><option>--no-owner</option></term>
+      <listitem>
+       <para>
+        Do not output commands to set
+       ownership of objects to match the original database.
+       By default, <application>pg_dumpall</application> issues
+       <command>SET SESSION AUTHORIZATION</command>
+       statements to set ownership of created schema elements.
+       These statements
+       will fail when the script is run unless it is started by a superuser
+       (or the same user that owns all of the objects in the script).
+       To make a script that can be restored by any user, but will give
+       that user ownership of all the objects, specify <option>-O</>.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>-s</option></term>
       <term><option>--schema-only</option></term>
       <listitem>
@@ -187,6 +206,19 @@ PostgreSQL documentation
      </varlistentry>
 
      <varlistentry>
+      <term><option>-S <replaceable class="parameter">username</replaceable></option></term>
+      <term><option>--superuser=<replaceable class="parameter">username</replaceable></option></term>
+      <listitem>
+       <para>
+        Specify the superuser user name to use when disabling triggers.
+       This is only relevant if <option>--disable-triggers</> is used.
+       (Usually, it's better to leave this out, and instead start the
+       resulting script as superuser.)
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
       <term><option>-v</></term>
       <term><option>--verbose</></term>
       <listitem>
@@ -209,6 +241,50 @@ PostgreSQL documentation
        </para>
       </listitem>
      </varlistentry>
+
+     <varlistentry>
+      <term><option>-X disable-dollar-quoting</></term>
+      <term><option>--disable-dollar-quoting</></term>
+      <listitem>
+       <para>
+        This option disables the use of dollar quoting for function bodies,
+        and forces them to be quoted using SQL standard string syntax.
+       </para>
+     </listitem>
+    </varlistentry>
+
+     <varlistentry>
+      <term><option>-X disable-triggers</></term>
+      <term><option>--disable-triggers</></term>
+      <listitem>
+       <para>
+        This option is only relevant when creating a data-only dump.
+        It instructs <application>pg_dumpall</application> to include commands
+        to temporarily disable triggers on the target tables while
+        the data is reloaded.  Use this if you have referential
+        integrity checks or other triggers on the tables that you
+        do not want to invoke during data reload.
+       </para>
+
+       <para>
+        Presently, the commands emitted for <option>--disable-triggers</>
+        must be done as superuser.  So, you should also specify
+        a superuser name with <option>-S</>, or preferably be careful to
+        start the resulting script as a superuser.
+       </para>
+      </listitem>
+     </varlistentry>
+
+     <varlistentry>
+      <term><option>-X use-set-session-authorization</></term>
+      <term><option>--use-set-session-authorization</></term>
+      <listitem>
+       <para>
+        This option is obsolete but still accepted for backwards
+        compatibility with <application>pg_dump</application>.
+       </para>
+      </listitem>
+     </varlistentry>
     </variablelist>
    </para>
 
index 4f1270f..d24d6db 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.43 2004/06/21 13:36:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.44 2004/07/12 14:35:45 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -59,7 +59,6 @@ static PGconn *connectDatabase(const char *dbname, const char *pghost, const cha
                                const char *pguser, bool require_password);
 static PGresult *executeQuery(PGconn *conn, const char *query);
 
-
 char       pg_dump_bin[MAXPGPATH];
 PQExpBuffer pgdumpopts;
 bool           output_clean = false;
@@ -67,7 +66,10 @@ bool         skip_acls = false;
 bool           verbose = false;
 int                    server_version;
 
-
+/* flags for -X long options */
+int    disable_dollar_quoting = 0;
+int    disable_triggers = 0;
+int    use_setsessauth = 0;
 
 int
 main(int argc, char *argv[])
@@ -92,13 +94,24 @@ main(int argc, char *argv[])
                {"host", required_argument, NULL, 'h'},
                {"ignore-version", no_argument, NULL, 'i'},
                {"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'},
+
+               /*
+                * the following options don't have an equivalent short option
+                * letter, but are available as '-X long-name'
+                */
+               {"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1},
+               {"disable-triggers", no_argument, &disable_triggers, 1},
+               {"use-set-session-authorization", no_argument, &use_setsessauth, 1},
+
                {NULL, 0, NULL, 0}
        };
 
@@ -142,7 +155,7 @@ main(int argc, char *argv[])
 
        pgdumpopts = createPQExpBuffer();
 
-       while ((c = getopt_long(argc, argv, "acdDgh:iop:sU:vWx", long_options, &optindex)) != -1)
+       while ((c = getopt_long(argc, argv, "acdDgh:ioOp:sS:U:vWxX:", long_options, &optindex)) != -1)
        {
                switch (c)
                {
@@ -174,6 +187,10 @@ main(int argc, char *argv[])
                                appendPQExpBuffer(pgdumpopts, " -%c", c);
                                break;
 
+                       case 'O':
+                               appendPQExpBuffer(pgdumpopts, " -O");
+                               break;
+
                        case 'p':
                                pgport = optarg;
                                appendPQExpBuffer(pgdumpopts, " -p '%s'", pgport);
@@ -184,6 +201,10 @@ main(int argc, char *argv[])
                                appendPQExpBuffer(pgdumpopts, " -s");
                                break;
 
+                       case 'S':
+                               appendPQExpBuffer(pgdumpopts, " -S '%s'", optarg);
+                               break;
+
                        case 'U':
                                pguser = optarg;
                                appendPQExpBuffer(pgdumpopts, " -U '%s'", pguser);
@@ -204,12 +225,40 @@ main(int argc, char *argv[])
                                appendPQExpBuffer(pgdumpopts, " -x");
                                break;
 
+                       case 'X':
+                               if (strcmp(optarg, "disable-dollar-quoting") == 0)
+                                       appendPQExpBuffer(pgdumpopts, " -X disable-dollar-quoting");
+                               else if (strcmp(optarg, "disable-triggers") == 0)
+                                       appendPQExpBuffer(pgdumpopts, " -X disable-triggers");
+                               else if (strcmp(optarg, "use-set-session-authorization") == 0)
+                                       /* no-op, still allowed for compatibility */ ;
+                               else
+                               {
+                                       fprintf(stderr,
+                                                       _("%s: invalid -X option -- %s\n"),
+                                                       progname, optarg);
+                                       fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+                                       exit(1);
+                               }
+                               break;
+
+                       case 0:
+                               break;
+
                        default:
                                fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
                                exit(1);
                }
        }
 
+       /*  Add long options to the pg_dump argument list */
+       if (disable_dollar_quoting)
+               appendPQExpBuffer(pgdumpopts, " -X disable-dollar-quoting");
+       if (disable_triggers)
+               appendPQExpBuffer(pgdumpopts, " -X disable-triggers");
+       if (use_setsessauth)
+               /* no-op, still allowed for compatibility */ ;
+               
        if (optind < argc)
        {
                fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
@@ -270,9 +319,15 @@ help(void)
        printf(_("  -i, --ignore-version     proceed even when server version mismatches\n"
                         "                           pg_dumpall version\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(_("  -o, --oids               include OIDs in dump\n"));
+       printf(_("  -O, --no-owner           do not output commands to set object ownership\n"));
        printf(_("  -v, --verbose            verbose mode\n"));
        printf(_("  -x, --no-privileges      do not dump privileges (grant/revoke)\n"));
+       printf(_("  -X disable-dollar-quoting, --disable-dollar-quoting\n"
+                        "                           disable dollar quoting, use SQL standard quoting\n"));
+       printf(_("  -X disable-triggers, --disable-triggers\n"
+                        "                           disable triggers during data-only restore\n"));
        printf(_("  --help                   show this help, then exit\n"));
        printf(_("  --version                output version information, then exit\n"));