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 1neabm-0006T1-53 for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Apr 2022 10:52:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1neabl-0000vH-0f for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Apr 2022 10:52:21 +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 1neabk-0000v8-Kr for pgsql-hackers@lists.postgresql.org; Wed, 13 Apr 2022 10:52:20 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1neabh-0007Uk-OT for pgsql-hackers@lists.postgresql.org; Wed, 13 Apr 2022 10:52:20 +0000 Received: by mail-io1-xd32.google.com with SMTP id x4so1381948iop.7 for ; Wed, 13 Apr 2022 03:52:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=tmdV4ghUFa8acM46h9xWoEpX2H2kXVIE70nsiYeKeOk=; b=6uLwfFL2qEYpQ1iOe3PL5IBketAO/ejoNv2fLI+hdqpK4b9XGYfaxqE8a1oFUnGbsA lYKNwYzzr+T5avf+eXT0Md7VqO9P8Kzh0Hi//RuOrYoCRKq8mbOsiY/l7/XQ+vDXQPRF RwRi1vr9Bl60H4tcmw1SBpgDLmWTxDIYo+UQ45VCwagMnX5hf73Jwa9LLt6e22bRZhAi nDF2U57BjuFSgWW10iWTJ9TEKYcBV9OS5FJoZRgUEt6oGyy7gJLBtkkSORcMMGVmg8up asS6F5eTriu0/PVCUpwO48ACx651YbGLbGUYKIlGkFii78nkgS1HdJRtHxcrfqMwBrFj asAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=tmdV4ghUFa8acM46h9xWoEpX2H2kXVIE70nsiYeKeOk=; b=0C5CmUwTL+mO8BeSbKT80Earw2L5xEvtQyJY4N8a2tZfEl6C4CZSfDkmNS+WK3W9xX 7mOPrOFSiUZCRrA4GVRvXET+CQRRAl3C+uU1wnBW2iyzUO3jMikgF31nW+1Uz6lJ77UD 9P/EdHdmkY5yFvBsOZAtvVTFY+E7l+5KWU8TXsG7lN67rJ82lbaGxVWsU/aQPenN8wnW ZSwS45AwXqd1aedfw+aDwRmmEy/WaTJFuzZvhsvTXLqpruToaazb093BZQpLVwGgfYXI WEnmLAvCJ1qmGMdXfk3oLY7wkYvuMgHiwclqVOMgOVqA3sq21wyQbOUt68f5FtRUs/3S 6Onw== X-Gm-Message-State: AOAM531LAB/aMeu8r4NZHz5il2Th8h/FgWdtg8Lcp3jE5BiDdEEu1cWx VA7n4TNNR1QlVI1ttGvroWCJbQ== X-Google-Smtp-Source: ABdhPJwcf3ema8qWSCA0ooqwTjs0WnK9Es0qW7sT5DH0b0paLEcHNhjdeN7qiuE8s4gCMJw7NhRHvA== X-Received: by 2002:a05:6638:3385:b0:325:fd95:4531 with SMTP id h5-20020a056638338500b00325fd954531mr11281041jav.260.1649847135518; Wed, 13 Apr 2022 03:52:15 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id x8-20020a0566022c4800b006464119d985sm22810770iov.43.2022.04.13.03.52.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Apr 2022 03:52:15 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 5F861800C97; Wed, 13 Apr 2022 05:52:14 -0500 (CDT) Date: Wed, 13 Apr 2022 05:52:14 -0500 From: Justin Pryzby To: Michael Paquier Cc: Alvaro Herrera , =?utf-8?B?5p2O5p2wKOaFjui/vSk=?= , pgsql-hackers@lists.postgresql.org, =?utf-8?B?5pu+5paH5peMKOS5ieS7jik=?= , Zhihong Yu Subject: Re: CLUSTER on partitioned index Message-ID: <20220413105214.GL26620@telsasoft.com> References: <202204021711.zf24w66t6o6w@alvherre.pgsql> <202204021721.myr2alroeunz@alvherre.pgsql> <20220411140609.GF26620@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Apr 13, 2022 at 03:50:15PM +0900, Michael Paquier wrote: > > > That dates to a556549d7 (see also cbe24a6dd8 for an earlier commit in CLUSTER > > itself). The reason was to avoid blocking if an unprivileged user runs VACUUM > > FULL which would try to lock things (including shared catalogs) before checking > > if they have permission to vacuum them. That commit also initially checks the > > owner of the partitioned table, and then re-checking owner of partitions later > > on. > > > > A similar issue exists here. But 1) catalog tables are not partitioned, and, > > 2) ownership of a partitioned table is checked immediately. So the problem can > > only occur if a user who owns a partitioned table but doesn't own all its > > partitions tries to cluster it, and it blocks behind another session. Fixing > > this is probably a good idea, but seems improbable that it would avoid a DOS. > > Catalogs are out of the picture as you say and I would not worry about > them becoming somewhat partitioned even in the far future. Are you > saying that it is possible for a user kicking a CLUSTER command on a > partitioned table who has no ownership on some of the partitions to > do some blocking table_open() calls if the permission check is not > done in get_tables_to_cluster_partitioned()? Hence, this user could > block the access to such partitions? I am not sure that we need to > add any new ownership checks here as CLUOPT_RECHECK gets added to the > parameters in cluster() before calling cluster_multiple_rels(), then > we do a mix of try_relation_open() with a skip when we are not the > owner anymore. So this logic looks sound to me. In short, you don't > need this extra check, and the test proposed in 0002 keeps the same > behavior. Are you sure? The ownership re-check in cluster_rel() occurs after acquiring locks. s1: postgres=# CREATE TABLE p(i int) PARTITION BY LIST (i); postgres=# CREATE TABLE p1 PARTITION OF p FOR VALUES IN (1); postgres=# CREATE TABLE p2 PARTITION OF p FOR VALUES IN (2); postgres=# CREATE INDEX ON p (i); postgres=# CREATE ROLE po WITH LOGIN; postgres=# ALTER TABLE p OWNER TO po; postgres=# begin; SELECT FROM p1; s2: postgres=> SET client_min_messages =debug; postgres=> CLUSTER VERBOSE p USING p_i_idx ; LOG: process 26058 still waiting for AccessExclusiveLock on relation 39577 of database 5 after 1000.105 ms postgres=> SELECT 39577::regclass; regclass | p1