summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Grittner <kgrittn@postgresql.org>2013-11-30 11:33:54 -0600
committerKevin Grittner <kgrittn@postgresql.org>2013-11-30 11:33:54 -0600
commit27b33245a5f505794a0e8dd4cdb9342f8cf2cc0a (patch)
treed5cc51032561749c391ed1ca23b4cd317e38bbf2
parent8f8c666144226860d8d766054f6c8f3d78862e8b (diff)
downloadpostgresql-27b33245a5f505794a0e8dd4cdb9342f8cf2cc0a.tar.gz
Fix pg_dumpall to work for databases flagged as read-only.
pg_dumpall's charter is to be able to recreate a database cluster's contents in a virgin installation, but it was failing to honor that contract if the cluster had any ALTER DATABASE SET default_transaction_read_only settings. By including a SET command for the connection for each connection opened by pg_dumpall output, errors are avoided and the source cluster is successfully recreated. There was discussion of whether to also set this for the connection applying pg_dump output, but it was felt that it was both less appropriate in that context, and far easier to work around. Backpatch to all supported branches.
-rw-r--r--src/bin/pg_dump/pg_dumpall.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 5ed8ca1339..8dd17f70fa 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -448,6 +448,9 @@ main(int argc, char *argv[])
* database we're connected to at the moment is fine.
*/
+ /* Restore will need to write to the target cluster */
+ fprintf(OPF, "SET default_transaction_read_only = off;\n\n");
+
/* Replicate encoding and std_strings in output */
fprintf(OPF, "SET client_encoding = '%s';\n",
pg_encoding_to_char(encoding));
@@ -1586,6 +1589,17 @@ dumpDatabases(PGconn *conn)
fprintf(OPF, "\\connect %s\n\n", fmtId(dbname));
+ /*
+ * Restore will need to write to the target cluster. This connection
+ * setting is emitted for pg_dumpall rather than in the code also used
+ * by pg_dump, so that a cluster with databases or users which have
+ * this flag turned on can still be replicated through pg_dumpall
+ * without editing the file or stream. With pg_dump there are many
+ * other ways to allow the file to be used, and leaving it out allows
+ * users to protect databases from being accidental restore targets.
+ */
+ fprintf(OPF, "SET default_transaction_read_only = off;\n\n");
+
if (filename)
fclose(OPF);