Re: pg_dumpall --roles-only interact with other options

Nathan Bossart <nathandbossart@gmail.com>

From: Nathan Bossart <nathandbossart@gmail.com>
To: jian he <jian.universality@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2026-02-03T21:25:54Z
Lists: pgsql-hackers
On Tue, Feb 03, 2026 at 10:15:35AM +0800, jian he wrote:
> please check the attached.

Thanks.

> -		{"statistics", no_argument, &with_statistics, 1},
> -		{"statistics-only", no_argument, &statistics_only, 1},
> +		{"statistics", no_argument, NULL, 10},
> +		{"statistics-only", no_argument, NULL, 11},

nitpick: I don't totally disagree with these changes, but they are
unrelated to the patch at hand, so I think we'd better leave them out.

> +	/* reject conflicting "-only" options */
> +	if (globals_only && with_statistics)
> +		pg_fatal("options %s and %s cannot be used together",
> +				 "-g/--globals-only", "--statistics");
> +
> +	if (data_only && roles_only)
> +		pg_fatal("options %s and %s cannot be used together",
> +				 "-a/--data-only", "-r/--roles-only");
> [...]
> +
> +	if (data_only && tablespaces_only)
> +		pg_fatal("options %s and %s cannot be used together",
> +				 "-a/--data-only", "-t/--tablespaces-only");
> [...]

Could we integrate this into the existing handling for conflicting options
a few lines above this point?

> -	if (!data_only && !statistics_only && !no_schema)

I wonder if we ought to create "derivative flags" like we did for pg_dump
in commit 96a81c1be9.  That could make some of this stuff easier to
maintain and to follow.

> 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 => {

Could you add some new tests for the conflicting options?

-- 
nathan



Commits

  1. pg_dumpall: Fix handling of conflicting options.

  2. pg_dump: Add dumpSchema and dumpData derivative flags.