1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-23 14:01:44 +03:00

Cause pg_dump to emit a 'SET client_encoding' command at the start of

any restore operation, thereby ensuring that dumped data is interpreted
the same way it was dumped even if the target database has a different
encoding.  Per suggestions from Pavel Stehule and others.  Also,
simplify scheme for handling check_function_bodies ... we may as well
just set that at the head of the script.
This commit is contained in:
Tom Lane
2004-02-24 03:35:19 +00:00
parent 55fb172739
commit 92bec9a0bc
3 changed files with 91 additions and 16 deletions

View File

@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.82 2004/01/04 04:02:15 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.83 2004/02/24 03:35:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -49,6 +49,7 @@ static ArchiveHandle *_allocAH(const char *FileSpec, const ArchiveFormat fmt,
const int compression, ArchiveMode mode);
static int _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData);
static void _doSetFixedOutputState(ArchiveHandle *AH);
static void _doSetSessionAuth(ArchiveHandle *AH, const char *user);
static void _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user);
static void _becomeUser(ArchiveHandle *AH, const char *user);
@ -200,6 +201,11 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");
/*
* Establish important parameter values right away.
*/
_doSetFixedOutputState(AH);
/*
* Drop the items at the start, in reverse order
*/
@ -1568,7 +1574,6 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
AH->currUser = strdup(""); /* So it's valid, but we can free() it
* later if necessary */
AH->currSchema = strdup(""); /* ditto */
AH->chk_fn_bodies = true; /* assumed default state */
AH->toc = (TocEntry *) calloc(1, sizeof(TocEntry));
if (!AH->toc)
@ -1826,6 +1831,10 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt)
{
teReqs res = 3; /* Schema = 1, Data = 2, Both = 3 */
/* ENCODING objects are dumped specially, so always reject here */
if (strcmp(te->desc, "ENCODING") == 0)
return 0;
/* If it's an ACL, maybe ignore it */
if (ropt->aclsSkip && strcmp(te->desc, "ACL") == 0)
return 0;
@ -1910,6 +1919,33 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt)
return res;
}
/*
* Issue SET commands for parameters that we want to have set the same way
* at all times during execution of a restore script.
*/
static void
_doSetFixedOutputState(ArchiveHandle *AH)
{
TocEntry *te;
/* If we have an encoding setting, emit that */
te = AH->toc->next;
while (te != AH->toc)
{
if (strcmp(te->desc, "ENCODING") == 0)
{
ahprintf(AH, "%s", te->defn);
break;
}
te = te->next;
}
/* Make sure function checking is disabled */
ahprintf(AH, "SET check_function_bodies = false;\n");
ahprintf(AH, "\n");
}
/*
* Issue a SET SESSION AUTHORIZATION command. Caller is responsible
* for updating state if appropriate. If user is NULL or an empty string,
@ -1991,7 +2027,8 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user)
free(AH->currSchema);
AH->currSchema = strdup("");
AH->chk_fn_bodies = true; /* assumed default state */
/* re-establish fixed state */
_doSetFixedOutputState(AH);
}
/*
@ -2087,13 +2124,6 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
_becomeOwner(AH, te);
_selectOutputSchema(AH, te->namespace);
/* If it's a function, make sure function checking is disabled */
if (AH->chk_fn_bodies && strcmp(te->desc, "FUNCTION") == 0)
{
ahprintf(AH, "SET check_function_bodies = false;\n\n");
AH->chk_fn_bodies = false;
}
if (isData)
pfx = "Data for ";
else