From f8335c148469c0041096de50115b6fbd9c9bb5af Mon Sep 17 00:00:00 2001 From: Colm Date: Thu, 5 Dec 2024 10:03:28 +0000 Subject: [PATCH] PG17 compatibility: fix diffs in create_index, privileges vanilla tests (#7766) PG17 regress sanity (#7653) fix; address diffs in vanilla tests `create_index` and `privileges`. There is a change from `permission denied` to `must be owner of`, seen in create_index: ``` @@ -2970,21 +2970,21 @@ REINDEX TABLE pg_toast.pg_toast_1260; ERROR: permission denied for table pg_toast_1260 REINDEX INDEX pg_toast.pg_toast_1260_index; -ERROR: permission denied for index pg_toast_1260_index +ERROR: must be owner of index pg_toast_1260_index ``` and privileges: ``` @@ -2945,41 +2945,43 @@ ERROR: permission denied for table maintain_test REINDEX INDEX maintain_test_a_idx; -ERROR: permission denied for index maintain_test_a_idx +ERROR: must be owner of index maintain_test_a_idx REINDEX SCHEMA reindex_test; REINDEX INDEX maintain_test_a_idx; +ERROR: must be owner of index maintain_test_a_idx REINDEX SCHEMA reindex_test; ``` The fix updates function `RangeVarCallbackForReindexIndex()` in `index.c` with changes made by the introduction of the [MAINTAIN privilege in PG17](https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=ecb0fd337) to the function `RangeVarCallbackForReindexIndex()` in `indexcmds.c`. The code is under a Postgres 17 version directive, which can be removed when 17 becomes the oldest supported Postgres version. --- src/backend/distributed/commands/index.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/commands/index.c b/src/backend/distributed/commands/index.c index f4943ebde..1401da0a6 100644 --- a/src/backend/distributed/commands/index.c +++ b/src/backend/distributed/commands/index.c @@ -1115,6 +1115,7 @@ RangeVarCallbackForReindexIndex(const RangeVar *relation, Oid relId, Oid oldRelI char relkind; struct ReindexIndexCallbackState *state = arg; LOCKMODE table_lockmode; + Oid table_oid; /* * Lock level here should match table lock in reindex_index() for @@ -1152,13 +1153,24 @@ RangeVarCallbackForReindexIndex(const RangeVar *relation, Oid relId, Oid oldRelI errmsg("\"%s\" is not an index", relation->relname))); /* Check permissions */ + + #if PG_VERSION_NUM >= PG_VERSION_17 + table_oid = IndexGetRelation(relId, true); + if (OidIsValid(table_oid)) + { + AclResult aclresult = pg_class_aclcheck(table_oid, GetUserId(), ACL_MAINTAIN); + if (aclresult != ACLCHECK_OK) + aclcheck_error(aclresult, OBJECT_INDEX, relation->relname); + } + #else if (!object_ownercheck(RelationRelationId, relId, GetUserId())) aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_INDEX, relation->relname); + #endif /* Lock heap before index to avoid deadlock. */ if (relId != oldRelId) { - Oid table_oid = IndexGetRelation(relId, true); + table_oid = IndexGetRelation(relId, true); /* * If the OID isn't valid, it means the index was concurrently