From be0d0b457cb605f6e539f92af5e564fbe9d65e59 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 16 Mar 2026 11:01:20 -0500 Subject: [PATCH] pg_dumpall: Fix handling of incompatible options. This commit teaches pg_dumpall to fail when both --clean and --data-only are specified. Previously, it passed the options through to pg_dump, which would fail after pg_dumpall had already started producing output. Like recent commits b2898baaf7 and 7c8280eeb5, no back-patch. Author: Mahendra Singh Thalor Reviewed-by: Srinath Reddy Sadipiralla Discussion: https://postgr.es/m/CAKYtNArrHiJ0LDB9BFZiUWs6tC78QkBN50wiwO07WhxewYDS3Q%40mail.gmail.com --- src/bin/pg_dump/pg_dumpall.c | 4 ++++ src/bin/pg_dump/t/001_basic.pl | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 3d2a1d27aef..20cdd2d92f0 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -455,6 +455,10 @@ main(int argc, char *argv[]) schema_only, "-s/--schema-only", tablespaces_only, "-t/--tablespaces-only"); + /* --clean and --data-only are incompatible */ + check_mut_excl_opts(output_clean, "-c/--clean", + data_only, "-a/--data-only"); + if (if_exists && !output_clean) pg_fatal("option %s requires option %s", "--if-exists", "-c/--clean"); diff --git a/src/bin/pg_dump/t/001_basic.pl b/src/bin/pg_dump/t/001_basic.pl index 2f5eb48e7b8..86eec1b0064 100644 --- a/src/bin/pg_dump/t/001_basic.pl +++ b/src/bin/pg_dump/t/001_basic.pl @@ -101,6 +101,11 @@ command_fails_like( qr/\Qpg_dump: error: options -c\/--clean and -a\/--data-only cannot be used together\E/, 'pg_dump: options -c/--clean and -a/--data-only cannot be used together'); +command_fails_like( + [ 'pg_dumpall', '-c', '-a' ], + qr/\Qpg_dumpall: error: options -c\/--clean and -a\/--data-only cannot be used together\E/, + 'pg_dumpall: options -c/--clean and -a/--data-only cannot be used together'); + command_fails_like( [ 'pg_restore', '-c', '-a', '-f -' ], qr/\Qpg_restore: error: options -c\/--clean and -a\/--data-only cannot be used together\E/,