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 1r31u0-001t6n-II for pgsql-admin@arkaria.postgresql.org; Tue, 14 Nov 2023 22:29:01 +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 1r31sy-00BJCA-VF for pgsql-admin@arkaria.postgresql.org; Tue, 14 Nov 2023 22:27:56 +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 1r31sx-00BJ8l-14 for pgsql-admin@lists.postgresql.org; Tue, 14 Nov 2023 22:27:56 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r31ss-006SbE-IV for pgsql-admin@lists.postgresql.org; Tue, 14 Nov 2023 22:27:54 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 290763200971; Tue, 14 Nov 2023 17:27:46 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 14 Nov 2023 17:27:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1700000865; x=1700087265; bh=3N J0YPTuLRHgrP+aar0Him1+UMXNhCD1bYUrsEbXECY=; b=VnqfcZUQxO0eAAriBB qf04cn5GwBjPJ4Z97yPNifKsiBE6Y7f/Y9gMkep1XxROt7P4zVgo31knySqaaLEV iGyZqKwigLJ81LXRGPL/YuZM2B0PncBw5zk4+OZl4I3o1HZgTzrnY99bSRgslkU3 UHN8JpyeB896xGnoOy0PoVi6AFEfzOy1n6TOmC5q8XBadriY+D/FXfsXS50or6sx 7n2OTjp5AdQQ8qbIyzS6O0Ek3DubGbowALym71AYrBfSZiRrBoYLona4zTzt22v2 RcF1l4ef4xbSibQq1NI/v/GIcSUDn0CrdQLy8JP6T8ZhoOXBlsnlKFE9Sa0nODkO fiQw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1700000865; x=1700087265; bh=3NJ0YPTuLRHgr P+aar0Him1+UMXNhCD1bYUrsEbXECY=; b=Z0bbIKWvaEnZZUQZW3cYLEiI0ejv5 wbUUPsqoiHVCdovTxaMmm4q6hLIl+P+Kk4S6z0+SW0G+j+8wiXjvuG0Fd2rdvOtI TKD9DssNfM93XXo0DIPQZHp2yFnOc44Awni1zTdZBVjqqVT117QwYh/JXs+ORYHR WNcaZmyIXD41ciI2stNlSGMjKHUebaeKideoeA3CIamqOOrwWr6fYQ8wfKTxFoUg cDJ/cWCaSIkeTISSwT64mC2k1Z6CmAPZJDOQpr5FCEy/HmCTQB0tpXIFZzwz5RXK 8HP16Utl0IRZM9pf0MxEiD3jQGdKN13ektOMzX5uL+e5uTwcT3Q3YJ96A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeffedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepvdfffeevhfetveffgeeiteefhfdtvdffjeevhfeuteegleduheetvedu ieettddunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 14 Nov 2023 17:27:44 -0500 (EST) Date: Tue, 14 Nov 2023 14:27:43 -0800 From: Andres Freund To: Tom Lane Cc: Aditya D , pgsql-admin Subject: Re: pg_restore -L reordering of the statements does not work Message-ID: <20231114222743.x2c2r74ttgom2cfx@awork3.anarazel.de> References: <1589825.1698431686@sss.pgh.pa.us> <20231114194933.ci3nxol3avtisyrs@awork3.anarazel.de> <2522830.1699994542@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2522830.1699994542@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2023-11-14 15:42:22 -0500, Tom Lane wrote: > Andres Freund writes: > > A schema like: > > ... > > results in the following, abbreviated, dump on HEAD: > > ... > > Which is bad because the ALTER TABLE OWNER TO cannot be executed before > > the GRANT ALL: > > ERROR: 42501: permission denied for schema nosuper > > LOCATION: aclcheck_error, aclchk.c:2833 > > Works fine for me. I agree that it might not work if you're restoring > as non-superuser, but if you try that the ALTER OWNER commands are all > going to fail too. It's indeed dependent on restoring as a non-superuser. Notably even if restoring as nosuper_1. > Moreover, reordering the GRANTs is no solution, because who promised that > the schema owner granted you any permissions? I'm not quite following - the schema is created in the dump, so the grant is part of it? > The bigger picture here is that pg_dump effectively relies on all > objects being treated throughout the restore as though the restoring > user is their owner --- either via --no-owner, or because the > restoring user is superuser, or perhaps because the restoring user is > a member of every object owner named in the dump. In my repro I was restoring with nosuper_1, which is granted membership to nosuper_2. > Postponing execution of GRANTs to the end should therefore be perfectly > safe, and indeed it's *necessary* if you want to successfully restore cases > in which an object owner has revoked some of their own privileges. > > I experimented with making the restoring user be a member with inherit > of the nosuper_N roles, and indeed I still see the failure above, > which makes me wonder if the ACL check is being done correctly for > that specific case. The INHERIT bit ought to let it work. The check is for nosuper_2 to have permission on the schema and the check happens before the grant on the schema. For inherit to help, nosuper_2 would have to be granted membership to the presumably more privileged user doing the restore. Greetings, Andres Freund