Commit bd823e11 authored by Tom Lane's avatar Tom Lane

Ensure that pg_restore -l will output DATABASE entries whether or not -C

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".
parent ea9968c3
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * 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); ...@@ -96,7 +96,7 @@ typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
typedef struct _restoreOptions 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 noOwner; /* Don't try to match original object owner */
int noTablespace; /* Don't issue tablespace-related commands */ int noTablespace; /* Don't issue tablespace-related commands */
int disable_triggers; /* disable triggers during data-only int disable_triggers; /* disable triggers during data-only
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -211,19 +211,19 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
/* /*
* Check for nonsensical option combinations. * 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 * 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 * 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... * 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"); 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. * 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"); die_horribly(AH, modulename, "-C and -1 are incompatible options\n");
/* /*
...@@ -815,6 +815,9 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt) ...@@ -815,6 +815,9 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
ahprintf(AH, ";\n;\n; Selected TOC Entries:\n;\n"); 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) for (te = AH->toc->next; te != AH->toc; te = te->next)
{ {
if (ropt->verbose || _tocEntryRequired(te, ropt, true) != 0) if (ropt->verbose || _tocEntryRequired(te, ropt, true) != 0)
...@@ -2257,7 +2260,7 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls) ...@@ -2257,7 +2260,7 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls)
return 0; return 0;
/* Ignore DATABASE entry unless we should create it */ /* 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; return 0;
/* Check options for selective dump/restore */ /* Check options for selective dump/restore */
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* http://archives.postgresql.org/pgsql-bugs/2010-02/msg00187.php * http://archives.postgresql.org/pgsql-bugs/2010-02/msg00187.php
* *
* IDENTIFICATION * 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) ...@@ -243,7 +243,7 @@ main(int argc, char **argv)
int compressLevel = -1; int compressLevel = -1;
int plainText = 0; int plainText = 0;
int outputClean = 0; int outputClean = 0;
int outputCreate = 0; int outputCreateDB = 0;
bool outputBlobs = false; bool outputBlobs = false;
int outputNoOwner = 0; int outputNoOwner = 0;
char *outputSuperuser = NULL; char *outputSuperuser = NULL;
...@@ -352,7 +352,7 @@ main(int argc, char **argv) ...@@ -352,7 +352,7 @@ main(int argc, char **argv)
break; break;
case 'C': /* Create DB */ case 'C': /* Create DB */
outputCreate = 1; outputCreateDB = 1;
break; break;
case 'E': /* Dump encoding */ case 'E': /* Dump encoding */
...@@ -766,7 +766,7 @@ main(int argc, char **argv) ...@@ -766,7 +766,7 @@ main(int argc, char **argv)
ropt->dropSchema = outputClean; ropt->dropSchema = outputClean;
ropt->aclsSkip = aclsSkip; ropt->aclsSkip = aclsSkip;
ropt->superuser = outputSuperuser; ropt->superuser = outputSuperuser;
ropt->create = outputCreate; ropt->createDB = outputCreateDB;
ropt->noOwner = outputNoOwner; ropt->noOwner = outputNoOwner;
ropt->noTablespace = outputNoTablespaces; ropt->noTablespace = outputNoTablespaces;
ropt->disable_triggers = disable_triggers; ropt->disable_triggers = disable_triggers;
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -154,7 +154,7 @@ main(int argc, char **argv)
opts->dropSchema = 1; opts->dropSchema = 1;
break; break;
case 'C': case 'C':
opts->create = 1; opts->createDB = 1;
break; break;
case 'd': case 'd':
opts->dbname = strdup(optarg); opts->dbname = strdup(optarg);
......
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