aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-10-20 16:58:32 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-10-20 16:58:42 -0400
commita4ef1f09bd870048ed91b43c5b584cf90cc59b54 (patch)
treebf20e030aa08522a47e536c49adf13ddd4b95040 /src
parent12b721a7f0e3cb05630f267e0d9b4e63bbba6b0b (diff)
downloadpostgresql-a4ef1f09bd870048ed91b43c5b584cf90cc59b54.tar.gz
postgresql-a4ef1f09bd870048ed91b43c5b584cf90cc59b54.zip
Fix pg_dump's handling of DROP DATABASE commands in --clean mode.
In commit 4317e0246c645f60c39e6572644cff1cb03b4c65, I accidentally broke this behavior while rearranging code to ensure that --create wouldn't affect whether a DATABASE entry gets put into archive-format output. Thus, 9.2 would issue a DROP DATABASE command in --clean mode, which is either useless or dangerous depending on the usage scenario. It should not do that, and no longer does. A bright spot is that this refactoring makes it easy to allow the combination of --clean and --create to work sensibly, ie, emit DROP DATABASE then CREATE DATABASE before reconnecting. Ordinarily we'd consider that a feature addition and not back-patch it, but it seems silly to not include the extra couple of lines required in the 9.2 version of the code. Per report from Guillaume Lelarge, though this is slightly more extensive than his proposed patch.
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index c7ef9a6fd33..c176b656dbf 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -303,15 +303,6 @@ RestoreArchive(Archive *AHX)
/*
* Check for nonsensical option combinations.
*
- * 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->createDB && ropt->dropSchema)
- exit_horribly(modulename, "-C and -c are incompatible options\n");
-
- /*
* -C is not compatible with -1, because we can't create a database inside
* a transaction block.
*/
@@ -456,7 +447,25 @@ RestoreArchive(Archive *AHX)
{
AH->currentTE = te;
- /* We want anything that's selected and has a dropStmt */
+ /*
+ * In createDB mode, issue a DROP *only* for the database as a
+ * whole. Issuing drops against anything else would be wrong,
+ * because at this point we're connected to the wrong database.
+ * Conversely, if we're not in createDB mode, we'd better not
+ * issue a DROP against the database at all.
+ */
+ if (ropt->createDB)
+ {
+ if (strcmp(te->desc, "DATABASE") != 0)
+ continue;
+ }
+ else
+ {
+ if (strcmp(te->desc, "DATABASE") == 0)
+ continue;
+ }
+
+ /* Otherwise, drop anything that's selected and has a dropStmt */
if (((te->reqs & (REQ_SCHEMA | REQ_DATA)) != 0) && te->dropStmt)
{
ahlog(AH, 1, "dropping %s %s\n", te->desc, te->tag);
@@ -938,9 +947,6 @@ 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;
-
curSection = SECTION_PRE_DATA;
for (te = AH->toc->next; te != AH->toc; te = te->next)
{