From 0ce85b65606876715fea56de6f75981a370a51a2 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathandbossart@gmail.com>
Date: Tue, 6 Sep 2022 10:23:56 -0700
Subject: [PATCH v6 2/4] Simplify WARNING messages emitted when skipping
 vacuum/analyze for a table.

---
 src/backend/commands/vacuum.c                 |  32 ++----
 .../isolation/expected/vacuum-conflict.out    |  16 +--
 src/test/regress/expected/vacuum.out          | 102 +++++++++---------
 3 files changed, 65 insertions(+), 85 deletions(-)

diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 7ccde07de9..651e4a7556 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -579,18 +579,9 @@ vacuum_is_relation_owner(Oid relid, Form_pg_class reltuple, bits32 options)
 
 	if ((options & VACOPT_VACUUM) != 0)
 	{
-		if (reltuple->relisshared)
-			ereport(WARNING,
-					(errmsg("skipping \"%s\" --- only superuser can vacuum it",
-							relname)));
-		else if (reltuple->relnamespace == PG_CATALOG_NAMESPACE)
-			ereport(WARNING,
-					(errmsg("skipping \"%s\" --- only superuser or database owner can vacuum it",
-							relname)));
-		else
-			ereport(WARNING,
-					(errmsg("skipping \"%s\" --- only table or database owner can vacuum it",
-							relname)));
+		ereport(WARNING,
+				(errmsg("permission denied to vacuum \"%s\", skipping it",
+						relname)));
 
 		/*
 		 * For VACUUM ANALYZE, both logs could show up, but just generate
@@ -601,20 +592,9 @@ vacuum_is_relation_owner(Oid relid, Form_pg_class reltuple, bits32 options)
 	}
 
 	if ((options & VACOPT_ANALYZE) != 0)
-	{
-		if (reltuple->relisshared)
-			ereport(WARNING,
-					(errmsg("skipping \"%s\" --- only superuser can analyze it",
-							relname)));
-		else if (reltuple->relnamespace == PG_CATALOG_NAMESPACE)
-			ereport(WARNING,
-					(errmsg("skipping \"%s\" --- only superuser or database owner can analyze it",
-							relname)));
-		else
-			ereport(WARNING,
-					(errmsg("skipping \"%s\" --- only table or database owner can analyze it",
-							relname)));
-	}
+		ereport(WARNING,
+				(errmsg("permission denied to analyze \"%s\", skipping it",
+						relname)));
 
 	return false;
 }
diff --git a/src/test/isolation/expected/vacuum-conflict.out b/src/test/isolation/expected/vacuum-conflict.out
index ffde537305..77e45506c3 100644
--- a/src/test/isolation/expected/vacuum-conflict.out
+++ b/src/test/isolation/expected/vacuum-conflict.out
@@ -4,7 +4,7 @@ starting permutation: s1_begin s1_lock s2_auth s2_vacuum s1_commit s2_reset
 step s1_begin: BEGIN;
 step s1_lock: LOCK vacuum_tab IN SHARE UPDATE EXCLUSIVE MODE;
 step s2_auth: SET ROLE regress_vacuum_conflict;
-s2: WARNING:  skipping "vacuum_tab" --- only table or database owner can vacuum it
+s2: WARNING:  permission denied to vacuum "vacuum_tab", skipping it
 step s2_vacuum: VACUUM vacuum_tab;
 step s1_commit: COMMIT;
 step s2_reset: RESET ROLE;
@@ -12,7 +12,7 @@ step s2_reset: RESET ROLE;
 starting permutation: s1_begin s2_auth s2_vacuum s1_lock s1_commit s2_reset
 step s1_begin: BEGIN;
 step s2_auth: SET ROLE regress_vacuum_conflict;
-s2: WARNING:  skipping "vacuum_tab" --- only table or database owner can vacuum it
+s2: WARNING:  permission denied to vacuum "vacuum_tab", skipping it
 step s2_vacuum: VACUUM vacuum_tab;
 step s1_lock: LOCK vacuum_tab IN SHARE UPDATE EXCLUSIVE MODE;
 step s1_commit: COMMIT;
@@ -22,14 +22,14 @@ starting permutation: s1_begin s2_auth s1_lock s2_vacuum s1_commit s2_reset
 step s1_begin: BEGIN;
 step s2_auth: SET ROLE regress_vacuum_conflict;
 step s1_lock: LOCK vacuum_tab IN SHARE UPDATE EXCLUSIVE MODE;
-s2: WARNING:  skipping "vacuum_tab" --- only table or database owner can vacuum it
+s2: WARNING:  permission denied to vacuum "vacuum_tab", skipping it
 step s2_vacuum: VACUUM vacuum_tab;
 step s1_commit: COMMIT;
 step s2_reset: RESET ROLE;
 
 starting permutation: s2_auth s2_vacuum s1_begin s1_lock s1_commit s2_reset
 step s2_auth: SET ROLE regress_vacuum_conflict;
-s2: WARNING:  skipping "vacuum_tab" --- only table or database owner can vacuum it
+s2: WARNING:  permission denied to vacuum "vacuum_tab", skipping it
 step s2_vacuum: VACUUM vacuum_tab;
 step s1_begin: BEGIN;
 step s1_lock: LOCK vacuum_tab IN SHARE UPDATE EXCLUSIVE MODE;
@@ -40,7 +40,7 @@ starting permutation: s1_begin s1_lock s2_auth s2_analyze s1_commit s2_reset
 step s1_begin: BEGIN;
 step s1_lock: LOCK vacuum_tab IN SHARE UPDATE EXCLUSIVE MODE;
 step s2_auth: SET ROLE regress_vacuum_conflict;
-s2: WARNING:  skipping "vacuum_tab" --- only table or database owner can analyze it
+s2: WARNING:  permission denied to analyze "vacuum_tab", skipping it
 step s2_analyze: ANALYZE vacuum_tab;
 step s1_commit: COMMIT;
 step s2_reset: RESET ROLE;
@@ -48,7 +48,7 @@ step s2_reset: RESET ROLE;
 starting permutation: s1_begin s2_auth s2_analyze s1_lock s1_commit s2_reset
 step s1_begin: BEGIN;
 step s2_auth: SET ROLE regress_vacuum_conflict;
-s2: WARNING:  skipping "vacuum_tab" --- only table or database owner can analyze it
+s2: WARNING:  permission denied to analyze "vacuum_tab", skipping it
 step s2_analyze: ANALYZE vacuum_tab;
 step s1_lock: LOCK vacuum_tab IN SHARE UPDATE EXCLUSIVE MODE;
 step s1_commit: COMMIT;
@@ -58,14 +58,14 @@ starting permutation: s1_begin s2_auth s1_lock s2_analyze s1_commit s2_reset
 step s1_begin: BEGIN;
 step s2_auth: SET ROLE regress_vacuum_conflict;
 step s1_lock: LOCK vacuum_tab IN SHARE UPDATE EXCLUSIVE MODE;
-s2: WARNING:  skipping "vacuum_tab" --- only table or database owner can analyze it
+s2: WARNING:  permission denied to analyze "vacuum_tab", skipping it
 step s2_analyze: ANALYZE vacuum_tab;
 step s1_commit: COMMIT;
 step s2_reset: RESET ROLE;
 
 starting permutation: s2_auth s2_analyze s1_begin s1_lock s1_commit s2_reset
 step s2_auth: SET ROLE regress_vacuum_conflict;
-s2: WARNING:  skipping "vacuum_tab" --- only table or database owner can analyze it
+s2: WARNING:  permission denied to analyze "vacuum_tab", skipping it
 step s2_analyze: ANALYZE vacuum_tab;
 step s1_begin: BEGIN;
 step s1_lock: LOCK vacuum_tab IN SHARE UPDATE EXCLUSIVE MODE;
diff --git a/src/test/regress/expected/vacuum.out b/src/test/regress/expected/vacuum.out
index c63a157e5f..0035d158b7 100644
--- a/src/test/regress/expected/vacuum.out
+++ b/src/test/regress/expected/vacuum.out
@@ -295,120 +295,120 @@ CREATE ROLE regress_vacuum;
 SET ROLE regress_vacuum;
 -- Simple table
 VACUUM vacowned;
-WARNING:  skipping "vacowned" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned", skipping it
 ANALYZE vacowned;
-WARNING:  skipping "vacowned" --- only table or database owner can analyze it
+WARNING:  permission denied to analyze "vacowned", skipping it
 VACUUM (ANALYZE) vacowned;
-WARNING:  skipping "vacowned" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned", skipping it
 -- Catalog
 VACUUM pg_catalog.pg_class;
-WARNING:  skipping "pg_class" --- only superuser or database owner can vacuum it
+WARNING:  permission denied to vacuum "pg_class", skipping it
 ANALYZE pg_catalog.pg_class;
-WARNING:  skipping "pg_class" --- only superuser or database owner can analyze it
+WARNING:  permission denied to analyze "pg_class", skipping it
 VACUUM (ANALYZE) pg_catalog.pg_class;
-WARNING:  skipping "pg_class" --- only superuser or database owner can vacuum it
+WARNING:  permission denied to vacuum "pg_class", skipping it
 -- Shared catalog
 VACUUM pg_catalog.pg_authid;
-WARNING:  skipping "pg_authid" --- only superuser can vacuum it
+WARNING:  permission denied to vacuum "pg_authid", skipping it
 ANALYZE pg_catalog.pg_authid;
-WARNING:  skipping "pg_authid" --- only superuser can analyze it
+WARNING:  permission denied to analyze "pg_authid", skipping it
 VACUUM (ANALYZE) pg_catalog.pg_authid;
-WARNING:  skipping "pg_authid" --- only superuser can vacuum it
+WARNING:  permission denied to vacuum "pg_authid", skipping it
 -- Partitioned table and its partitions, nothing owned by other user.
 -- Relations are not listed in a single command to test ownership
 -- independently.
 VACUUM vacowned_parted;
-WARNING:  skipping "vacowned_parted" --- only table or database owner can vacuum it
-WARNING:  skipping "vacowned_part1" --- only table or database owner can vacuum it
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_parted", skipping it
+WARNING:  permission denied to vacuum "vacowned_part1", skipping it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 VACUUM vacowned_part1;
-WARNING:  skipping "vacowned_part1" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part1", skipping it
 VACUUM vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 ANALYZE vacowned_parted;
-WARNING:  skipping "vacowned_parted" --- only table or database owner can analyze it
-WARNING:  skipping "vacowned_part1" --- only table or database owner can analyze it
-WARNING:  skipping "vacowned_part2" --- only table or database owner can analyze it
+WARNING:  permission denied to analyze "vacowned_parted", skipping it
+WARNING:  permission denied to analyze "vacowned_part1", skipping it
+WARNING:  permission denied to analyze "vacowned_part2", skipping it
 ANALYZE vacowned_part1;
-WARNING:  skipping "vacowned_part1" --- only table or database owner can analyze it
+WARNING:  permission denied to analyze "vacowned_part1", skipping it
 ANALYZE vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can analyze it
+WARNING:  permission denied to analyze "vacowned_part2", skipping it
 VACUUM (ANALYZE) vacowned_parted;
-WARNING:  skipping "vacowned_parted" --- only table or database owner can vacuum it
-WARNING:  skipping "vacowned_part1" --- only table or database owner can vacuum it
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_parted", skipping it
+WARNING:  permission denied to vacuum "vacowned_part1", skipping it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 VACUUM (ANALYZE) vacowned_part1;
-WARNING:  skipping "vacowned_part1" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part1", skipping it
 VACUUM (ANALYZE) vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 RESET ROLE;
 -- Partitioned table and one partition owned by other user.
 ALTER TABLE vacowned_parted OWNER TO regress_vacuum;
 ALTER TABLE vacowned_part1 OWNER TO regress_vacuum;
 SET ROLE regress_vacuum;
 VACUUM vacowned_parted;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 VACUUM vacowned_part1;
 VACUUM vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 ANALYZE vacowned_parted;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can analyze it
+WARNING:  permission denied to analyze "vacowned_part2", skipping it
 ANALYZE vacowned_part1;
 ANALYZE vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can analyze it
+WARNING:  permission denied to analyze "vacowned_part2", skipping it
 VACUUM (ANALYZE) vacowned_parted;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 VACUUM (ANALYZE) vacowned_part1;
 VACUUM (ANALYZE) vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 RESET ROLE;
 -- Only one partition owned by other user.
 ALTER TABLE vacowned_parted OWNER TO CURRENT_USER;
 SET ROLE regress_vacuum;
 VACUUM vacowned_parted;
-WARNING:  skipping "vacowned_parted" --- only table or database owner can vacuum it
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_parted", skipping it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 VACUUM vacowned_part1;
 VACUUM vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 ANALYZE vacowned_parted;
-WARNING:  skipping "vacowned_parted" --- only table or database owner can analyze it
-WARNING:  skipping "vacowned_part2" --- only table or database owner can analyze it
+WARNING:  permission denied to analyze "vacowned_parted", skipping it
+WARNING:  permission denied to analyze "vacowned_part2", skipping it
 ANALYZE vacowned_part1;
 ANALYZE vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can analyze it
+WARNING:  permission denied to analyze "vacowned_part2", skipping it
 VACUUM (ANALYZE) vacowned_parted;
-WARNING:  skipping "vacowned_parted" --- only table or database owner can vacuum it
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_parted", skipping it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 VACUUM (ANALYZE) vacowned_part1;
 VACUUM (ANALYZE) vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 RESET ROLE;
 -- Only partitioned table owned by other user.
 ALTER TABLE vacowned_parted OWNER TO regress_vacuum;
 ALTER TABLE vacowned_part1 OWNER TO CURRENT_USER;
 SET ROLE regress_vacuum;
 VACUUM vacowned_parted;
-WARNING:  skipping "vacowned_part1" --- only table or database owner can vacuum it
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part1", skipping it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 VACUUM vacowned_part1;
-WARNING:  skipping "vacowned_part1" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part1", skipping it
 VACUUM vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 ANALYZE vacowned_parted;
-WARNING:  skipping "vacowned_part1" --- only table or database owner can analyze it
-WARNING:  skipping "vacowned_part2" --- only table or database owner can analyze it
+WARNING:  permission denied to analyze "vacowned_part1", skipping it
+WARNING:  permission denied to analyze "vacowned_part2", skipping it
 ANALYZE vacowned_part1;
-WARNING:  skipping "vacowned_part1" --- only table or database owner can analyze it
+WARNING:  permission denied to analyze "vacowned_part1", skipping it
 ANALYZE vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can analyze it
+WARNING:  permission denied to analyze "vacowned_part2", skipping it
 VACUUM (ANALYZE) vacowned_parted;
-WARNING:  skipping "vacowned_part1" --- only table or database owner can vacuum it
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part1", skipping it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 VACUUM (ANALYZE) vacowned_part1;
-WARNING:  skipping "vacowned_part1" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part1", skipping it
 VACUUM (ANALYZE) vacowned_part2;
-WARNING:  skipping "vacowned_part2" --- only table or database owner can vacuum it
+WARNING:  permission denied to vacuum "vacowned_part2", skipping it
 RESET ROLE;
 DROP TABLE vacowned;
 DROP TABLE vacowned_parted;
-- 
2.25.1

