Skip to content

Commit 4bdccd8

Browse files
committed
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.
1 parent 9f1e051 commit 4bdccd8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/bin/pg_dump/pg_dumpall.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ main(int argc, char *argv[])
441441

442442
fprintf(OPF, "\\connect postgres\n\n");
443443

444+
/* Restore will need to write to the target cluster */
445+
fprintf(OPF, "SET default_transaction_read_only = off;\n\n");
446+
444447
/* Replicate encoding and std_strings in output */
445448
fprintf(OPF, "SET client_encoding = '%s';\n",
446449
pg_encoding_to_char(encoding));
@@ -1550,6 +1553,17 @@ dumpDatabases(PGconn *conn)
15501553

15511554
fprintf(OPF, "\\connect %s\n\n", fmtId(dbname));
15521555

1556+
/*
1557+
* Restore will need to write to the target cluster. This connection
1558+
* setting is emitted for pg_dumpall rather than in the code also used
1559+
* by pg_dump, so that a cluster with databases or users which have
1560+
* this flag turned on can still be replicated through pg_dumpall
1561+
* without editing the file or stream. With pg_dump there are many
1562+
* other ways to allow the file to be used, and leaving it out allows
1563+
* users to protect databases from being accidental restore targets.
1564+
*/
1565+
fprintf(OPF, "SET default_transaction_read_only = off;\n\n");
1566+
15531567
if (filename)
15541568
fclose(OPF);
15551569

0 commit comments

Comments
 (0)