aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_archiver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/pg_dump/pg_backup_archiver.c')
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c53
1 files changed, 42 insertions, 11 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index a4deb53e3a8..fc233a608f3 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -70,6 +70,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, ArchiveHandle *AH);
static RestorePass _tocEntryRestorePass(TocEntry *te);
static bool _tocEntryIsACL(TocEntry *te);
@@ -900,7 +901,9 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
ahprintf(AH, "TRUNCATE TABLE %s%s;\n\n",
(PQserverVersion(AH->connection) >= 80400 ?
"ONLY " : ""),
- fmtId(te->tag));
+ fmtQualifiedId(PQserverVersion(AH->connection),
+ te->namespace,
+ te->tag));
}
/*
@@ -987,10 +990,10 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te)
/*
* 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
@@ -1015,10 +1018,10 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te)
/*
* 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));
}
/*
@@ -2711,6 +2714,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);
}
}
@@ -2759,6 +2764,16 @@ processStdStringsEntry(ArchiveHandle *AH, TocEntry *te)
}
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 void
StrictNamesCheck(RestoreOptions *ropt)
{
const char *missing_name;
@@ -2814,9 +2829,10 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH)
teReqs res = REQ_SCHEMA | REQ_DATA;
RestoreOptions *ropt = AH->public.ropt;
- /* 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;
/*
@@ -3117,6 +3133,10 @@ _doSetFixedOutputState(ArchiveHandle *AH)
if (ropt && ropt->use_role)
ahprintf(AH, "SET ROLE %s;\n", fmtId(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");
@@ -3321,6 +3341,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 */
@@ -3453,8 +3482,10 @@ _getObjectDescription(PQExpBuffer buf, TocEntry *te, ArchiveHandle *AH)
strcmp(type, "SUBSCRIPTION") == 0 ||
strcmp(type, "USER MAPPING") == 0)
{
- /* We already know that search_path was set properly */
- appendPQExpBuffer(buf, "%s %s", type, fmtId(te->tag));
+ appendPQExpBuffer(buf, "%s ", type);
+ if (te->namespace && *te->namespace)
+ appendPQExpBuffer(buf, "%s.", fmtId(te->namespace));
+ appendPQExpBufferStr(buf, fmtId(te->tag));
return;
}