If pg_dump drops a schema, make sure 'search_path' it SET the next time
authorBruce Momjian <bruce@momjian.us>
Sat, 24 Nov 2007 17:45:32 +0000 (17:45 +0000)
committerBruce Momjian <bruce@momjian.us>
Sat, 24 Nov 2007 17:45:32 +0000 (17:45 +0000)
it is needed --- basically don't remember the previous 'search_path'
after a drop schema because it might have failed but be created later.

src/bin/pg_dump/pg_backup_archiver.c

index 149764e62b6493a414c23e25177bcb808af722df..ec38549d2c0e370213bb1850a365297e528a92c7 100644 (file)
@@ -245,6 +245,21 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
                                _selectOutputSchema(AH, te->namespace);
                                /* Drop it */
                                ahprintf(AH, "%s", te->dropStmt);
+                               if (strcmp(te->desc, "SCHEMA") == 0)
+                               {
+                                       /*
+                                        * If we dropped a schema, we know we are going to be
+                                        * creating one later so don't remember the current one
+                                        * so we try later. The previous 'search_path' setting
+                                        * might have failed because the schema didn't exist
+                                        * (and now it certainly doesn't exist), so force
+                                        * search_path to be set as part of the next operation
+                                        * and it might succeed.
+                                        */
+                                       if (AH->currSchema)
+                                               free(AH->currSchema);
+                                       AH->currSchema = strdup("");
+                               }
                        }
                }
        }