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 1r30Ez-001lld-IK for pgsql-admin@arkaria.postgresql.org; Tue, 14 Nov 2023 20:42:33 +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 1r30Ew-00AxE5-Cl for pgsql-admin@arkaria.postgresql.org; Tue, 14 Nov 2023 20:42:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r30Ew-00AxDw-1O for pgsql-admin@lists.postgresql.org; Tue, 14 Nov 2023 20:42:30 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r30Es-005adO-Kz for pgsql-admin@lists.postgresql.org; Tue, 14 Nov 2023 20:42:28 +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 3AEKgMqU2522831; Tue, 14 Nov 2023 15:42:22 -0500 From: Tom Lane To: Andres Freund cc: Aditya D , pgsql-admin Subject: Re: pg_restore -L reordering of the statements does not work In-reply-to: <20231114194933.ci3nxol3avtisyrs@awork3.anarazel.de> References: <1589825.1698431686@sss.pgh.pa.us> <20231114194933.ci3nxol3avtisyrs@awork3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Tue, 14 Nov 2023 11:49:33 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2522829.1699994542.1@sss.pgh.pa.us> Date: Tue, 14 Nov 2023 15:42:22 -0500 Message-ID: <2522830.1699994542@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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. Moreover, reordering the GRANTs is no solution, because who promised that the schema owner granted you any permissions? 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. 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. regards, tom lane