Remove the -d and -D options of pg_dump and pg_dumpall. The functionality

is still available, but you must now write the long equivalent --inserts
or --column-inserts.  This change is made to eliminate confusion with the
use of -d to specify a database name in most other Postgres client programs.
Original patch by Greg Mullane, modified per subsequent discussion.
This commit is contained in:
Tom Lane 2009-03-22 16:44:26 +00:00
parent 0fd85d7879
commit 5698f6b925
4 changed files with 124 additions and 127 deletions

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.112 2009/03/04 11:57:00 petere Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.113 2009/03/22 16:44:26 tgl Exp $
PostgreSQL documentation
-->
@ -175,46 +175,6 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>-d</option></term>
<term><option>--inserts</option></term>
<listitem>
<para>
Dump data as <command>INSERT</command> commands (rather
than <command>COPY</command>). This will make restoration very slow;
it is mainly useful for making dumps that can be loaded into
non-<productname>PostgreSQL</productname> databases.
Also, since this option generates a separate command for each row,
an error in reloading a row causes only that row to be lost rather
than the entire table contents.
Note that
the restore might fail altogether if you have rearranged column order.
The <option>-D</option> option is safe against column order changes,
though even slower.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-D</option></term>
<term><option>--column-inserts</option></term>
<term><option>--attribute-inserts</option></term>
<listitem>
<para>
Dump data as <command>INSERT</command> commands with explicit
column names (<literal>INSERT INTO
<replaceable>table</replaceable>
(<replaceable>column</replaceable>, ...) VALUES
...</literal>). This will make restoration very slow; it is mainly
useful for making dumps that can be loaded into
non-<productname>PostgreSQL</productname> databases.
Also, since this option generates a separate command for each row,
an error in reloading a row causes only that row to be lost rather
than the entire table contents.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-E <replaceable class="parameter">encoding</replaceable></option></term>
<term><option>--encoding=<replaceable class="parameter">encoding</replaceable></option></term>
@ -562,6 +522,44 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>--inserts</option></term>
<listitem>
<para>
Dump data as <command>INSERT</command> commands (rather
than <command>COPY</command>). This will make restoration very slow;
it is mainly useful for making dumps that can be loaded into
non-<productname>PostgreSQL</productname> databases.
Also, since this option generates a separate command for each row,
an error in reloading a row causes only that row to be lost rather
than the entire table contents.
Note that
the restore might fail altogether if you have rearranged column order.
The <option>--column-inserts</option> option is safe against column
order changes, though even slower.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--column-inserts</option></term>
<term><option>--attribute-inserts</option></term>
<listitem>
<para>
Dump data as <command>INSERT</command> commands with explicit
column names (<literal>INSERT INTO
<replaceable>table</replaceable>
(<replaceable>column</replaceable>, ...) VALUES
...</literal>). This will make restoration very slow; it is mainly
useful for making dumps that can be loaded into
non-<productname>PostgreSQL</productname> databases.
Also, since this option generates a separate command for each row,
an error in reloading a row causes only that row to be lost rather
than the entire table contents.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--disable-dollar-quoting</></term>
<listitem>
@ -814,11 +812,10 @@ CREATE DATABASE foo WITH TEMPLATE template0;
</para>
<para>
<application>pg_dump</application> has a limitation; when a
data-only dump is chosen and the option <option>--disable-triggers</>
When a data-only dump is chosen and the option <option>--disable-triggers</>
is used, <application>pg_dump</application> emits commands
to disable triggers on user tables before inserting the data
and commands to re-enable them after the data has been
to disable triggers on user tables before inserting the data,
and then commands to re-enable them after the data has been
inserted. If the restore is stopped in the middle, the system
catalogs might be left in the wrong state.
</para>
@ -846,12 +843,19 @@ CREATE DATABASE foo WITH TEMPLATE template0;
<para>
Because <application>pg_dump</application> is used to transfer data
to newer versions of <productname>PostgreSQL</>, the output of
<application>pg_dump</application> can be loaded into
newer <productname>PostgreSQL</> databases. It also can read older
<productname>PostgreSQL</> databases. However, it usually cannot
read newer <productname>PostgreSQL</> databases or produce dump output
that can be loaded into older database versions. To do this, manual
editing of the dump file might be required.
<application>pg_dump</application> can be expected to load into
<productname>PostgreSQL</> server versions newer than
<application>pg_dump</>'s version. <application>pg_dump</> can also
dump from <productname>PostgreSQL</> servers older than its own version.
(Currently, servers back to version 7.0 are supported.)
However, <application>pg_dump</> cannot dump from
<productname>PostgreSQL</> servers newer than its own major version;
it will refuse to even try, rather than risk making an invalid dump.
Also, it is not guaranteed that <application>pg_dump</>'s output can
be loaded into a server of an older major version &mdash; not even if the
dump was taken from a server of that version. Loading a dump file
into an older server may require manual editing of the dump file
to remove syntax not understood by the older server.
</para>
</refsect1>

