8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a541dbb commit 160a4f6Copy full SHA for 160a4f6
src/bin/pg_dump/pg_backup_archiver.c
@@ -833,8 +833,13 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
833
}
834
835
836
- /* If we created a DB, connect to it... */
837
- if (strcmp(te->desc, "DATABASE") == 0)
+ /*
+ * If we created a DB, connect to it. Also, if we changed DB
838
+ * properties, reconnect to ensure that relevant GUC settings are
839
+ * applied to our session.
840
+ */
841
+ if (strcmp(te->desc, "DATABASE") == 0 ||
842
+ strcmp(te->desc, "DATABASE PROPERTIES") == 0)
843
{
844
PQExpBufferData connstr;
845
src/bin/pg_dump/pg_backup_archiver.h
@@ -448,7 +448,7 @@ extern void InitArchiveFmt_Tar(ArchiveHandle *AH);
448
449
extern bool isValidTarHeader(char *header);
450
451
-extern int ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *newUser);
+extern void ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *newUser);
452
extern void DropBlobIfExists(ArchiveHandle *AH, Oid oid);
453
454
void ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH);
src/bin/pg_dump/pg_backup_db.c
@@ -76,13 +76,9 @@ _check_database_version(ArchiveHandle *AH)
76
/*
77
* Reconnect to the server. If dbname is not NULL, use that database,
78
* else the one associated with the archive handle. If username is
79
- * not NULL, use that user name, else the one from the handle. If
80
- * both the database and the user match the existing connection already,
81
- * nothing will be done.
82
- *
83
- * Returns 1 in any case.
+ * not NULL, use that user name, else the one from the handle.
84
*/
85
-int
+void
86
ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
87
88
PGconn *newConn;
@@ -99,20 +95,13 @@ ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
99
95
else
100
96
newusername = username;
101
97
102
- /* Let's see if the request is already satisfied */
103
- if (strcmp(newdbname, PQdb(AH->connection)) == 0 &&
104
- strcmp(newusername, PQuser(AH->connection)) == 0)
105
- return 1;
106
-
107
98
newConn = _connectDB(AH, newdbname, newusername);
108
109
/* Update ArchiveHandle's connCancel before closing old connection */
110
set_archive_cancel_info(AH, newConn);
111
112
PQfinish(AH->connection);
113
AH->connection = newConn;
114
115
116
117
118
src/bin/pg_dump/pg_dump.c
@@ -2819,10 +2819,11 @@ dumpDatabase(Archive *fout)
2819
2820
2821
* Now construct a DATABASE PROPERTIES archive entry to restore any
2822
- * non-default database-level properties. We want to do this after
2823
- * reconnecting so that these properties won't apply during the restore
2824
- * session. In this way, restoring works even if there is, say, an ALTER
2825
- * 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
2826
+ * DATABASE in that context.)
2827
2828
resetPQExpBuffer(creaQry);
2829
resetPQExpBuffer(delQry);
@@ -2854,8 +2855,7 @@ dumpDatabase(Archive *fout)
2854
2855
2856
2857
* We stick this binary-upgrade query into the DATABASE PROPERTIES archive
- * entry, too. It can't go into the DATABASE entry because that would
2858
- * result in an implicit transaction block around the CREATE DATABASE.
+ * entry, too, for lack of a better place.
2859
2860
if (dopt->binary_upgrade)
2861