From 73079702e513471d35fd0423350503644cf27e0f Mon Sep 17 00:00:00 2001 From: jian he Date: Sat, 21 Feb 2026 10:09:56 +0800 Subject: [PATCH v17 1/1] misc review for v17 based on v17_19022026-Non-text-modes-for-pg_dumpall-correspondingly-change.patch --- doc/src/sgml/ref/pg_dumpall.sgml | 12 +----------- doc/src/sgml/ref/pg_restore.sgml | 25 ++++++++++++++++++++++--- src/bin/pg_dump/pg_restore.c | 10 +++++++--- src/bin/pg_dump/t/007_pg_dumpall.pl | 1 + 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/doc/src/sgml/ref/pg_dumpall.sgml b/doc/src/sgml/ref/pg_dumpall.sgml index 49e5c99b09e..94a674c9501 100644 --- a/doc/src/sgml/ref/pg_dumpall.sgml +++ b/doc/src/sgml/ref/pg_dumpall.sgml @@ -225,7 +225,7 @@ PostgreSQL documentation Dump only global objects (roles and tablespaces), no databases. Note: cannot be used with - with non-text dump format. + with non-plain-text dump format. @@ -1049,16 +1049,6 @@ exclude database PATTERN the script will attempt to drop other databases immediately, and that will fail for the database you are connected to. - - - If the dump was taken in a non-plain-text format, use - pg_restore to restore the databases: - -$ pg_restore db.out -d postgres -C - - This will restore all databases. To restore only some databases, use - the option to skip those not wanted. - diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml index b058326b3c9..92407705fa9 100644 --- a/doc/src/sgml/ref/pg_restore.sgml +++ b/doc/src/sgml/ref/pg_restore.sgml @@ -58,6 +58,11 @@ PostgreSQL documentation When restoring from a dump made by pg_dumpall, each database will be created and then the restoration will be run in that database. + Not all options are supported when restoring from a dump created by pg_dumpall. + The following options are not supported: + , , , , + , + In addition, must include value. Otherwise, when a database name is not specified, a script containing the SQL commands necessary to rebuild the database or cluster is created and written @@ -138,6 +143,8 @@ PostgreSQL documentation If any of the objects do not exist in the destination database, ignorable error messages will be reported, unless is also specified. + If is specified, then must also be specified + when restoring multiple databases from an archive created by pg_dumpall. @@ -266,8 +273,9 @@ PostgreSQL documentation Restore only global objects (roles and tablespaces), no databases. - This option is only relevant when restoring from an archive made using pg_dumpall. - Note: cannot be used with , + This option is only relevant when restoring from a non-plain-text archive made using pg_dumpall. + Note: cannot be used with , , + , , , , , or . @@ -624,7 +632,7 @@ PostgreSQL documentation quote the pattern if needed to prevent shell wildcard expansion. - This option is only relevant when restoring from an archive made using pg_dumpall. + This option is only relevant when restoring from a non-plain-text archive made using pg_dumpall. @@ -1234,6 +1242,17 @@ CREATE DATABASE foo WITH TEMPLATE template0; initially empty. + + Suppose we have used pg_dumpall non-plain-text + format dumped all the database in a cluster to directory db.dir, + use pg_restore to restore the databases: + +$ pg_restore db.dir -d postgres -C + + This will restore all databases. To restore only some databases, use + the option to skip those not wanted. + + To reorder database items, it is first necessary to dump the table of contents of the archive: diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index b351b29d2e4..f197ff81f20 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -562,12 +562,16 @@ main(int argc, char **argv) (file_exists_in_directory(inputFileSpec, "toc.glo"))) { char global_path[MAXPGPATH]; - RestoreOptions *tmpopts = (RestoreOptions *) pg_malloc0(sizeof(RestoreOptions)); + RestoreOptions *tmpopts = pg_malloc0_object(RestoreOptions); opts->format = archUnknown; memcpy(tmpopts, opts, sizeof(RestoreOptions)); + if (opts->dropSchema && !if_exists) + pg_fatal("option %s must also be specified if option %s is specified when restoring an archive created by pg_dumpall", + "--if-exists", "-c/--clean"); + /* * Can only use --list or --use-list options with a single database * dump. @@ -1182,8 +1186,8 @@ restore_all_databases(const char *inputFileSpec, int n_errors_total = 0; char *connected_db = NULL; PGconn *conn = NULL; - RestoreOptions *original_opts = (RestoreOptions *) pg_malloc0(sizeof(RestoreOptions)); - RestoreOptions *tmpopts = (RestoreOptions *) pg_malloc0(sizeof(RestoreOptions)); + RestoreOptions *original_opts = pg_malloc0_object(RestoreOptions); + RestoreOptions *tmpopts = pg_malloc0_object(RestoreOptions); memcpy(original_opts, opts, sizeof(RestoreOptions)); diff --git a/src/bin/pg_dump/t/007_pg_dumpall.pl b/src/bin/pg_dump/t/007_pg_dumpall.pl index 309f42beabb..84e537c9136 100644 --- a/src/bin/pg_dump/t/007_pg_dumpall.pl +++ b/src/bin/pg_dump/t/007_pg_dumpall.pl @@ -409,6 +409,7 @@ $node->command_fails_like( "$tempdir/format_custom", '-C', '--format' => 'custom', '--clean', + '--if-exists', '--globals-only', '--file' => "$tempdir/error_test.sql", ], -- 2.34.1