From fbb7340fe924f4d1fcadf20e99978190e0cbd0a4 Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Mon, 23 Feb 2026 15:05:09 +0800
Subject: [PATCH v18 1/1] misc fix for v18

Non-text-modes-for-pg_dumpall-correspondingly-change.patch

discussion: https://postgr.es/m/
---
 doc/src/sgml/ref/pg_restore.sgml | 25 +++++++++++++++++++++++++
 src/bin/pg_dump/pg_dumpall.c     |  6 ++++--
 src/bin/pg_dump/pg_restore.c     | 27 +++++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml
index 3d5531cfa96..cd8233712e4 100644
--- a/doc/src/sgml/ref/pg_restore.sgml
+++ b/doc/src/sgml/ref/pg_restore.sgml
@@ -58,7 +58,28 @@ 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.
+   </para>
 
+   <para>
+    Not all options are supported when restoring from an archive created by <application>pg_dumpall</application>.
+    The following options are not supported:
+     <option>-a/--data-only</option>,
+     <option>filter</option>,
+     <option>-l/--list</option>,
+     <option>-L/--use-list</option>,
+     <option>-n</option>/<option>--schema</option>,
+     <option>--no-schema</option>,
+     <option>-N</option>/<option>--exclude-schema</option>,
+     <option>-P</option>/<option>--function</option>,
+     <option>-I</option>/<option>--index</option>,
+     <option>--statistics-only</option>,
+     <option>--strict-names</option>,
+     <option>-t</option>/<option>--table</option>,
+     <option>-T</option>/<option>--trigger</option>,
+     In addition, <option>--section</option> must include value<option>--pre-data</option>.
+   </para>
+
+  <para>
    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
    to a file or standard output.  This script output is equivalent to
@@ -151,6 +172,10 @@ 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.
+        When restoring multiple databases from an archive created by
+        <application>pg_dumpall</application> specifying the
+        <option>--clean</option> option implicitly enables
+        <option>--if-exists</option> as well.
        </para>
       </listitem>
      </varlistentry>
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 5a114d09185..d18c7280d19 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -134,7 +134,6 @@ 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;
 static ArchiveFormat archDumpFormat = archNull;
 static const CatalogId nilCatalogId = {0, 0};
@@ -655,6 +654,7 @@ main(int argc, char *argv[])
 		PQExpBuffer qry = createPQExpBuffer();
 		char            global_path[MAXPGPATH];
 		const char *encname;
+		pg_compress_specification compression_spec = {0};
 
 		/* Set file path for global sql commands. */
 		snprintf(global_path, MAXPGPATH, "%s/toc.glo", filename);
@@ -1184,7 +1184,9 @@ dumpRoles(PGconn *conn)
 		if (archDumpFormat == archNull)
 		{
 			fprintf(OPF, "%s", buf->data);
-			fprintf(OPF, "%s", comment_buf->data);
+
+			if (comment_buf->data[0] != '\0')
+				fprintf(OPF, "%s", comment_buf->data);
 
 			if (seclabel_buf->data[0] != '\0')
 				fprintf(OPF, "%s", seclabel_buf->data);
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 37f30e65421..0c6404096e5 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -566,6 +566,9 @@ main(int argc, char **argv)
 
 		opts->format = archUnknown;
 
+		if (opts->dropSchema)
+			opts->if_exists = true;
+
 		memcpy(tmpopts, opts, sizeof(RestoreOptions));
 
 		/*
@@ -602,6 +605,30 @@ main(int argc, char **argv)
 			pg_fatal("option %s cannot exclude %s when restoring a pg_dumpall archive",
 					 "--section", "--pre-data");
 
+		if (opts->indexNames.head != NULL)
+			pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
+					 "-I/--index");
+
+		if (opts->functionNames.head != NULL)
+			pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
+					 "-P/--function");
+
+		if (opts->schemaNames.head != NULL)
+			pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
+					 "-n/--schema");
+
+		if (opts->schemaExcludeNames.head != NULL)
+			pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
+					 "-N/--exclude-schema");
+
+		if (opts->triggerNames.head != NULL)
+			pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
+					 "-T/--trigger");
+
+		if (opts->tableNames.head != NULL)
+			pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall",
+					 "-t/--table");
+
 		/*
 		 * To restore from a pg_dumpall archive, -C (create database) option
 		 * must be specified unless we are only restoring globals.
-- 
2.34.1

