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 1qBfLS-0003XI-UQ for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jun 2023 17:40:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qBfLR-0004zw-9X for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jun 2023 17:40:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qBfLQ-0004zn-QF for pgsql-hackers@lists.postgresql.org; Tue, 20 Jun 2023 17:40:45 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qBfLJ-003HVN-SH for pgsql-hackers@postgresql.org; Tue, 20 Jun 2023 17:40:43 +0000 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-553ad54d3c6so1369379a12.1 for ; Tue, 20 Jun 2023 10:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687282836; x=1689874836; 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=1hXfdgE5r8juU82AdO1QUviNzqy76B8vANourhD6IBA=; b=cp+EitW8l/Mt4bOJKaY8jODha2AB7Gt0wN3ijg3FQ3U19jTBmSo0X4ADI+hiZA17ZM jgpyghJNV8/d/9HjRCe81t4DqTGT3cG9fIufUjImBKrmio/rfR1Sm1XgTjed5trBetbH IueIyF7R8CvAh+9g/WG1GJozSITHfsPeuajC6+zZnVmqf++itnJkjPxzoHCskd/9jpci nUPPUkdrkEy3L2uo8UDsJtnIHGqRgdxO8Zisyct69M0ZvAOnO5ofbcSx3zORhZhRmLUr Ks8OikU68VALVhea5t+Cqd3xRHipSJgiD++VXczxkxSFf1oA7vWOCjKGuoTelPzETSXL 8LTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687282836; x=1689874836; 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=1hXfdgE5r8juU82AdO1QUviNzqy76B8vANourhD6IBA=; b=h5nL7Fn33wUl1C+H3/XpT4JnRDbrfPgAob2Au+qhOgEEH2FxM3gI6ohue7WIHfW1cV 7lP2GHomcrDrZESoVUNhuhQD0NqrUjo9GB2+b4yT5SPKIv1eeWW9u8w8BgwTKhY+Hua5 r1e3ckY9TI2YgvlqkXRAHTFn0k7iEAR5J5sKrdWuJZCfZWX8ZyaESWz9lwte6ZwDuPSX HDe2bavoB1i8AsyQ54Fe/Cd5cgq9yMum9QTyqmS6MXn98oG4NiGwU8yC7nDqcmh20o/2 AEskBAMQdpZglaSZxq1LJp2y5m9ajxP9A7eaia/VPVuFNn696pqQQPH7nTIMCQtPORMr +Zqw== X-Gm-Message-State: AC+VfDzW4M39/QnSunQ/ZCH+iUE8+o6o1I5f54fh52tS7EsNuT30pX31 ewNsoK+gqaguDgzfBEpxzbJlGAv4JjY= X-Google-Smtp-Source: ACHHUZ5ygFHAbkQSoxuURwyn0w3mBd60Ss7L4EA8Z+cryO4ogzeZxnRB1j4/LMR10v+eoTUmlvVbFA== X-Received: by 2002:a05:6a20:918b:b0:114:6993:5a3b with SMTP id v11-20020a056a20918b00b0011469935a3bmr10473051pzd.13.1687282836023; Tue, 20 Jun 2023 10:40:36 -0700 (PDT) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id j18-20020aa79292000000b006589cf6d88bsm1628934pfa.145.2023.06.20.10.40.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 10:40:35 -0700 (PDT) Date: Tue, 20 Jun 2023 10:40:32 -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: <20230620174032.GA471329@nathanxps13> References: <20230613211246.GA219055@nathanxps13> <20230613235442.GA222795@nathanxps13> <20230614181711.GA488295@nathanxps13> <20230615041044.GA736001@nathanxps13> <20230615235700.GA877311@nathanxps13> <20230616052025.GA1026700@nathanxps13> <20230619215534.GA442477@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="h31gzZEtNLTqOjlF" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jun 20, 2023 at 10:04:37AM -0700, Jeff Davis wrote: > I think v4-0001 broke the handling of toast tables? It looks like you > removed the check for !skip_privs but need to add it to the flags in > vacuum_is_permitted_for_relation(). Good catch. I'm not sure why some of the calls to vacuum_is_permitted_for_relation() are masking the options. AFAICT we can simply remove the masks. I've done so in the attached patch. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --h31gzZEtNLTqOjlF Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v5-0001-convert-boolean-parameter-into-a-VACOPT_-option.patch" From b7528138025f6fae062008fe4e166957789bdc25 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 14 Jun 2023 11:08:03 -0700 Subject: [PATCH v5 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..08f7ba1623 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)) { relation_close(onerel, ShareUpdateExclusiveLock); return; diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index a843f9ad92..108b5640d1 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)) { 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 --h31gzZEtNLTqOjlF--