Remove the -d and -D options of pg_dump and pg_dumpall. The functionality
authorTom Lane
Sun, 22 Mar 2009 16:44:26 +0000 (16:44 +0000)
committerTom Lane
Sun, 22 Mar 2009 16:44:26 +0000 (16:44 +0000)
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.

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

index 11fa5fbe601e47a64f5ab810e3e9fdb7167fa876..0f5068ef32e50240c00ad9c113d177cde3ab5656 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -175,46 +175,6 @@ PostgreSQL documentation
       
      
 
-     
-      
-      
-      
-       
-        Dump data as INSERT commands (rather
-        than COPY).  This will make restoration very slow;
-        it is mainly useful for making dumps that can be loaded into
-        non-PostgreSQL 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 is safe against column order changes,
-        though even slower.
-       
-      
-     
-
-     
-      
-      
-      
-      
-       
-        Dump data as INSERT commands with explicit
-        column names (INSERT INTO
-        table
-        (column, ...) VALUES
-        ...).  This will make restoration very slow; it is mainly
-        useful for making dumps that can be loaded into
-        non-PostgreSQL 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.
-       
-      
-     
-
      
       
       
@@ -562,6 +522,44 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+       
+        Dump data as INSERT commands (rather
+        than COPY).  This will make restoration very slow;
+        it is mainly useful for making dumps that can be loaded into
+        non-PostgreSQL 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 is safe against column
+        order changes, though even slower.
+       
+      
+     
+
+     
+      
+      
+      
+       
+        Dump data as INSERT commands with explicit
+        column names (INSERT INTO
+        table
+        (column, ...) VALUES
+        ...).  This will make restoration very slow; it is mainly
+        useful for making dumps that can be loaded into
+        non-PostgreSQL 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.
+       
+      
+     
+
      
       
       
@@ -814,11 +812,10 @@ CREATE DATABASE foo WITH TEMPLATE template0;
   
 
   
-   pg_dump has a limitation; when a
-   data-only dump is chosen and the option 
+   When a data-only dump is chosen and the option 
    is used, pg_dump 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.
   
@@ -846,12 +843,19 @@ CREATE DATABASE foo WITH TEMPLATE template0;
   
    Because pg_dump is used to transfer data
    to newer versions of PostgreSQL, the output of
-   pg_dump can be loaded into
-   newer PostgreSQL databases.  It also can read older
-   PostgreSQL databases.  However, it usually cannot
-   read newer 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.
+   pg_dump can be expected to load into
+   PostgreSQL server versions newer than
+   pg_dump's version.  pg_dump can also
+   dump from PostgreSQL servers older than its own version.
+   (Currently, servers back to version 7.0 are supported.)
+   However, pg_dump cannot dump from
+   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 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.
   
  
 
index 6a91c05e7803054e3028e6b891915c0ee8b56541..3c341bad1a683079e297b81ae671edde6b2d96ca 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -98,38 +98,6 @@ PostgreSQL documentation
       
      
 
-     
-      
-      
-      
-       
-        Dump data as INSERT commands (rather
-        than COPY).  This will make restoration very slow;
-        it is mainly useful for making dumps that can be loaded into
-        non-PostgreSQL databases.  Note that
-        the restore might fail altogether if you have rearranged column order.
-        The  option is safer, though even slower.
-       
-      
-     
-
-     
-      
-      
-      
-      
-       
-        Dump data as INSERT commands with explicit
-        column names (INSERT INTO
-        table
-        (column, ...) VALUES
-        ...).  This will make restoration very slow; it is mainly
-        useful for making dumps that can be loaded into
-        non-PostgreSQL databases.
-       
-      
-     
-
      
       
       
@@ -302,6 +270,37 @@ PostgreSQL documentation
       
      
 
+     
+      
+      
+       
+        Dump data as INSERT commands (rather
+        than COPY).  This will make restoration very slow;
+        it is mainly useful for making dumps that can be loaded into
+        non-PostgreSQL databases.  Note that
+        the restore might fail altogether if you have rearranged column order.
+        The  option is safer, though even
+        slower.
+       
+      
+     
+
+     
+      
+      
+      
+       
+        Dump data as INSERT commands with explicit
+        column names (INSERT INTO
+        table
+        (column, ...) VALUES
+        ...).  This will make restoration very slow; it is mainly
+        useful for making dumps that can be loaded into
+        non-PostgreSQL databases.
+       
+      
+     
+
      
       
       
@@ -511,7 +510,7 @@ PostgreSQL documentation
 
   
    pg_dumpall 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.
   
index f30aef41d1e274eea543d376d6539a3121f6f46f..1ee647119ab9bcc3054ccf93c35306dda6935942 100644 (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;
index b455051e27097a840e3dcdcb8d9b27833a718d6d..84b448129cc275334293877bdd2300993934dcdd 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.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"));