Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d681d6

Browse files
committed
Fix some problems with restoring databases owned by non-superusers,
as per bug #1249; and remove the last vestiges of using \connect tochange authorization.
1 parentb339d1f commit1d681d6

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.96 2004/08/30 19:44:14 tgl Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.97 2004/09/10 20:05:18 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -56,7 +56,7 @@ static void fixPriorBlobRefs(ArchiveHandle *AH, TocEntry *blobte,
5656
staticvoid_doSetFixedOutputState(ArchiveHandle*AH);
5757
staticvoid_doSetSessionAuth(ArchiveHandle*AH,constchar*user);
5858
staticvoid_doSetWithOids(ArchiveHandle*AH,constboolwithOids);
59-
staticvoid_reconnectToDB(ArchiveHandle*AH,constchar*dbname,constchar*user);
59+
staticvoid_reconnectToDB(ArchiveHandle*AH,constchar*dbname);
6060
staticvoid_becomeUser(ArchiveHandle*AH,constchar*user);
6161
staticvoid_becomeOwner(ArchiveHandle*AH,TocEntry*te);
6262
staticvoid_selectOutputSchema(ArchiveHandle*AH,constchar*schemaName);
@@ -277,8 +277,8 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
277277
/* If we created a DB, connect to it... */
278278
if (strcmp(te->desc,"DATABASE")==0)
279279
{
280-
ahlog(AH,1,"connecting to new database \"%s\" as user \"%s\"\n",te->tag,te->owner);
281-
_reconnectToDB(AH,te->tag,te->owner);
280+
ahlog(AH,1,"connecting to new database \"%s\"\n",te->tag);
281+
_reconnectToDB(AH,te->tag);
282282
}
283283
}
284284

@@ -2151,26 +2151,25 @@ _doSetWithOids(ArchiveHandle *AH, const bool withOids)
21512151

21522152

21532153
/*
2154-
* Issue the commands to connect to the specified database
2155-
* as the specified user.
2154+
* Issue the commands to connect to the specified database.
21562155
*
21572156
* If we're currently restoring right into a database, this will
21582157
* actually establish a connection. Otherwise it puts a \connect into
21592158
* the script output.
2159+
*
2160+
* NULL dbname implies reconnecting to the current DB (pretty useless).
21602161
*/
21612162
staticvoid
2162-
_reconnectToDB(ArchiveHandle*AH,constchar*dbname,constchar*user)
2163+
_reconnectToDB(ArchiveHandle*AH,constchar*dbname)
21632164
{
21642165
if (RestoringToDB(AH))
2165-
ReconnectToServer(AH,dbname,user);
2166+
ReconnectToServer(AH,dbname,NULL);
21662167
else
21672168
{
21682169
PQExpBufferqry=createPQExpBuffer();
21692170

2170-
appendPQExpBuffer(qry,"\\connect %s",
2171+
appendPQExpBuffer(qry,"\\connect %s\n\n",
21712172
dbname ?fmtId(dbname) :"-");
2172-
appendPQExpBuffer(qry," %s\n\n",
2173-
fmtId(user));
21742173

21752174
ahprintf(AH,qry->data);
21762175

@@ -2179,12 +2178,12 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user)
21792178

21802179
/*
21812180
* NOTE: currUser keeps track of what the imaginary session user in
2182-
* our script is
2181+
* our script is. It's now effectively reset to the original userID.
21832182
*/
21842183
if (AH->currUser)
21852184
free(AH->currUser);
21862185

2187-
AH->currUser=strdup(user);
2186+
AH->currUser=strdup("");
21882187

21892188
/* don't assume we still know the output schema */
21902189
if (AH->currSchema)
@@ -2448,6 +2447,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
24482447
strlen(te->owner)>0&&strlen(te->dropStmt)>0&&
24492448
(strcmp(te->desc,"AGGREGATE")==0||
24502449
strcmp(te->desc,"CONVERSION")==0||
2450+
strcmp(te->desc,"DATABASE")==0||
24512451
strcmp(te->desc,"DOMAIN")==0||
24522452
strcmp(te->desc,"FUNCTION")==0||
24532453
strcmp(te->desc,"OPERATOR")==0||

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*Implements the basic DB functions used by the archiver.
66
*
77
* IDENTIFICATION
8-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.57 2004/08/2905:06:53 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.58 2004/09/10 20:05:18 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -88,8 +88,8 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
8888
* Reconnect to the server. If dbname is not NULL, use that database,
8989
* else the one associated with the archive handle. If username is
9090
* not NULL, use that user name, else the one from the handle.If
91-
* both the database and the userandmatch the existing connection
92-
*already,nothing will be done.
91+
* both the database and the user match the existing connection already,
92+
* nothing will be done.
9393
*
9494
* Returns 1 in any case.
9595
*/
@@ -111,8 +111,8 @@ ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
111111
newusername=username;
112112

113113
/* Let's see if the request is already satisfied */
114-
if (strcmp(newusername,PQuser(AH->connection))==0
115-
&&strcmp(newdbname,PQdb(AH->connection))==0)
114+
if (strcmp(newdbname,PQdb(AH->connection))==0&&
115+
strcmp(newusername,PQuser(AH->connection))==0)
116116
return1;
117117

118118
newConn=_connectDB(AH,newdbname,newusername);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp