On Fri, Feb 6, 2026 at 4:35 AM Zsolt Parragi <[email protected]> wrote:
>
> > The attached patch also addresses the points mentioned by Zsolt Parragi.
>
> old:
>
> - if (!data_only && !statistics_only && !no_schema)
>
> new:
>
> + shouldDumpTablespaces = !roles_only && !no_tablespaces && !data_only
> && !schema_only && !statistics_only;
> + shouldDumpRoles = !tablespaces_only && !data_only && !schema_only &&
> !statistics_only;
>
> This is still a user visible change: no_schema -> schema_only
>
> And I don't think this change is good, roles and tablespaces are part
> of the schema, without them, DDL statements later can fail.
>
hi.
I believe "schema" generally refers to object definitions, excluding
things like roles and tablespaces.
I tend to think that once "only" is specified, the "no" option meaning
is not applied,
thus I'm ok with
pg_dumpall --globals-only --no-schema
is equivalent to
pg_dumpall --globals-only
For all these pg_dumpall combination
--roles-only
--tablespaces-only
--statistics-only
--schema-only
--globals-only
--data-only
--statistics
The only allowed combination is --statistics --statistics-only.
since pg_dump also supports it, and these two option meanings do not contradict.
please check v4, it looks very neat, IMHO.
for example:
+ 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");
+
src/bin/pg_dump/t/001_basic.pl tests are well aligned with pg_dumpall.c code, so
it's quite easy to review.
--
jian
https://www.enterprisedb.com/
From eed81c913d77333185331ff2ce4ed4f440dbbfe7 Mon Sep 17 00:00:00 2001
From: jian he <[email protected]>
Date: Fri, 6 Feb 2026 14:18:28 +0800
Subject: [PATCH v4 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.
pg_dumpall: --statistics-only --data-only --schema-only
implies don't dump globals objects(roles, tablespaces).
pg_dumpall: --globals-only --roles-only --tablespaces-only implies don't dump databases.
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 | 143 +++++++++++++++++++++----------
src/bin/pg_dump/t/001_basic.pl | 102 ++++++++++++++++++++++
src/bin/pg_dump/t/002_pg_dump.pl | 2 -
3 files changed, 198 insertions(+), 49 deletions(-)
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 30fecd0c252..098ee73198b 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,55 +671,56 @@ main(int argc, char *argv[])
fprintf(OPF, "SET standard_conforming_strings = on;\n");
fprintf(OPF, "\n");
- if (!data_only && !statistics_only && !no_schema)
- {
- /*
- * If asked to --clean, do that first. We can avoid detailed
- * dependency analysis because databases never depend on each other,
- * and tablespaces never depend on each other. Roles could have
- * grants to each other, but DROP ROLE will clean those up silently.
- */
- if (output_clean)
- {
- if (!globals_only && !roles_only && !tablespaces_only)
- dropDBs(conn);
+ dump_DBs = !globals_only && !roles_only && !tablespaces_only;
+ dump_tablespaces = !roles_only && !no_tablespaces && !data_only && !schema_only && !statistics_only;
+ dump_roles = !tablespaces_only && !data_only && !schema_only && !statistics_only;
- if (!roles_only && !no_tablespaces)
- dropTablespaces(conn);
+ /*
+ * If asked to --clean, do that first. We can avoid detailed dependency
+ * analysis because databases never depend on each other, and tablespaces
+ * never depend on each other. Roles could have grants to each other, but
+ * DROP ROLE will clean those up silently.
+ */
+ if (output_clean)
+ {
+ if (dump_DBs)
+ dropDBs(conn);
- if (!tablespaces_only)
- dropRoles(conn);
- }
+ if (dump_tablespaces)
+ dropTablespaces(conn);
- /*
- * Now create objects as requested. Be careful that option logic here
- * is the same as for drops above.
- */
- if (!tablespaces_only)
- {
- /* Dump roles (users) */
- dumpRoles(conn);
+ if (dump_roles)
+ dropRoles(conn);
+ }
- /* Dump role memberships */
- dumpRoleMembership(conn);
+ /*
+ * Now create objects as requested. Be careful that option logic here is
+ * the same as for drops above.
+ */
+ if (dump_roles)
+ {
+ /* Dump roles (users) */
+ dumpRoles(conn);
- /* Dump role GUC privileges */
- if (server_version >= 150000 && !skip_acls)
- dumpRoleGUCPrivs(conn);
- }
+ /* Dump role memberships */
+ dumpRoleMembership(conn);
- /* Dump tablespaces */
- if (!roles_only && !no_tablespaces)
- dumpTablespaces(conn);
+ /* Dump role GUC privileges */
+ if (server_version >= 150000 && !skip_acls)
+ dumpRoleGUCPrivs(conn);
}
+ /* Dump tablespaces */
+ if (dump_tablespaces)
+ dumpTablespaces(conn);
+
/*
* 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);
- 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