Re: pg_dumpall --roles-only interact with other options - Mailing list pgsql-hackers

From Chao Li
Subject Re: pg_dumpall --roles-only interact with other options
Date
Msg-id 2FAB1AE3-7812-4603-A314-E2D3189AA5C8@gmail.com
Whole thread Raw
In response to Re: pg_dumpall --roles-only interact with other options  (Nathan Bossart <nathandbossart@gmail.com>)
Responses Re: pg_dumpall --roles-only interact with other options
Re: pg_dumpall --roles-only interact with other options
List pgsql-hackers

> On Mar 3, 2026, at 06:41, Nathan Bossart <nathandbossart@gmail.com> wrote:
>
> On Mon, Mar 02, 2026 at 10:23:17PM +0000, Zsolt Parragi wrote:
>> New version looks good!
>
> I'm not thrilled about the long list of checks.  What if we added a
> function that could check an arbitrary number of mutually exclusive
> options, a bit like the attached?
>
> --
> nathan
> <v8-0001-pg_dumpall-error-out-conflict-options.patch>

Yeah, the new helper function makes the code much cleaner, good job.

A few comments on v8:

1 - dumputils.c
```
+void
+CheckMutuallyExclusiveOpts(int n,...)
+{
+    char       *first = NULL;
+    va_list        args;
+
+    va_start(args, n);
+    for (int i = 0; i < n; i += 2)
```

I think we can Assert(n % 2 == 0).

If a future code author mistakenly forgets an option name, the compiler won’t detect that, and runtime will only show
“null”for the option name. 

I tried to delete the last option name from the first CheckMutuallyExclusiveOpts call, then I got:
```
% pg_dumpall -a --no-data
pg_dumpall: error: options -a/--data-only and (null) cannot be used together
```

2 - dumputils.c
```
+            pg_fatal("options %s and %s cannot be used together",
+                     first, opt);
```

The current code also shows a hint upon the error, do we want to retain that?
```
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
```

3 - 001_basic.pl
```
+    'pg_dumpall: error: options /-s\/--schema-only and --statistics-only cannot be used together'
```

“/“ before “-s” seems not needed.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/







pgsql-hackers by date:

Previous
From: Lukas Fittl
Date:
Subject: Re: pg_buffercache: Add per-relation summary stats
Next
From: Thomas Munro
Date:
Subject: Exploring pass-by-value for small Bitmapset sets