On Fri, 10 Sep 2004, Tom Lane wrote:

> Hmm.  This is still broken in CVS tip, but I think the correct solution
> is just to replace "\connect db user" with "\connect db" everywhere.
> This will retain the starting real user authentication throughout the
> restore process.  We have completely abandoned use of \connect to change
> authorization, and this seems just an unintentional hangover from the
> old way.

Attached is a backport of your CVS commit to 7.4.5 it seems to work fine 
here after some testing.
--- postgresql-7.4.5/src/bin/pg_dump/pg_backup_archiver.c.orig  Fri Sep 10 17:33:09 
2004
+++ postgresql-7.4.5/src/bin/pg_dump/pg_backup_archiver.c       Fri Sep 10 18:24:30 
2004
@@ -50,7 +50,7 @@
 
 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 _reconnectToDB(ArchiveHandle *AH, const char *dbname);
 static void _becomeUser(ArchiveHandle *AH, const char *user);
 static void _becomeOwner(ArchiveHandle *AH, TocEntry *te);
 static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName);
@@ -262,8 +262,8 @@
                        /* If we created a DB, connect to it... */
                        if (strcmp(te->desc, "DATABASE") == 0)
                        {
-                               ahlog(AH, 1, "connecting to new database \"%s\" as 
user \"%s\"\n", te->tag, te->owner);
-                               _reconnectToDB(AH, te->tag, te->owner);
+                               ahlog(AH, 1, "connecting to new database \"%s\"\n", 
te->tag);
+                               _reconnectToDB(AH, te->tag);
                        }
                }
 
@@ -2104,18 +2104,16 @@
  * the script output.
  */
 static void
-_reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user)
+_reconnectToDB(ArchiveHandle *AH, const char *dbname)
 {
        if (RestoringToDB(AH))
-               ReconnectToServer(AH, dbname, user);
+               ReconnectToServer(AH, dbname, NULL);
        else
        {
                PQExpBuffer qry = createPQExpBuffer();
 
-               appendPQExpBuffer(qry, "\\connect %s",
+               appendPQExpBuffer(qry, "\\connect %s\n\n",
                                                  dbname ? fmtId(dbname) : "-");
-               appendPQExpBuffer(qry, " %s\n\n",
-                                                 fmtId(user));
 
                ahprintf(AH, qry->data);
 
@@ -2124,12 +2122,12 @@
 
        /*
         * NOTE: currUser keeps track of what the imaginary session user in
-        * our script is
+        * our script is. It's now effectively reset to the original userID.
         */
        if (AH->currUser)
                free(AH->currUser);
 
-       AH->currUser = strdup(user);
+       AH->currUser = strdup("");
 
        /* don't assume we still know the output schema */
        if (AH->currSchema)
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to