v02-PG14-pg_dumpall-clean-and-data-only-are-incompatible.noci

application/octet-stream

Filename: v02-PG14-pg_dumpall-clean-and-data-only-are-incompatible.noci
Type: application/octet-stream
Part: 2
Message: Re: bug: pg_dumpall with --data-only and --clean options is giving an error after some dump
From 84ff3fc8efe7cbd07f41697ee83e3d3c395e0fff Mon Sep 17 00:00:00 2001
From: Mahendra Singh Thalor <mahi6run@gmail.com>
Date: Sun, 15 Mar 2026 19:10:26 +0530
Subject: [PATCH] PG14 pg_dumpall: -clean and --data-only are incompatible

Report error when -clean and --data-only are given with pg_dumpall.

As of now, we are dumping some data and later we are exiting with
error from pg_dump

PG14
---
---
 src/bin/pg_dump/pg_dumpall.c   | 9 +++++++++
 src/bin/pg_dump/t/001_basic.pl | 5 +++++
 2 files changed, 14 insertions(+)

diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index a5e3bcca514..a85f36e07a0 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -388,6 +388,15 @@ main(int argc, char *argv[])
 		exit_nicely(1);
 	}
 
+	/* --clean and --data-only are incompatible */
+	if (output_clean && data_only)
+	{
+		pg_log_error("options -c/--clean and -a/--data-only cannot be used together");
+		fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
+				progname);
+		exit_nicely(1);
+	}
+
 	if (if_exists && !output_clean)
 	{
 		pg_log_error("option --if-exists requires option -c/--clean");
diff --git a/src/bin/pg_dump/t/001_basic.pl b/src/bin/pg_dump/t/001_basic.pl
index 9f12ca6c51d..131ae99fccc 100644
--- a/src/bin/pg_dump/t/001_basic.pl
+++ b/src/bin/pg_dump/t/001_basic.pl
@@ -52,6 +52,11 @@ command_fails_like(
 	'pg_dump: options -s/--schema-only 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_dump', '-s', '--include-foreign-data=xxx' ],
 	qr/\Qpg_dump: error: options -s\/--schema-only and --include-foreign-data cannot be used together\E/,
-- 
2.52.0