On Fri, Feb 6, 2026 at 5:36 PM Zsolt Parragi <[email protected]> wrote:
>
> Please see the attached tap test case. It works with the current
> master branch, and fails with the patch. Basically my expectation is
> that if we use dumpall --schema-only, we should be able to restore it
> without errors, except for one error for the already existing
> postgres/current user which it ignores.
>
> I also found one more issue/behavior change: --no-schema --clean now
> generates DROP statements (roles, tablespaces, databases), while
> previously it didn't.

hi.

It would be better to simply reject the CONFLICT ONLY option and keep the rest
of the logic same as the HEAD. That way, we avoid any surprising behavior.
IMHO.

Please check attached v5.


--
jian
https://www.enterprisedb.com/
From feb6b020c9f8fe92c811e2fe4711f6793d698c0d Mon Sep 17 00:00:00 2001
From: jian he <[email protected]>
Date: Mon, 9 Feb 2026 14:29:48 +0800
Subject: [PATCH v5 1/1] pg_dumpall error out conflict options

--roles-only
--tablespaces-only
--statistics-only
--schema-only
--globals-only
--data-only
--statistics

only allowed combination is --statistics --statistics-only.
since pg_dump also support it.

discussion: https://postgr.es/m/CACJufxFf5=wsv2msuo8izovplzq1-meamwhw7jx5gnvwo5p...@mail.gmail.com
commitfest entry: https://commitfest.postgresql.org/patch/6459
---
 src/bin/pg_dump/pg_dumpall.c     |  88 ++++++++++++++++++++------
 src/bin/pg_dump/t/001_basic.pl   | 102 +++++++++++++++++++++++++++++++
 src/bin/pg_dump/t/002_pg_dump.pl |   2 -
 3 files changed, 172 insertions(+), 20 deletions(-)

diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 30fecd0c252..c768eb653ce 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -198,6 +198,7 @@ main(int argc, char *argv[])
 	char	   *use_role = NULL;
 	const char *dumpencoding = NULL;
 	trivalue	prompt_password = TRI_DEFAULT;
+	bool		schema_only = false;
 	bool		data_only = false;
 	bool		globals_only = false;
 	bool		roles_only = false;
@@ -207,6 +208,9 @@ main(int argc, char *argv[])
 	int			c,
 				ret;
 	int			optindex;
+	bool		dump_DBs;
+	bool		dump_roles;
+	bool		dump_tablespaces;
 
 	pg_logging_init(argv[0]);
 	pg_logging_set_level(PG_LOG_WARNING);
@@ -299,6 +303,7 @@ main(int argc, char *argv[])
 				break;
 
 			case 's':
+				schema_only = true;
 				appendPQExpBufferStr(pgdumpopts, " -s");
 				break;
 
@@ -406,18 +411,69 @@ main(int argc, char *argv[])
 	}
 
 	/* Make sure the user hasn't specified a mix of globals-only options */
-	if (globals_only && roles_only)
+	if (globals_only &&
+		(roles_only || tablespaces_only || with_statistics || statistics_only || schema_only || data_only))
 	{
 		pg_log_error("options %s and %s cannot be used together",
-					 "-g/--globals-only", "-r/--roles-only");
+					 "-g/--globals-only",
+					 roles_only ? "-r/--roles-only" :
+					 tablespaces_only ? "-t/--tablespaces-only" :
+					 with_statistics ? "--statistics" :
+					 statistics_only ? "--statistics-only" :
+					 schema_only ? "-s/--schema-only" :
+					 "-a/--data-only");
+
+		pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+		exit_nicely(1);
+	}
+
+	if (roles_only &&
+		(tablespaces_only || schema_only || with_statistics || statistics_only || data_only))
+	{
+		pg_log_error("options %s and %s cannot be used together",
+					 "-r/--roles-only",
+					 tablespaces_only ? "-t/--tablespaces-only" :
+					 schema_only ? "-s/--schema-only" :
+					 with_statistics ? "--statistics" :
+					 statistics_only ? "--statistics-only" :
+					 "-a/--data-only");
+
+		pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+		exit_nicely(1);
+	}
+
+	if (tablespaces_only &&
+		(schema_only || with_statistics || statistics_only || data_only))
+	{
+		pg_log_error("options %s and %s cannot be used together",
+					 "-t/--tablespaces-only",
+					 schema_only ? "-s/--schema-only" :
+					 with_statistics ? "--statistics" :
+					 statistics_only ? "--statistics-only" :
+					 "-a/--data-only");
+
 		pg_log_error_hint("Try \"%s --help\" for more information.", progname);
 		exit_nicely(1);
 	}
 
