!802 gs_restore,指定use-set-session-authorization时,执行SET_SESSION前先RESET_SESSION
Merge pull request !802 from 吴岳川/gs_restore_session_bug
This commit is contained in:
@ -136,6 +136,7 @@ static void _printTocEntry(ArchiveHandle* AH, TocEntry* te, RestoreOptions* ropt
|
||||
static char* replace_line_endings(const char* str);
|
||||
static void _doSetFixedOutputState(ArchiveHandle* AH);
|
||||
static void _doSetSessionAuth(ArchiveHandle* AH, const char* user);
|
||||
static void _doResetSessionAuth(ArchiveHandle* AH);
|
||||
static void _doSetWithOids(ArchiveHandle* AH, const bool withOids);
|
||||
static void _reconnectToDB(ArchiveHandle* AH, const char* dbname);
|
||||
static void _becomeUser(ArchiveHandle* AH, const char* user);
|
||||
@ -2624,6 +2625,9 @@ static void _doSetFixedOutputState(ArchiveHandle* AH)
|
||||
*/
|
||||
static void _doSetSessionAuth(ArchiveHandle* AH, const char* user)
|
||||
{
|
||||
if (RestoringToDB(AH)) {
|
||||
_doResetSessionAuth(AH);
|
||||
}
|
||||
PQExpBuffer cmd = createPQExpBuffer();
|
||||
char* rolepassword = NULL;
|
||||
|
||||
@ -2660,6 +2664,29 @@ static void _doSetSessionAuth(ArchiveHandle* AH, const char* user)
|
||||
(void)destroyPQExpBuffer(cmd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Issue a RESET SESSION AUTHORIZATION command. Only used before _doSetSessionAuth when gs_restoring.
|
||||
*/
|
||||
static void _doResetSessionAuth(ArchiveHandle* AH) {
|
||||
PQExpBuffer cmd = createPQExpBuffer();
|
||||
(void)appendPQExpBuffer(cmd, "RESET SESSION AUTHORIZATION;");
|
||||
if (RestoringToDB(AH)) {
|
||||
PGresult* res = NULL;
|
||||
|
||||
res = PQexec(AH->connection, cmd->data);
|
||||
if ((res == NULL) || PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||
/* NOT warn_or_exit_horribly... use -O instead to skip this. */
|
||||
exit_horribly(modulename, "could not reset session: %s", PQerrorMessage(AH->connection));
|
||||
PQclear(res);
|
||||
} else {
|
||||
// not used
|
||||
(void)ahprintf(AH, "%s\n\n", cmd->data);
|
||||
}
|
||||
|
||||
(void)destroyPQExpBuffer(cmd);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Issue a SET default_with_oids command. Caller is responsible
|
||||
* for updating state if appropriate.
|
||||
|
Reference in New Issue
Block a user