Hi.

        RestoreOptions *tmpopts = (RestoreOptions *)
pg_malloc0(sizeof(RestoreOptions));
need change to
        RestoreOptions *tmpopts = pg_malloc0_object(RestoreOptions);

+  <para>
+   If the dump was taken in a non-plain-text format, use
+   <application>pg_restore</application> to restore the databases:
+<screen>
+<prompt>$</prompt> <userinput>pg_restore db.out -d postgres -C</userinput>
+</screen>
+   This will restore all databases. To restore only some databases, use
+   the <option>--exclude-database</option> option to skip those not wanted.
+  </para>

The change above was added to pg_dumpall.sgml, which seems inappropriate;
it would be more correct to place it in pg_restore.sgml.

+     <varlistentry>
+      <term><option>-g</option></term>
+      <term><option>--globals-only</option></term>
+      <listitem>
+       <para>
+        Restore only global objects (roles and tablespaces), no databases.
+       </para>
+       <para>
+        This option is only relevant when restoring from an archive
made using <application>pg_dumpall</application>.
+        Note: <option>--globals-only</option> cannot be used with
<option>--exit-on-error</option>,
+              <option>--single-transaction</option>,
<option>--clean</option>, or <option>--transaction-size</option>.
+       </para>
+      </listitem>
+     </varlistentry>
+
<option>--globals-only</option> cannot be used with --data-only,
--schema-only, --statistics-only, --statistics.
We should also mention that.

In doc/src/sgml/ref/pg_restore.sgml
"when restoring from an archive made using pg_dumpall."
It  would be better using
"when restoring from a non-plain-text archive made using pg_dumpall."
that would be aligned with pg_dumpall.sgml.

      <varlistentry>
       <term><option>-g</option></term>
       <term><option>--globals-only</option></term>
       <listitem>
        <para>
         Dump only global objects (roles and tablespaces), no databases.
+        Note: <option>--globals-only</option> cannot be used with
+        <option>--clean</option> with non-text dump format.
        </para>
Elsewhere, we use the term “non-plain-text,” so we should use
“non-plain-text” here as well instead of “non-text,” for consistency.

In doc/src/sgml/ref/pg_restore.sgml, We did not mention that many
options cannot be used with pg_restore when performing a
non-plain-text restore.
Like:
"-l/--list"
"-L/--use-list"
"--strict-names"
"--no-schema"
"-a/--data-only"
"--statistics-only"
--section does not include "--pre-data"

pg_restore --clean --format=directory will produce DROP DATABASE will
process global objects,
it will also produce DROP DATABASE when processing each individual database.
To prevent errors during a subsequent restore, we can require
pg_restore --clean option must be used together with --if-exists when
restoring a non-plain-text dump.



--
jian
https://www.enterprisedb.com
From 73079702e513471d35fd0423350503644cf27e0f Mon Sep 17 00:00:00 2001
From: jian he <[email protected]>
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
        <para>
         Dump only global objects (roles and tablespaces), no databases.
         Note: <option>--globals-only</option> cannot be used with
-        <option>--clean</option> with non-text dump format.
+        <option>--clean</option> with non-plain-text dump format.
        </para>
       </listitem>
      </varlistentry>
@@ -1049,16 +1049,6 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
    the script will attempt to drop other databases immediately, and that
    will fail for the database you are connected to.
   </para>
-
-  <para>
-   If the dump was taken in a non-plain-text format, use
-   <application>pg_restore</application> to restore the databases:
-<screen>
-<prompt>$</prompt> <userinput>pg_restore db.out -d postgres -C</userinput>
-</screen>
-   This will restore all databases.  To restore only some databases, use
-   the <option>--exclude-database</option> option to skip those not wanted.
-  </para>
  </refsect1>
 
  <refsect1>
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 <application>pg_dumpall</application>,
    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 <application>pg_dumpall</application>.
+   The following options are not supported:
+   <option>-l/--list</option>, <option>-L/--use-list</option>, <option>--strict-names</option>, <option>--no-schema</option>,
+   <option>-a/--data-only</option>,<option>--statistics-only</option>
+   In addition, <option>--section</option> must include value<option>--pre-data</option>.
 
    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 <option>--if-exists</option> is also specified.
+        If <option>--clean</option> is specified, then <option>--if-exists</option> must also be specified
+        when restoring multiple databases from an archive created by <application>pg_dumpall</application>.
        </para>
       </listitem>
      </varlistentry>
@@ -266,8 +273,9 @@ PostgreSQL documentation
         Restore only global objects (roles and tablespaces), no databases.
        </para>
        <para>
-        This option is only relevant when restoring from an archive made using <application>pg_dumpall</application>.
-        Note: <option>--globals-only</option> cannot be used with <option>--exit-on-error</option>,
+        This option is only relevant when restoring from a non-plain-text archive made using <application>pg_dumpall</application>.
+        Note: <option>--globals-only</option> cannot be used with <option>--data-only</option>, <option>--exit-on-error</option>,
+              <option>--schema-only</option>, <option>--statistics-only</option>, <option>--statistics</option>,
               <option>--single-transaction</option>, <option>--clean</option>, or <option>--transaction-size</option>.
        </para>
       </listitem>
@@ -624,7 +632,7 @@ PostgreSQL documentation
         quote the pattern if needed to prevent shell wildcard expansion.
        </para>
        <para>
-        This option is only relevant when restoring from an archive made using <application>pg_dumpall</application>.
+        This option is only relevant when restoring from a non-plain-text archive made using <application>pg_dumpall</application>.
        </para>
       </listitem>
      </varlistentry>
@@ -1234,6 +1242,17 @@ CREATE DATABASE foo WITH TEMPLATE template0;
    initially empty.
   </para>
 
+  <para>
+  Suppose we have used <application>pg_dumpall</application> non-plain-text
+  format dumped all the database in a cluster to directory <literal>db.dir</literal>,
+  use <application>pg_restore</application> to restore the databases:
+<screen>
+<prompt>$</prompt> <userinput>pg_restore db.dir -d postgres -C</userinput>
+</screen>
+   This will restore all databases.  To restore only some databases, use
+   the <option>--exclude-database</option> option to skip those not wanted.
+  </para>
+
   <para>
    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

Reply via email to