-	if (globals_only && tablespaces_only)
+	if (data_only && (schema_only || with_statistics || statistics_only))
 	{
 		pg_log_error("options %s and %s cannot be used together",
-					 "-g/--globals-only", "-t/--tablespaces-only");
+					 "-a/--data-only",
+					 schema_only ? "-s/--schema-only" :
+					 statistics_only ? "--statistics-only" :
+					 "--statistics");
+		pg_log_error_hint("Try \"%s --help\" for more information.", progname);
+		exit_nicely(1);
+	}
+
+	if (schema_only && (with_statistics || statistics_only))
+	{
+		pg_log_error("options %s and %s cannot be used together",
+					 "-s/--schema-only",
+					 statistics_only ? "--statistics-only" :
+					 "--statistics");
+
 		pg_log_error_hint("Try \"%s --help\" for more information.", progname);
 		exit_nicely(1);
 	}
@@ -426,14 +482,6 @@ main(int argc, char *argv[])
 		pg_fatal("option %s requires option %s",
 				 "--if-exists", "-c/--clean");
 
-	if (roles_only && tablespaces_only)
-	{
-		pg_log_error("options %s and %s cannot be used together",
-					 "-r/--roles-only", "-t/--tablespaces-only");
-		pg_log_error_hint("Try \"%s --help\" for more information.", progname);
-		exit_nicely(1);
-	}
-
 	/*
 	 * If password values are not required in the dump, switch to using
 	 * pg_roles which is equally useful, just more likely to have unrestricted
@@ -623,6 +671,10 @@ main(int argc, char *argv[])
 	fprintf(OPF, "SET standard_conforming_strings = on;\n");
 	fprintf(OPF, "\n");
 
+	dump_DBs = !globals_only && !roles_only && !tablespaces_only;
+	dump_tablespaces = !roles_only && !no_tablespaces;
+	dump_roles = !tablespaces_only;
+
 	if (!data_only && !statistics_only && !no_schema)
 	{
 		/*
@@ -633,13 +685,13 @@ main(int argc, char *argv[])
 		 */
 		if (output_clean)
 		{
-			if (!globals_only && !roles_only && !tablespaces_only)
+			if (dump_DBs)
 				dropDBs(conn);
 
-			if (!roles_only && !no_tablespaces)
+			if (dump_tablespaces)
 				dropTablespaces(conn);
 
-			if (!tablespaces_only)
+			if (dump_roles)
 				dropRoles(conn);
 		}
 
@@ -647,7 +699,7 @@ main(int argc, char *argv[])
 		 * Now create objects as requested.  Be careful that option logic here
 		 * is the same as for drops above.
 		 */
-		if (!tablespaces_only)
+		if (dump_roles)
 		{
 			/* Dump roles (users) */
 			dumpRoles(conn);
@@ -661,7 +713,7 @@ main(int argc, char *argv[])
 		}
 
 		/* Dump tablespaces */
-		if (!roles_only && !no_tablespaces)
+		if (dump_tablespaces)
 			dumpTablespaces(conn);
 	}
 
@@ -671,7 +723,7 @@ main(int argc, char *argv[])
 	 */
 	fprintf(OPF, "\\unrestrict %s\n\n", restrict_key);
 
-	if (!globals_only && !roles_only && !tablespaces_only)
+	if (dump_DBs)
 		dumpDatabases(conn);
 
 	PQfinish(conn);
diff --git a/src/bin/pg_dump/t/001_basic.pl b/src/bin/pg_dump/t/001_basic.pl
index ab9310eb42b..23ed5c34d53 100644
--- a/src/bin/pg_dump/t/001_basic.pl
+++ b/src/bin/pg_dump/t/001_basic.pl
@@ -220,12 +220,114 @@ command_fails_like(
 	'pg_dumpall: options -g/--globals-only and -t/--tablespaces-only cannot be used together'
 );
 
