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 1ltzd1-0002t1-GB for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Jun 2021 21:32: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 1ltzd0-0007Fx-CY for pgsql-bugs@arkaria.postgresql.org; Thu, 17 Jun 2021 21:32:46 +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 1ltzd0-0007Fo-5s for pgsql-bugs@lists.postgresql.org; Thu, 17 Jun 2021 21:32:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ltzcy-00077R-5r for pgsql-bugs@lists.postgresql.org; Thu, 17 Jun 2021 21:32:45 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 15HLWgpw1067501; Thu, 17 Jun 2021 17:32:42 -0400 From: Tom Lane To: Stephen Frost cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17062: Assert failed in RemoveRoleFromObjectPolicy() on DROP OWNED policy applied to duplicate role In-reply-to: <1066940.1623964553@sss.pgh.pa.us> References: <17062-11f471ae3199ca23@postgresql.org> <1066940.1623964553@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 17 Jun 2021 17:15:53 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1067499.1623965562.1@sss.pgh.pa.us> Date: Thu, 17 Jun 2021 17:32:42 -0400 Message-ID: <1067500.1623965562@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wroteL > PG Bug reporting form writes: >> When executing the following query: >> CREATE USER role1; >> CREATE TABLE t1(id int); >> CREATE POLICY p1 ON t1 TO role1,role1 USING (true); >> DROP OWNED BY role1; >> The server halts with the failed assertion: > Nice. Seems to be that way at least as far back as 9.6, too. So the proximate problem is RemoveRoleFromObjectPolicy's unfounded assumption that there are no duplicate OIDs in a pg_policy.polroles entry. But that function has got some other serious problems too: * Locking. It acquires lock on the policy's relation only after it looks up the pg_policy entry. By that point the entry could be gone or modified. * Why is it expensively reconstructing the dependencies of the policy expressions? Those aren't going to be changed by this operation. AFAICS it ought to be sufficient to remove and rebuild the policy's shared dependencies. I wonder whether other operations on policies share either of these issues. regards, tom lane