</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>
</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>
</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>
<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 — 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>
</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>
</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>
<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>
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;
/* 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 */
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);
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'},
/*
* 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},
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]);
}
}
- 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)
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;
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");
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);
}
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"));
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"));
archprintf(fout, "DEFAULT VALUES;\n");
continue;
}
- if (attrNames == true)
+ if (column_inserts)
{
resetPQExpBuffer(q);
appendPQExpBuffer(q, "(");
DataDumperPtr dumpFn;
char *copyStmt;
- if (!dumpInserts)
+ if (!dump_inserts)
{
/* Dump/restore using COPY */
dumpFn = dumpTableData_copy;
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;
static FILE *OPF;
static char *filename = NULL;
-static int binary_upgrade = 0;
int
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'},
/*
* 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},
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)
{
output_clean = true;
break;
- case 'd':
- case 'D':
- appendPQExpBuffer(pgdumpopts, " -%c", c);
- break;
-
case 'f':
filename = optarg;
appendPQExpBuffer(pgdumpopts, " -f ");
/* 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)
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"));
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"));