Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1suamP-007zoh-P1 for pgsql-general@arkaria.postgresql.org; Sat, 28 Sep 2024 16:58:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1suamO-00AfOC-V9 for pgsql-general@arkaria.postgresql.org; Sat, 28 Sep 2024 16:58:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1suamN-00AfNm-Df for pgsql-general@lists.postgresql.org; Sat, 28 Sep 2024 16:58:48 +0000 Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1suamC-001YFj-Si for pgsql-general@lists.postgresql.org; Sat, 28 Sep 2024 16:58:46 +0000 Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 45DC51140126; Sat, 28 Sep 2024 12:58:36 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Sat, 28 Sep 2024 12:58:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1727542716; x=1727629116; bh=h0sRMGP1t81kVH7X+kbzCRXi1jKgqVg9iKpHohmFtcg=; b= hA1iSaJUOTPepZcux0QzufjiKsPfUSkEjX9TzC+nk6BQ2Noep36zm1PtjMA7dsf9 Qvoy/1Cv999wcAlcr63V03bGWDE8tgIU8eqP+fwWSkz/I7A71ta4fP+zEHxii2e9 rJXHhlZzqjDMaSP6FJ5y+7KzKWgyX2wfzakhej7E5HN9kDTG+RIIJ0TSeMsJfWJf dmWPIfRRJfLv/n3PHe/0d4OtKAPqIK1uLoxNhfM+hu9nAH1M5bmxzGJ4n+WIWlMm cCXuCTzaVrPxdTN9UgQiJJJpae4ji87nME4FGRW923tq5EojbfKOghSWML/p5mjd 7wg+ib+0qWOG7mHs7/Tzfg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727542716; x= 1727629116; bh=h0sRMGP1t81kVH7X+kbzCRXi1jKgqVg9iKpHohmFtcg=; b=X Ay0I9scBIMhWPjBEvkLC2CPm567LxuyA1e5L7t44arYbnzmW50PX7OEXZDe0iRi8 o4ZLp63acgrxcTAnNZPMNSvfHmt0x1d7DnSYlBB6htvw/10Nqx4nqV3mgkV/U/Is RicUi53I/xg18YTDw0zbwLQML4Uw1frcaPnurvsd4fjrJhMZfwdwJQ+wi0D56uXp 9/QVhoKs29Uoj9ndE1WpQzFJn65wnJzAel9PSPBqEOhtM9o7fCNufR2DroZNx4p/ PnzZWr1yH9iYXSx37yyaMHD+8TpczhkRIcWjKrlCN5t/ddqze8FCJ5ZQCS6nFr4j SyeqXq/9DzGpsFtdDlM4w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduuddgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfg fuvfevfhfhjggtgfesthekredttddvjeenucfhrhhomheptegurhhirghnucfmlhgrvhgv rhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrg htthgvrhhnpefhvdffgffhheekveevhfdtteevhefgfeejveffgeefueevheevudefgeek leekgfenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhpghgpphgrrhhtmhgrnhdrmh gunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggu rhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhdpnhgspghrtghpthhtohepvd dpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhokhhnrghthhdrjeefsehgmhgr ihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrph hoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 28 Sep 2024 12:58:35 -0400 (EDT) Message-ID: Date: Sat, 28 Sep 2024 09:58:34 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Grants not working on partitions To: Lok P Cc: pgsql-general References: <4a17cf81-3fdd-4661-a0b4-1ad135f85511@aklaver.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 9/28/24 08:56, Lok P wrote: > > > On Sat, Sep 28, 2024 at 8:46 PM Adrian Klaver > wrote: > > On 9/28/24 04:02, Lok P wrote: > > Hi, > > While we are creating any new tables, we used to give SELECT > privilege > > on the newly created tables using the below command. But we are > seeing > > now , in case of partitioned tables even if we had given the > privileges > > in the same fashion, the user is not able to query specific > partitions > > but only the table. Commands like "select * from > > schema1. " are erroring out with the "insufficient > > privilege" error , even if the partition belongs to the same table. > > > > Grant SELECT ON to ; > > > > Grant was seen as a one time command which needed while creating the > > table and then subsequent partition creation for that table was > handled > > by the pg_partman extension. But that extension is not creating or > > copying any grants on the table to the users. We were expecting , > once > > the base table is given a grant , all the inherited partitions > will be > > automatically applied to those grants. but it seems it's not working > > that way. So is there any other way to handle this situation? > > > The docs are there for a reason: > > https://github.com/pgpartman/pg_partman/blob/master/doc/pg_partman.md#child-table-property-inheritance > > "Privileges & ownership are NOT inherited by default. If enabled by > pg_partman, note that this inheritance is only at child table creation > and isn't automatically retroactive when changed (see > reapply_privileges()). Unless you need direct access to the child > tables, this should not be needed. You can set the inherit_privileges > option if this is needed (see config table information below)." > > > And: > > "reapply_privileges( >      p_parent_table text > ) > RETURNS void > >      This function is used to reapply ownership & grants on all child > tables based on what the parent table has set. >      Privileges that the parent table has will be granted to all child > tables and privileges that the parent does not have will be revoked > (with CASCADE). >      Privileges that are checked for are SELECT, INSERT, UPDATE, > DELETE, > TRUNCATE, REFERENCES, & TRIGGER. >      Be aware that for large partition sets, this can be a very long > running operation and is why it was made into a separate function to > run > independently. Only privileges that are different between the parent & > child are applied, but it still has to do system catalog lookups and > comparisons for every single child partition and all individual > privileges on each. >      p_parent_table - parent table of the partition set. Must be > schema > qualified and match a parent table name already configured in > pg_partman. > " > > > > Thank you. I was not aware about this function which copies the grants > from parent to child ,so we can give a call to this function at the end > of the pg_partman job call which is happening through the cron job. But > I see , the only issue is that this function only has one parameter > "p_parent_table" but nothing for "child_table" and that means it will > try to apply grants on all the childs/partitions which have been created > till today and may already be having the privileges already added in them. > > And we have just ~60 partitions in most of the table so hope that will > not take longer but considering we create/purge one partition daily for > each partition table using the pg_partman, every time we give it a call, > it will try to apply/copy the grants on all the partitions(along with > the current day live partition), will it cause the existing running > queries on the live partitions to hard parse? or say will it cause any > locking effect when it will try to apply grant on the current/live > partitions , which must be inserted/updated/deleted data into or being > queries by the users? > 1) You seem to have missed the first part of the answer: "Privileges & ownership are NOT inherited by default. If enabled by pg_partman, note that this inheritance is only at child table creation and isn't automatically retroactive when changed (see reapply_privileges()). Unless you need direct access to the child tables, this should not be needed. **You can set the inherit_privileges** option if this is needed (see config table information below)." Read ** ...** part. 2) This is open source the code is available for you to see what is actually going on: https://github.com/pgpartman/pg_partman/blob/master/sql/functions/reapply_privileges.sql which in turn uses: https://github.com/pgpartman/pg_partman/blob/master/sql/functions/apply_privileges.sql 3) This is something that is easily tested on you end. -- Adrian Klaver adrian.klaver@aklaver.com