*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.96 2004/08/30 19:44:14 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.97 2004/09/10 20:05:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static void _doSetFixedOutputState(ArchiveHandle *AH);
static void _doSetSessionAuth(ArchiveHandle *AH, const char *user);
static void _doSetWithOids(ArchiveHandle *AH, const bool withOids);
-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);
/* 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);
}
}
/*
- * Issue the commands to connect to the specified database
- * as the specified user.
+ * Issue the commands to connect to the specified database.
*
* If we're currently restoring right into a database, this will
* actually establish a connection. Otherwise it puts a \connect into
* the script output.
+ *
+ * NULL dbname implies reconnecting to the current DB (pretty useless).
*/
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);
/*
* 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)
strlen(te->owner) > 0 && strlen(te->dropStmt) > 0 &&
(strcmp(te->desc, "AGGREGATE") == 0 ||
strcmp(te->desc, "CONVERSION") == 0 ||
+ strcmp(te->desc, "DATABASE") == 0 ||
strcmp(te->desc, "DOMAIN") == 0 ||
strcmp(te->desc, "FUNCTION") == 0 ||
strcmp(te->desc, "OPERATOR") == 0 ||
* Implements the basic DB functions used by the archiver.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.57 2004/08/29 05:06:53 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.58 2004/09/10 20:05:18 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* Reconnect to the server. If dbname is not NULL, use that database,
* else the one associated with the archive handle. If username is
* not NULL, use that user name, else the one from the handle. If
- * both the database and the user and match the existing connection
- * already, nothing will be done.
+ * both the database and the user match the existing connection already,
+ * nothing will be done.
*
* Returns 1 in any case.
*/
newusername = username;
/* Let's see if the request is already satisfied */
- if (strcmp(newusername, PQuser(AH->connection)) == 0
- && strcmp(newdbname, PQdb(AH->connection)) == 0)
+ if (strcmp(newdbname, PQdb(AH->connection)) == 0 &&
+ strcmp(newusername, PQuser(AH->connection)) == 0)
return 1;
newConn = _connectDB(AH, newdbname, newusername);