diff options
Diffstat (limited to 'src/bin/pg_dump/pg_backup_archiver.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 50ec4776d9f..8c9455041eb 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -67,6 +67,7 @@ static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName); static void _selectTablespace(ArchiveHandle *AH, const char *tablespace); static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te); static void processStdStringsEntry(ArchiveHandle *AH, TocEntry *te); +static void processSearchPathEntry(ArchiveHandle *AH, TocEntry *te); static teReqs _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt); static RestorePass _tocEntryRestorePass(TocEntry *te); static bool _tocEntryIsACL(TocEntry *te); @@ -706,7 +707,9 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, ahprintf(AH, "TRUNCATE TABLE %s%s;\n\n", (PQserverVersion(AH->connection) >= 80400 ? "ONLY " : ""), - fmtId(te->tag)); + fmtQualifiedId(PQserverVersion(AH->connection), + te->namespace, + te->tag)); } /* @@ -791,10 +794,10 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop /* * Disable them. */ - _selectOutputSchema(AH, te->namespace); - ahprintf(AH, "ALTER TABLE %s DISABLE TRIGGER ALL;\n\n", - fmtId(te->tag)); + fmtQualifiedId(PQserverVersion(AH->connection), + te->namespace, + te->tag)); } static void @@ -817,10 +820,10 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt /* * Enable them. */ - _selectOutputSchema(AH, te->namespace); - ahprintf(AH, "ALTER TABLE %s ENABLE TRIGGER ALL;\n\n", - fmtId(te->tag)); + fmtQualifiedId(PQserverVersion(AH->connection), + te->namespace, + te->tag)); } /* @@ -2450,6 +2453,8 @@ ReadToc(ArchiveHandle *AH) processEncodingEntry(AH, te); else if (strcmp(te->desc, "STDSTRINGS") == 0) processStdStringsEntry(AH, te); + else if (strcmp(te->desc, "SEARCHPATH") == 0) + processSearchPathEntry(AH, te); } } @@ -2497,14 +2502,25 @@ processStdStringsEntry(ArchiveHandle *AH, TocEntry *te) te->defn); } +static void +processSearchPathEntry(ArchiveHandle *AH, TocEntry *te) +{ + /* + * te->defn should contain a command to set search_path. We just copy it + * verbatim for use later. + */ + AH->public.searchpath = pg_strdup(te->defn); +} + static teReqs _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt) { teReqs res = REQ_SCHEMA | REQ_DATA; - /* ENCODING and STDSTRINGS items are treated specially */ + /* These items are treated specially */ if (strcmp(te->desc, "ENCODING") == 0 || - strcmp(te->desc, "STDSTRINGS") == 0) + strcmp(te->desc, "STDSTRINGS") == 0 || + strcmp(te->desc, "SEARCHPATH") == 0) return REQ_SPECIAL; /* If it's an ACL, maybe ignore it */ @@ -2708,6 +2724,10 @@ _doSetFixedOutputState(ArchiveHandle *AH) if (AH->ropt && AH->ropt->use_role) ahprintf(AH, "SET ROLE %s;\n", fmtId(AH->ropt->use_role)); + /* Select the dump-time search_path */ + if (AH->public.searchpath) + ahprintf(AH, "%s", AH->public.searchpath); + /* Make sure function checking is disabled */ ahprintf(AH, "SET check_function_bodies = false;\n"); @@ -2904,6 +2924,15 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName) { PQExpBuffer qry; + /* + * If there was a SEARCHPATH TOC entry, we're supposed to just stay with + * that search_path rather than switching to entry-specific paths. + * Otherwise, it's an old archive that will not restore correctly unless + * we set the search_path as it's expecting. + */ + if (AH->public.searchpath) + return; + if (!schemaName || *schemaName == '\0' || (AH->currSchema && strcmp(AH->currSchema, schemaName) == 0)) return; /* no need to do anything */ |