View File

@ -1,5 +1,5 @@
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.78 2009/03/04 11:57:00 petere Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.79 2009/03/22 16:44:26 tgl Exp $
PostgreSQL documentation
-->
@ -98,38 +98,6 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>-d</option></term>
<term><option>--inserts</option></term>
<listitem>
<para>
Dump data as <command>INSERT</command> commands (rather
than <command>COPY</command>). This will make restoration very slow;
it is mainly useful for making dumps that can be loaded into
non-<productname>PostgreSQL</productname> databases. Note that
the restore might fail altogether if you have rearranged column order.
The <option>-D</option> option is safer, though even slower.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-D</option></term>
<term><option>--column-inserts</option></term>
<term><option>--attribute-inserts</option></term>
<listitem>
<para>
Dump data as <command>INSERT</command> commands with explicit
column names (<literal>INSERT INTO
<replaceable>table</replaceable>
(<replaceable>column</replaceable>, ...) VALUES
...</literal>). This will make restoration very slow; it is mainly
useful for making dumps that can be loaded into
non-<productname>PostgreSQL</productname> databases.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-f <replaceable class="parameter">filename</replaceable></option></term>
<term><option>--file=<replaceable class="parameter">filename</replaceable></option></term>
@ -302,6 +270,37 @@ PostgreSQL documentation
</listitem>
</varlistentry>
<varlistentry>
<term><option>--inserts</option></term>
<listitem>
<para>
Dump data as <command>INSERT</command> commands (rather
than <command>COPY</command>). This will make restoration very slow;
it is mainly useful for making dumps that can be loaded into
non-<productname>PostgreSQL</productname> databases. Note that
the restore might fail altogether if you have rearranged column order.
The <option>--column-inserts</option> option is safer, though even
slower.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--column-inserts</option></term>
<term><option>--attribute-inserts</option></term>
<listitem>
<para>
Dump data as <command>INSERT</command> commands with explicit
column names (<literal>INSERT INTO
<replaceable>table</replaceable>
(<replaceable>column</replaceable>, ...) VALUES
...</literal>). This will make restoration very slow; it is mainly
useful for making dumps that can be loaded into
non-<productname>PostgreSQL</productname> databases.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--disable-dollar-quoting</></term>
<listitem>
@ -511,7 +510,7 @@ PostgreSQL documentation
<para>
<application>pg_dumpall</application> requires all needed
tablespace directories to exist before the restore or
tablespace directories to exist before the restore, else
database creation will fail for databases in non-default
locations.
</para>

View File