+command_fails_like(
+	[ 'pg_dumpall', '-g', '--statistics' ],
+	qr/\Qpg_dumpall: error: options -g\/--globals-only and --statistics cannot be used together\E/,
+	'pg_dumpall: error: options -g/--globals-only and --statistics cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-g', '--statistics-only' ],
+	qr/\Qpg_dumpall: error: options -g\/--globals-only and --statistics-only cannot be used together\E/,
+	'pg_dumpall: error: options -g/--globals-only and --statistics-only cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-g', '-s' ],
+	qr/\Qpg_dumpall: error: options -g\/--globals-only and -s\/--schema-only cannot be used together\E/,
+	'pg_dumpall: error: options -g/--globals-only and -s/--schema-only cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-g', '-a' ],
+	qr/\Qpg_dumpall: error: options -g\/--globals-only and -a\/--data-only cannot be used together\E/,
+	'pg_dumpall: error: options -g/--globals-only and -a/--data-only cannot be used together'
+);
+
 command_fails_like(
 	[ 'pg_dumpall', '-r', '-t' ],
 	qr/\Qpg_dumpall: error: options -r\/--roles-only and -t\/--tablespaces-only cannot be used together\E/,
 	'pg_dumpall: options -r/--roles-only and -t/--tablespaces-only cannot be used together'
 );
 
+command_fails_like(
+	[ 'pg_dumpall', '-r', '-s' ],
+	qr/\Qpg_dumpall: error: options -r\/--roles-only and -s\/--schema-only cannot be used together\E/,
+	'pg_dumpall: error: options -r/--roles-only and -s/--schema-only cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-r', '--statistics' ],
+	qr/\Qpg_dumpall: error: options -r\/--roles-only and --statistics cannot be used together\E/,
+	'pg_dumpall: error: options -r/--roles-only and --statistics cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-r', '--statistics-only' ],
+	qr/\Qpg_dumpall: error: options -r\/--roles-only and --statistics-only cannot be used together\E/,
+	'pg_dumpall: error: options -r/--roles-only and --statistics-only cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-r', '-a' ],
+	qr/\Qpg_dumpall: error: options -r\/--roles-only and -a\/--data-only cannot be used together\E/,
+	'pg_dumpall: error: options -r/--roles-only and -a/--data-only cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-t', '-s' ],
+	qr/\Qpg_dumpall: error: options -t\/--tablespaces-only and -s\/--schema-only cannot be used together\E/,
+	'pg_dumpall: error: options -t/--tablespaces-only and -s/--schema-only cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-t', '--statistics' ],
+	qr/\Qpg_dumpall: error: options -t\/--tablespaces-only and --statistics cannot be used together\E/,
+	'pg_dumpall: error: options -t/--tablespaces-only and --statistics cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-t', '--statistics-only'],
+	qr/\Qpg_dumpall: error: options -t\/--tablespaces-only and --statistics-only cannot be used together\E/,
+	'pg_dumpall: error: options -t/--tablespaces-only and --statistics-only cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-t', '-a'],
+	qr/\Qpg_dumpall: error: options -t\/--tablespaces-only and -a\/--data-only cannot be used together\E/,
+	'pg_dumpall: error: options -t/--tablespaces-only and -a/--data-only cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-a', '-s' ],
+	qr/\Qpg_dumpall: error: options -a\/--data-only and -s\/--schema-only cannot be used together\E/,
+	'pg_dumpall: error: options -a/--data-only and -s/--schema-only cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-a', '--statistics' ],
+	qr/\Qpg_dumpall: error: options -a\/--data-only and --statistics cannot be used together\E/,
+	'pg_dumpall: error: options -a/--data-only and --statistics cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-a', '--statistics-only' ],
+	qr/\Qpg_dumpall: error: options -a\/--data-only and --statistics-only cannot be used together\E/,
+	'pg_dumpall: error: options -a/--data-only and --statistics-only cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-s', '--statistics' ],
+	qr/\Qpg_dumpall: error: options -s\/--schema-only and --statistics cannot be used together\E/,
+	'pg_dumpall: error: options -s/--schema-only and --statistics cannot be used together'
+);
+
+command_fails_like(
+	[ 'pg_dumpall', '-s', '--statistics-only' ],
+	qr/\Qpg_dumpall: error: options -s\/--schema-only and --statistics-only cannot be used together\E/,
+	'pg_dumpall: error: options /--schema-only and --statistics-only cannot be used together'
+);
+
 command_fails_like(
 	[ 'pg_dumpall', '--if-exists' ],
 	qr/\Qpg_dumpall: error: option --if-exists requires option -c\/--clean\E/,
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index a8dcc2b5c75..340cf953a60 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -322,7 +322,6 @@ my %pgdump_runs = (
 			'--file' => "$tempdir/pg_dumpall_globals.sql",
 			'--globals-only',
 			'--no-sync',
-			'--statistics',
 		],
 	},
 	pg_dumpall_globals_clean => {
@@ -332,7 +331,6 @@ my %pgdump_runs = (
 			'--globals-only',
 			'--clean',
 			'--no-sync',
-			'--statistics',
 		],
 	},
 	pg_dumpall_dbprivs => {
-- 
2.34.1

Reply via email to