From 4debd839b5dbbfd188ad2422112f8e303c5d7a71 Mon Sep 17 00:00:00 2001 From: Vaibhav Dalvi Date: Wed, 5 Nov 2025 06:22:00 +0000 Subject: [PATCH v1 1/1] delta v05 non-text modes for pg_dumpall This delta patch is to fix --restrict-key with non-text dump format. Vaibhav Dalvi --- src/bin/pg_dump/pg_dumpall.c | 52 +++++++++++++----------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 601b9f9738e..9e447dc9738 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -127,7 +127,6 @@ static char *filename = NULL; static SimpleStringList database_exclude_patterns = {NULL, NULL}; static SimpleStringList database_exclude_names = {NULL, NULL}; -static char *restrict_key; static Archive *fout = NULL; static pg_compress_specification compression_spec = {0}; static int dumpIdVal = 0; @@ -397,7 +396,7 @@ main(int argc, char *argv[]) break; case 9: - restrict_key = pg_strdup(optarg); + dopt.restrict_key = pg_strdup(optarg); appendPQExpBufferStr(pgdumpopts, " --restrict-key "); appendShellString(pgdumpopts, optarg); break; @@ -555,15 +554,20 @@ main(int argc, char *argv[]) else OPF = stdout; - /* - * If you don't provide a restrict key, one will be appointed for you. - */ - if (!restrict_key) - restrict_key = generate_restrict_key(); - if (!restrict_key) - pg_fatal("could not generate restrict key"); - if (!valid_restrict_key(restrict_key)) - pg_fatal("invalid restrict key"); + if (archDumpFormat == archNull) + { + /* + * If you don't provide a restrict key, one will be appointed for you. + */ + if (!dopt.restrict_key) + dopt.restrict_key = generate_restrict_key(); + if (!dopt.restrict_key) + pg_fatal("could not generate restrict key"); + if (!valid_restrict_key(dopt.restrict_key)) + pg_fatal("invalid restrict key"); + } + else if (dopt.restrict_key) + pg_fatal("option --restrict-key can only be used with --format=plain"); /* * If there was a database specified on the command line, use that, @@ -670,15 +674,6 @@ main(int argc, char *argv[]) createOneArchiveEntry("--\n-- PostgreSQL database cluster dump\n--\n\n", "COMMENT"); - /* create entry for restrict */ - { - PQExpBuffer qry = createPQExpBuffer(); - - appendPQExpBuffer(qry, "\\restrict %s\n\n", restrict_key); - createOneArchiveEntry(qry->data, "RESTRICT"); - destroyPQExpBuffer(qry); - } - /* default_transaction_read_only = off */ { PQExpBuffer qry = createPQExpBuffer(); @@ -727,7 +722,7 @@ main(int argc, char *argv[]) * meta-commands so that the client machine that runs psql with the dump * output remains unaffected. */ - fprintf(OPF, "\\restrict %s\n\n", restrict_key); + fprintf(OPF, "\\restrict %s\n\n", dopt.restrict_key); /* * We used to emit \connect postgres here, but that served no purpose @@ -793,19 +788,10 @@ main(int argc, char *argv[]) if (archDumpFormat == archNull) { /* - * Exit restricted mode just before dumping the databases. pg_dump will - * handle entering restricted mode again as appropriate. + * Exit restricted mode just before dumping the databases. pg_dump + * will handle entering restricted mode again as appropriate. */ - fprintf(OPF, "\\unrestrict %s\n\n", restrict_key); - } - else - { - /* create entry for unrestrict */ - PQExpBuffer qry = createPQExpBuffer(); - - appendPQExpBuffer(qry, "\\unrestrict %s\n\n", restrict_key); - createOneArchiveEntry(qry->data, "UNRESTRICT"); - destroyPQExpBuffer(qry); + fprintf(OPF, "\\unrestrict %s\n\n", dopt.restrict_key); } if (!globals_only && !roles_only && !tablespaces_only) -- 2.43.0