@ -12,7 +12,7 @@
* by PostgreSQL
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.529 2009/03/17 10:10:13 petere Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.530 2009/03/22 16:44:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -67,8 +67,6 @@ Archive *g_fout; /* the script file */
PGconn *g_conn; /* the database connection */
/* various user-settable parameters */
bool dumpInserts; /* dump data using proper insert strings */
bool attrNames; /* put attr names into insert strings */
bool schemaOnly;
bool dataOnly;
bool aclsSkip;
@ -99,8 +97,6 @@ static SimpleOidList table_exclude_oids = {NULL, NULL};
/* default, if no "inclusion" switches appear, is to dump everything */
static bool include_everything = true;
static int binary_upgrade = 0;
char g_opaque_type[10]; /* name for the opaque type */
/* placeholders for the delimiters for comments */
@ -113,8 +109,11 @@ static const CatalogId nilCatalogId = {0, 0};
static NamespaceInfo *g_namespaces;
static int g_numNamespaces;
/* flag to turn on/off dollar quoting */
/* flags for various command-line long options */
static int binary_upgrade = 0;
static int disable_dollar_quoting = 0;
static int dump_inserts = 0;
static int column_inserts = 0;
static void help(const char *progname);
@ -239,16 +238,12 @@ main(int argc, char **argv)
static int use_setsessauth = 0;
struct option long_options[] = {
{"binary-upgrade", no_argument, &binary_upgrade, 1}, /* not documented */
{"data-only", no_argument, NULL, 'a'},
{"blobs", no_argument, NULL, 'b'},
{"clean", no_argument, NULL, 'c'},
{"create", no_argument, NULL, 'C'},
{"file", required_argument, NULL, 'f'},
{"format", required_argument, NULL, 'F'},
{"inserts", no_argument, NULL, 'd'},
{"attribute-inserts", no_argument, NULL, 'D'},
{"column-inserts", no_argument, NULL, 'D'},
{"host", required_argument, NULL, 'h'},
{"ignore-version", no_argument, NULL, 'i'},
{"no-reconnect", no_argument, NULL, 'R'},
@ -275,8 +270,12 @@ main(int argc, char **argv)
/*
* the following options don't have an equivalent short option letter
*/
{"attribute-inserts", no_argument, &column_inserts, 1},
{"binary-upgrade", no_argument, &binary_upgrade, 1},
{"column-inserts", no_argument, &column_inserts, 1},
{"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1},
{"disable-triggers", no_argument, &disable_triggers, 1},
{"inserts", no_argument, &dump_inserts, 1},
{"lock-wait-timeout", required_argument, NULL, 2},
{"no-tablespaces", no_argument, &outputNoTablespaces, 1},
{"role", required_argument, NULL, 3},
@ -293,7 +292,7 @@ main(int argc, char **argv)
g_comment_end[0] = '\0';
strcpy(g_opaque_type, "opaque");
dataOnly = schemaOnly = dumpInserts = attrNames = false;
dataOnly = schemaOnly = false;
lockWaitTimeout = NULL;
progname = get_progname(argv[0]);
@ -316,7 +315,7 @@ main(int argc, char **argv)
}
}
while ((c = getopt_long(argc, argv, "abcCdDE:f:F:h:in:N:oOp:RsS:t:T:U:vwWxX:Z:",
while ((c = getopt_long(argc, argv, "abcCE:f:F:h:in:N:oOp:RsS:t:T:U:vwWxX:Z:",
long_options, &optindex)) != -1)
{
switch (c)
@ -337,16 +336,6 @@ main(int argc, char **argv)
outputCreate = 1;
break;
case 'd': /* dump data as proper insert strings */
dumpInserts = true;
break;
case 'D': /* dump data as proper insert strings with
* attr names */
dumpInserts = true;
attrNames = true;
break;
case 'E': /* Dump encoding */
dumpencoding = optarg;
break;
@ -484,6 +473,10 @@ main(int argc, char **argv)
if (optind < argc)
dbname = argv[optind];
/* --column-inserts implies --inserts */
if (column_inserts)
dump_inserts = 1;
if (dataOnly && schemaOnly)
{
write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used together\n");
@ -496,9 +489,9 @@ main(int argc, char **argv)
exit(1);
}
if (dumpInserts == true && oids == true)
if (dump_inserts && oids)
{
write_msg(NULL, "options -d/-D/--inserts/--column-inserts and -o/--oids cannot be used together\n");
write_msg(NULL, "options --inserts/--column-inserts and -o/--oids cannot be used together\n");
write_msg(NULL, "(The INSERT command cannot set OIDs.)\n");
exit(1);
}
@ -815,8 +808,6 @@ help(const char *progname)
printf(_(" -b, --blobs include large objects in dump\n"));
printf(_(" -c, --clean clean (drop) database objects before recreating\n"));
printf(_(" -C, --create include commands to create database in dump\n"));
printf(_(" -d, --inserts dump data as INSERT commands, rather than COPY\n"));
printf(_(" -D, --column-inserts dump data as INSERT commands with column names\n"));
printf(_(" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
printf(_(" -n, --schema=SCHEMA dump the named schema(s) only\n"));
printf(_(" -N, --exclude-schema=SCHEMA do NOT dump the named schema(s)\n"));
@ -829,6 +820,8 @@ help(const char *progname)
printf(_(" -T, --exclude-table=TABLE do NOT dump the named table(s)\n"));
printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
printf(_(" --binary-upgrade for use by upgrade utilities only\n"));
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
printf(_(" --column-inserts dump data as INSERT commands with column names\n"));
printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
@ -1269,7 +1262,7 @@ dumpTableData_insert(Archive *fout, void *dcontext)
archprintf(fout, "DEFAULT VALUES;\n");
continue;
}
if (attrNames == true)
if (column_inserts)
{
resetPQExpBuffer(q);
appendPQExpBuffer(q, "(");
@ -1376,7 +1369,7 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
DataDumperPtr dumpFn;
char *copyStmt;
if (!dumpInserts)
if (!dump_inserts)
{
/* Dump/restore using COPY */
dumpFn = dumpTableData_copy;

View 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.119 2009/03/04 11:57:00 petere Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.120 2009/03/22 16:44:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -62,8 +62,11 @@ static bool output_clean = false;
static bool skip_acls = false;
static bool verbose = false;
static int binary_upgrade = 0;
static int column_inserts = 0;
static int disable_dollar_quoting = 0;
static int disable_triggers = 0;
static int inserts = 0;
static int no_tablespaces = 0;
static int use_setsessauth = 0;
static int server_version;
@ -71,7 +74,6 @@ static int server_version;
static FILE *OPF;
static char *filename = NULL;
static int binary_upgrade = 0;
int
main(int argc, char *argv[])
@ -94,12 +96,8 @@ main(int argc, char *argv[])
ret;
struct option long_options[] = {
{"binary-upgrade", no_argument, &binary_upgrade, 1}, /* not documented */
{"data-only", no_argument, NULL, 'a'},
{"clean", no_argument, NULL, 'c'},
{"inserts", no_argument, NULL, 'd'},
{"attribute-inserts", no_argument, NULL, 'D'},
{"column-inserts", no_argument, NULL, 'D'},
{"file", required_argument, NULL, 'f'},
{"globals-only", no_argument, NULL, 'g'},
{"host", required_argument, NULL, 'h'},
@ -122,8 +120,12 @@ main(int argc, char *argv[])
/*
* the following options don't have an equivalent short option letter
*/
{"attribute-inserts", no_argument, &column_inserts, 1},
{"binary-upgrade", no_argument, &binary_upgrade, 1},
{"column-inserts", no_argument, &column_inserts, 1},
{"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1},
{"disable-triggers", no_argument, &disable_triggers, 1},
{"inserts", no_argument, &inserts, 1},
{"lock-wait-timeout", required_argument, NULL, 2},
{"no-tablespaces", no_argument, &no_tablespaces, 1},
{"role", required_argument, NULL, 3},
@ -178,7 +180,7 @@ main(int argc, char *argv[])
pgdumpopts = createPQExpBuffer();
while ((c = getopt_long(argc, argv, "acdDf:gh:il:oOp:rsS:tU:vwWxX:", long_options, &optindex)) != -1)
while ((c = getopt_long(argc, argv, "acf:gh:il:oOp:rsS:tU:vwWxX:", long_options, &optindex)) != -1)
{
switch (c)
{
@ -191,11 +193,6 @@ main(int argc, char *argv[])
output_clean = true;
break;
case 'd':
case 'D':
appendPQExpBuffer(pgdumpopts, " -%c", c);
break;
case 'f':
filename = optarg;
appendPQExpBuffer(pgdumpopts, " -f ");
@ -321,10 +318,14 @@ main(int argc, char *argv[])
/* Add long options to the pg_dump argument list */
if (binary_upgrade)
appendPQExpBuffer(pgdumpopts, " --binary-upgrade");
if (column_inserts)
appendPQExpBuffer(pgdumpopts, " --column-inserts");
if (disable_dollar_quoting)
appendPQExpBuffer(pgdumpopts, " --disable-dollar-quoting");
if (disable_triggers)
appendPQExpBuffer(pgdumpopts, " --disable-triggers");
if (inserts)
appendPQExpBuffer(pgdumpopts, " --inserts");
if (no_tablespaces)
appendPQExpBuffer(pgdumpopts, " --no-tablespaces");
if (use_setsessauth)
@ -511,8 +512,6 @@ help(void)
printf(_("\nOptions controlling the output content:\n"));
printf(_(" -a, --data-only dump only the data, not the schema\n"));
printf(_(" -c, --clean clean (drop) databases before recreating\n"));
printf(_(" -d, --inserts dump data as INSERT commands, rather than COPY\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"));
@ -522,6 +521,8 @@ help(void)
printf(_(" -t, --tablespaces-only dump only tablespaces, no databases or roles\n"));
printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
printf(_(" --binary-upgrade for use by upgrade utilities only\n"));
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
printf(_(" --column-inserts dump data as INSERT commands with column names\n"));
printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
printf(_(" --disable-triggers disable triggers during data-only restore\n"));
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));