Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qBfat-0004EV-QU for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jun 2023 17:56:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qBfas-0003EJ-AU for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jun 2023 17:56:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qBfar-0003E8-W2 for pgsql-hackers@lists.postgresql.org; Tue, 20 Jun 2023 17:56:42 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qBfao-003fQy-VF for pgsql-hackers@postgresql.org; Tue, 20 Jun 2023 17:56:41 +0000 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-25bf4b269e0so4150132a91.0 for ; Tue, 20 Jun 2023 10:56:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687283797; x=1689875797; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=05mpuLnzExXSLmVo/IM1kDZb4yBjctHW4OYM2VNSUVs=; b=TxQFfqhhhnnIGpzBW1P+/avDejMIjTHzWCQJALkJyzKlUHYxHxM5KkchHTKJggLy+w vMCYa6mwuHV4G7728gfPy7KQ7SAGprCYZnRfG6YTAaWDlvXWKom3fqPTMjCMYgz6IufN itAqsUlr3zmRK+aMSomMPn+Wq22p5dObl8PmXCIK5trbdd7qtt3tTYiOUtegZScECkA1 HPxrAvBSaFBQo6CSU4zFzIY2BFKJ2NrYoyiquSimUpZIbb6WDfDFVCq8Wwf4y9/DRV0n D1MfvukV5DchXv9Nqz25ELrwfDQr4E0VIjvlbNVatv9KT0GFUUTMmx18zSXtP9XDgLQi TJOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687283797; x=1689875797; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=05mpuLnzExXSLmVo/IM1kDZb4yBjctHW4OYM2VNSUVs=; b=Zha9q9U6IsKHqIgXs5fs62QjJ51qab1LujUo+Yum78Ygr0fJ+V+6tEw+hYpuctQb/i Ln3dKE0k4g0Z3CtlVWegXQdY1LkLro/ORuAPAVF5Vx5rn3pSsPzDcwBuMhPmyL6r1Xye Ic9/1BiA7Nj3VM4ftMM1xXOjtxU8ZP2dcSX7SEnQw9P8FK80OQNWNk4/5ee+Jdq3nnxI j+kDzZ/re2Nwy78DGepvTiNMJMmV1dZmAlZfqdMpoTIIJinOGCjR73sx3M1wAbAT1oaA V+vW/XBusCLqluaum8UaEO2qPRL0dvO2Cx9AYgR8j+czERF04IGCscPKIa/d5s1/NCTF 6ghA== X-Gm-Message-State: AC+VfDz0+GFqot2rJ+qeKawkPCTmW7Bn3Y9ekV8aNqq7jMFF97kLVe7T z57g8pKHgMoatv3OGdunqUY= X-Google-Smtp-Source: ACHHUZ4YEu1JeMptju/OwwSSJbw2GVxNmfp9AIlQvmXuxCWV6pdt/r63YRtAJX99/EF5NwIPw/vHBQ== X-Received: by 2002:a17:90a:7282:b0:25e:7ffb:8a5e with SMTP id e2-20020a17090a728200b0025e7ffb8a5emr18498310pjg.7.1687283796965; Tue, 20 Jun 2023 10:56:36 -0700 (PDT) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id ok4-20020a17090b1d4400b00250d670306esm1776343pjb.35.2023.06.20.10.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 10:56:36 -0700 (PDT) Date: Tue, 20 Jun 2023 10:56:34 -0700 From: Nathan Bossart To: Jeff Davis Cc: Michael Paquier , Ted Yu , Pavel Luzanov , Justin Pryzby , pgsql-hackers@postgresql.org Subject: Re: allow granting CLUSTER, REFRESH MATERIALIZED VIEW, and REINDEX Message-ID: <20230620175634.GB494037@nathanxps13> References: <20230613235442.GA222795@nathanxps13> <20230614181711.GA488295@nathanxps13> <20230615041044.GA736001@nathanxps13> <20230615235700.GA877311@nathanxps13> <20230616052025.GA1026700@nathanxps13> <20230619215534.GA442477@nathanxps13> <20230620174032.GA471329@nathanxps13> <20230620174927.GA494037@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="HcAYCG3uE/tztfnV" Content-Disposition: inline In-Reply-To: <20230620174927.GA494037@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jun 20, 2023 at 10:49:27AM -0700, Nathan Bossart wrote: > Patch incoming... Attached. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --HcAYCG3uE/tztfnV Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v6-0001-convert-boolean-parameter-into-a-VACOPT_-option.patch" From 8842b58808372175202960c0a7067b5f00eee122 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 14 Jun 2023 11:08:03 -0700 Subject: [PATCH v6 1/1] convert boolean parameter into a VACOPT_* option --- src/backend/commands/analyze.c | 2 +- src/backend/commands/vacuum.c | 28 +++++++++++++++++++--------- src/include/commands/vacuum.h | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 52ef462dba..fc9a371f9b 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -167,7 +167,7 @@ analyze_rel(Oid relid, RangeVar *relation, */ if (!vacuum_is_permitted_for_relation(RelationGetRelid(onerel), onerel->rd_rel, - params->options & VACOPT_ANALYZE)) + params->options & ~VACOPT_VACUUM)) { relation_close(onerel, ShareUpdateExclusiveLock); return; diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index a843f9ad92..bb79de4da6 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -115,7 +115,7 @@ static void vac_truncate_clog(TransactionId frozenXID, TransactionId lastSaneFrozenXid, MultiXactId lastSaneMinMulti); static bool vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params, - bool skip_privs, BufferAccessStrategy bstrategy); + BufferAccessStrategy bstrategy); static double compute_parallel_delay(void); static VacOptValue get_vacoptval_from_boolean(DefElem *def); static bool vac_tid_reaped(ItemPointer itemptr, void *state); @@ -620,8 +620,7 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy, if (params->options & VACOPT_VACUUM) { - if (!vacuum_rel(vrel->oid, vrel->relation, params, false, - bstrategy)) + if (!vacuum_rel(vrel->oid, vrel->relation, params, bstrategy)) continue; } @@ -712,6 +711,13 @@ vacuum_is_permitted_for_relation(Oid relid, Form_pg_class reltuple, Assert((options & (VACOPT_VACUUM | VACOPT_ANALYZE)) != 0); + /* + * Privilege checks are bypassed in some cases (e.g., when recursing to a + * relation's TOAST table). + */ + if (options & VACOPT_SKIP_PRIVS) + return true; + /*---------- * A role has privileges to vacuum or analyze the relation if any of the * following are true: @@ -1953,7 +1959,7 @@ vac_truncate_clog(TransactionId frozenXID, */ static bool vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params, - bool skip_privs, BufferAccessStrategy bstrategy) + BufferAccessStrategy bstrategy) { LOCKMODE lmode; Relation rel; @@ -2040,10 +2046,9 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params, * happen across multiple transactions where privileges could have changed * in-between. Make sure to only generate logs for VACUUM in this case. */ - if (!skip_privs && - !vacuum_is_permitted_for_relation(RelationGetRelid(rel), + if (!vacuum_is_permitted_for_relation(RelationGetRelid(rel), rel->rd_rel, - params->options & VACOPT_VACUUM)) + params->options & ~VACOPT_ANALYZE)) { relation_close(rel, lmode); PopActiveSnapshot(); @@ -2229,11 +2234,16 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params, { VacuumParams toast_vacuum_params; - /* force VACOPT_PROCESS_MAIN so vacuum_rel() processes it */ + /* + * Force VACOPT_PROCESS_MAIN so vacuum_rel() processes it. Likewise, + * set VACOPT_SKIP_PRIVS since privileges on the main relation are + * sufficient to process it. + */ memcpy(&toast_vacuum_params, params, sizeof(VacuumParams)); toast_vacuum_params.options |= VACOPT_PROCESS_MAIN; + toast_vacuum_params.options |= VACOPT_SKIP_PRIVS; - vacuum_rel(toast_relid, NULL, &toast_vacuum_params, true, bstrategy); + vacuum_rel(toast_relid, NULL, &toast_vacuum_params, bstrategy); } /* diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h index 17e9b4f68e..cb5b11ab31 100644 --- a/src/include/commands/vacuum.h +++ b/src/include/commands/vacuum.h @@ -191,6 +191,7 @@ typedef struct VacAttrStats #define VACOPT_DISABLE_PAGE_SKIPPING 0x100 /* don't skip any pages */ #define VACOPT_SKIP_DATABASE_STATS 0x200 /* skip vac_update_datfrozenxid() */ #define VACOPT_ONLY_DATABASE_STATS 0x400 /* only vac_update_datfrozenxid() */ +#define VACOPT_SKIP_PRIVS 0x800 /* skip privilege checks */ /* * Values used by index_cleanup and truncate params. -- 2.25.1 --HcAYCG3uE/tztfnV--