Ensure that pg_restore -l will output DATABASE entries whether or not -C
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 15 May 2010 21:41:16 +0000 (21:41 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 15 May 2010 21:41:16 +0000 (21:41 +0000)
is specified.  Per bug report from Russell Smith and ensuing discussion.
Since this is a corner case behavioral change, I'm going to be conservative
and not back-patch it.

In passing, also rename the RestoreOptions field for the -C switch to
something less generic than "create".

src/bin/pg_dump/pg_backup.h
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_restore.c

index 3ca39d7ba0b5ab01a4b542b7cf4a7825d2b1248f..5a73779d2159be9d8c61437cfe88aa58284f7bd6 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.52 2009/06/11 14:49:07 momjian Exp $
+ *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.53 2010/05/15 21:41:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -96,7 +96,7 @@ typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
 
 typedef struct _restoreOptions
 {
-   int         create;         /* Issue commands to create the database */
+   int         createDB;       /* Issue commands to create the database */
    int         noOwner;        /* Don't try to match original object owner */
    int         noTablespace;   /* Don't issue tablespace-related commands */
    int         disable_triggers;       /* disable triggers during data-only
index bd723a0c74abf9963364e1cf8313471f9b09c344..d0e30ad5a217ab2d800b5499226ba47457516fb6 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.184 2010/04/23 23:21:44 rhaas Exp $
+ *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.185 2010/05/15 21:41:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -211,19 +211,19 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
    /*
     * Check for nonsensical option combinations.
     *
-    * NB: create+dropSchema is useless because if you're creating the DB,
+    * NB: createDB+dropSchema is useless because if you're creating the DB,
     * there's no need to drop individual items in it.  Moreover, if we tried
     * to do that then we'd issue the drops in the database initially
     * connected to, not the one we will create, which is very bad...
     */
-   if (ropt->create && ropt->dropSchema)
+   if (ropt->createDB && ropt->dropSchema)
        die_horribly(AH, modulename, "-C and -c are incompatible options\n");
 
    /*
-    * -1 is not compatible with -C, because we can't create a database inside
+    * -C is not compatible with -1, because we can't create a database inside
     * a transaction block.
     */
-   if (ropt->create && ropt->single_txn)
+   if (ropt->createDB && ropt->single_txn)
        die_horribly(AH, modulename, "-C and -1 are incompatible options\n");
 
    /*
@@ -815,6 +815,9 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
 
    ahprintf(AH, ";\n;\n; Selected TOC Entries:\n;\n");
 
+   /* We should print DATABASE entries whether or not -C was specified */
+   ropt->createDB = 1;
+
    for (te = AH->toc->next; te != AH->toc; te = te->next)
    {
        if (ropt->verbose || _tocEntryRequired(te, ropt, true) != 0)
@@ -2257,7 +2260,7 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls)
        return 0;
 
    /* Ignore DATABASE entry unless we should create it */
-   if (!ropt->create && strcmp(te->desc, "DATABASE") == 0)
+   if (!ropt->createDB && strcmp(te->desc, "DATABASE") == 0)
        return 0;
 
    /* Check options for selective dump/restore */
index 2ff4e0c87486db2140ede8e129e5a39391be6385..1df0aa12fd6c50b1e8e65d125cde9a602a9d01fd 100644 (file)
@@ -25,7 +25,7 @@
  * http://archives.postgresql.org/pgsql-bugs/2010-02/msg00187.php
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.579 2010/03/18 20:00:51 petere Exp $
+ *   $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.580 2010/05/15 21:41:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -243,7 +243,7 @@ main(int argc, char **argv)
    int         compressLevel = -1;
    int         plainText = 0;
    int         outputClean = 0;
-   int         outputCreate = 0;
+   int         outputCreateDB = 0;
    bool        outputBlobs = false;
    int         outputNoOwner = 0;
    char       *outputSuperuser = NULL;
@@ -352,7 +352,7 @@ main(int argc, char **argv)
                break;
 
            case 'C':           /* Create DB */
-               outputCreate = 1;
+               outputCreateDB = 1;
                break;
 
            case 'E':           /* Dump encoding */
@@ -766,7 +766,7 @@ main(int argc, char **argv)
        ropt->dropSchema = outputClean;
        ropt->aclsSkip = aclsSkip;
        ropt->superuser = outputSuperuser;
-       ropt->create = outputCreate;
+       ropt->createDB = outputCreateDB;
        ropt->noOwner = outputNoOwner;
        ropt->noTablespace = outputNoTablespaces;
        ropt->disable_triggers = disable_triggers;
index c5a196c366d08cff62e69512920540829da1a572..4927471dce44393a26e216767813d60db3135625 100644 (file)
@@ -34,7 +34,7 @@
  *
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.101 2009/11/19 22:05:48 petere Exp $
+ *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.102 2010/05/15 21:41:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -154,7 +154,7 @@ main(int argc, char **argv)
                opts->dropSchema = 1;
                break;
            case 'C':
-               opts->create = 1;
+               opts->createDB = 1;
                break;
            case 'd':
                opts->dbname = strdup(optarg);