aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c9
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.h2
-rw-r--r--src/bin/pg_dump/pg_backup_db.c15
-rw-r--r--src/bin/pg_dump/pg_dump.c12
4 files changed, 16 insertions, 22 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index ab009e6fe36..f55aa36c49c 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -833,8 +833,13 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
}
}
- /* If we created a DB, connect to it... */
- if (strcmp(te->desc, "DATABASE") == 0)
+ /*
+ * If we created a DB, connect to it. Also, if we changed DB
+ * properties, reconnect to ensure that relevant GUC settings are
+ * applied to our session.
+ */
+ if (strcmp(te->desc, "DATABASE") == 0 ||
+ strcmp(te->desc, "DATABASE PROPERTIES") == 0)
{
PQExpBufferData connstr;
diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h
index fd0d01b5069..becfee6e819 100644
--- a/src/bin/pg_dump/pg_backup_archiver.h
+++ b/src/bin/pg_dump/pg_backup_archiver.h
@@ -448,7 +448,7 @@ extern void InitArchiveFmt_Tar(ArchiveHandle *AH);
extern bool isValidTarHeader(char *header);
-extern int ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *newUser);
+extern void ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *newUser);
extern void DropBlobIfExists(ArchiveHandle *AH, Oid oid);
void ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH);
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
index 216853d6272..3b7dd241513 100644
--- a/src/bin/pg_dump/pg_backup_db.c
+++ b/src/bin/pg_dump/pg_backup_db.c
@@ -76,13 +76,9 @@ _check_database_version(ArchiveHandle *AH)
/*
* 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 match the existing connection already,
- * nothing will be done.
- *
- * Returns 1 in any case.
+ * not NULL, use that user name, else the one from the handle.
*/
-int
+void
ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
{
PGconn *newConn;
@@ -99,11 +95,6 @@ ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
else
newusername = username;
- /* Let's see if the request is already satisfied */
- if (strcmp(newdbname, PQdb(AH->connection)) == 0 &&
- strcmp(newusername, PQuser(AH->connection)) == 0)
- return 1;
-
newConn = _connectDB(AH, newdbname, newusername);
/* Update ArchiveHandle's connCancel before closing old connection */
@@ -111,8 +102,6 @@ ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
PQfinish(AH->connection);
AH->connection = newConn;
-
- return 1;
}
/*
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 11e1ba04cc4..d65ea54a69b 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -2819,10 +2819,11 @@ dumpDatabase(Archive *fout)
/*
* Now construct a DATABASE PROPERTIES archive entry to restore any
- * non-default database-level properties. We want to do this after
- * reconnecting so that these properties won't apply during the restore
- * session. In this way, restoring works even if there is, say, an ALTER
- * DATABASE SET that turns on default_transaction_read_only.
+ * non-default database-level properties. (The reason this must be
+ * separate is that we cannot put any additional commands into the TOC
+ * entry that has CREATE DATABASE. pg_restore would execute such a group
+ * in an implicit transaction block, and the backend won't allow CREATE
+ * DATABASE in that context.)
*/
resetPQExpBuffer(creaQry);
resetPQExpBuffer(delQry);
@@ -2854,8 +2855,7 @@ dumpDatabase(Archive *fout)
/*
* We stick this binary-upgrade query into the DATABASE PROPERTIES archive
- * entry, too. It can't go into the DATABASE entry because that would
- * result in an implicit transaction block around the CREATE DATABASE.
+ * entry, too, for lack of a better place.
*/
if (dopt->binary_upgrade)
{