Commit a0db74a3 authored by Bruce Momjian's avatar Bruce Momjian

This patch adds the following options to pg_dumpall, to be passed to

pg_dump:

-S, --superuser=NAME

-O, --no-owner

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

-X disable-triggers, --disable-triggers

Christopher Kings-Lynne
parent 96b9dc1a
<!-- <!--
$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 PostgreSQL documentation
--> -->
...@@ -176,6 +176,25 @@ PostgreSQL documentation ...@@ -176,6 +176,25 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </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> <varlistentry>
<term><option>-s</option></term> <term><option>-s</option></term>
<term><option>--schema-only</option></term> <term><option>--schema-only</option></term>
...@@ -186,6 +205,19 @@ PostgreSQL documentation ...@@ -186,6 +205,19 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </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> <varlistentry>
<term><option>-v</></term> <term><option>-v</></term>
<term><option>--verbose</></term> <term><option>--verbose</></term>
...@@ -209,6 +241,50 @@ PostgreSQL documentation ...@@ -209,6 +241,50 @@ PostgreSQL documentation
</para> </para>
</listitem> </listitem>
</varlistentry> </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> </variablelist>
</para> </para>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * 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 ...@@ -59,7 +59,6 @@ static PGconn *connectDatabase(const char *dbname, const char *pghost, const cha
const char *pguser, bool require_password); const char *pguser, bool require_password);
static PGresult *executeQuery(PGconn *conn, const char *query); static PGresult *executeQuery(PGconn *conn, const char *query);
char pg_dump_bin[MAXPGPATH]; char pg_dump_bin[MAXPGPATH];
PQExpBuffer pgdumpopts; PQExpBuffer pgdumpopts;
bool output_clean = false; bool output_clean = false;
...@@ -67,7 +66,10 @@ bool skip_acls = false; ...@@ -67,7 +66,10 @@ bool skip_acls = false;
bool verbose = false; bool verbose = false;
int server_version; int server_version;
/* flags for -X long options */
int disable_dollar_quoting = 0;
int disable_triggers = 0;
int use_setsessauth = 0;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
...@@ -92,13 +94,24 @@ main(int argc, char *argv[]) ...@@ -92,13 +94,24 @@ main(int argc, char *argv[])
{"host", required_argument, NULL, 'h'}, {"host", required_argument, NULL, 'h'},
{"ignore-version", no_argument, NULL, 'i'}, {"ignore-version", no_argument, NULL, 'i'},
{"oids", no_argument, NULL, 'o'}, {"oids", no_argument, NULL, 'o'},
{"no-owner", no_argument, NULL, 'O'},
{"port", required_argument, NULL, 'p'}, {"port", required_argument, NULL, 'p'},
{"password", no_argument, NULL, 'W'}, {"password", no_argument, NULL, 'W'},
{"schema-only", no_argument, NULL, 's'}, {"schema-only", no_argument, NULL, 's'},
{"superuser", required_argument, NULL, 'S'},
{"username", required_argument, NULL, 'U'}, {"username", required_argument, NULL, 'U'},
{"verbose", no_argument, NULL, 'v'}, {"verbose", no_argument, NULL, 'v'},
{"no-privileges", no_argument, NULL, 'x'}, {"no-privileges", no_argument, NULL, 'x'},
{"no-acl", 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} {NULL, 0, NULL, 0}
}; };
...@@ -142,7 +155,7 @@ main(int argc, char *argv[]) ...@@ -142,7 +155,7 @@ main(int argc, char *argv[])
pgdumpopts = createPQExpBuffer(); 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) switch (c)
{ {
...@@ -174,6 +187,10 @@ main(int argc, char *argv[]) ...@@ -174,6 +187,10 @@ main(int argc, char *argv[])
appendPQExpBuffer(pgdumpopts, " -%c", c); appendPQExpBuffer(pgdumpopts, " -%c", c);
break; break;
case 'O':
appendPQExpBuffer(pgdumpopts, " -O");
break;
case 'p': case 'p':
pgport = optarg; pgport = optarg;
appendPQExpBuffer(pgdumpopts, " -p '%s'", pgport); appendPQExpBuffer(pgdumpopts, " -p '%s'", pgport);
...@@ -184,6 +201,10 @@ main(int argc, char *argv[]) ...@@ -184,6 +201,10 @@ main(int argc, char *argv[])
appendPQExpBuffer(pgdumpopts, " -s"); appendPQExpBuffer(pgdumpopts, " -s");
break; break;
case 'S':
appendPQExpBuffer(pgdumpopts, " -S '%s'", optarg);
break;
case 'U': case 'U':
pguser = optarg; pguser = optarg;
appendPQExpBuffer(pgdumpopts, " -U '%s'", pguser); appendPQExpBuffer(pgdumpopts, " -U '%s'", pguser);
...@@ -204,12 +225,40 @@ main(int argc, char *argv[]) ...@@ -204,12 +225,40 @@ main(int argc, char *argv[])
appendPQExpBuffer(pgdumpopts, " -x"); appendPQExpBuffer(pgdumpopts, " -x");
break; 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: default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1); 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) if (optind < argc)
{ {
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
...@@ -270,9 +319,15 @@ help(void) ...@@ -270,9 +319,15 @@ help(void)
printf(_(" -i, --ignore-version proceed even when server version mismatches\n" printf(_(" -i, --ignore-version proceed even when server version mismatches\n"
" pg_dumpall version\n")); " pg_dumpall version\n"));
printf(_(" -s, --schema-only dump only the schema, no data\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, --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(_(" -v, --verbose verbose mode\n"));
printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\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(_(" --help show this help, then exit\n"));
printf(_(" --version output version information, then exit\n")); printf(_(" --version output version information, then exit\n"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment