Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFMZX-00069Q-VE for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2019 18:08:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iFMZV-0005AW-LT for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2019 18:08:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFMZU-0005AF-0w for pgsql-general@lists.postgresql.org; Tue, 01 Oct 2019 18:08:25 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFMZL-0000j2-P6 for pgsql-general@lists.postgresql.org; Tue, 01 Oct 2019 18:08:23 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 971E122289; Tue, 1 Oct 2019 14:08:13 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 01 Oct 2019 14:08:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=R yrpAbjrkkD9WGBJfv+Anytv+oL0GTp9wzTh2jWAqKY=; b=RFfZ++XwBn+7jLqc1 gLgoSh6RU/AC2S/GSVhzusqbMdx39vhBTxUPDxTleq7lrU8TW0KFgZwDWlL5DPc3 MdX030LTcCz48aqq6fqKEYGorutAPDSUmxFHCj6t9wMFwy9l8pW83sqkeP6JKF7p d4QnYYEzRmb5PIZ1JKLefUlqAH8dgTR01+hTgLST4OUe2jBzUfK/B78r672H2A6t jhhmOtnvoTj0KQPlNwKc0B+B9btb7YYcfLJhwi7/6b/wIRQWWAAxVCYV3ePVdnG7 gB8SckB5HdvoTW9C7aj9ZIdLL0nYJlPjDz/s23mcNUpkOeLz3Msx31LMw6j6nFYe psYSw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=RyrpAbjrkkD9WGBJfv+Anytv+oL0GTp9wzTh2jWAq KY=; b=0UhZEO8GdFY4kg1IWF8u2IU1HsWcydcwelvBsEh7yZQ4wzBRUoti8Eom0 8mmeryU48tjefjPrQnbvmaEGws5zxydJRW3aTXJpqdpVjPzJGtxvy/EyUU1PLRGm jKJ1zMXdm1MTl7pgM72NUJTDtTnf69W8woCTYeqc85Hp1c25/VNGFewsxIizjK2T QvEpUGN8BSJ6vg0QN8As1TzC8RhYuknU2mN2ZMn07ogAv6BcpSXn6z9glCz1s05C YCLduBTZjahlr/6bIQPsKfsT5IF2otPZakFMClu54FeCWIo4HxZc2g0shvVPe2c0 oJ6P6pKKdlcouu/WvyGAo3XTFWOuA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrgeeggdduvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucfkphephedtrdduleejrdektddrvdenucfrrghrrghmpehmrghilhhfrhhomhep rggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhenucevlhhushhtvghruf hiiigvpedt X-ME-Proxy: Received: from ranger.suse (50-197-80-2-static.hfc.comcastbusiness.net [50.197.80.2]) by mail.messagingengine.com (Postfix) with ESMTPA id C9897D6005E; Tue, 1 Oct 2019 14:08:12 -0400 (EDT) Subject: Re: Schema dump/restore not restoring grants on the schema To: Tom Lane , Mike Roest Cc: pgsql-general@lists.postgresql.org References: <6234.1569941612@sss.pgh.pa.us> From: Adrian Klaver Message-ID: Date: Tue, 1 Oct 2019 11:08:11 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <6234.1569941612@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 10/1/19 7:53 AM, Tom Lane wrote: > Mike Roest writes: >> Just trying to find out if something is intended behaviour. When doing a >> schema filtered pg_dump the created dump file includes the grants on that >> specific schema (in our case a grant usage to a unprivleged user) but doing >> a pg_restore with a -n does not restore that grant however >> individual grants on object within the filtered schema are restored. But >> it's resulting in our unprivileged user not actually being able to access >> the limited number of tables it should be able to as the grant usage on the >> schema itself is being lost. > > Hm. The pg_dump man page says > > -n pattern > --schema=pattern > > Dump only schemas matching pattern; this selects both the schema > itself, and all its contained objects. > > while pg_restore says > > -n schema > --schema=schema > > Restore only objects that are in the named schema. > > and the actual behavior seems consistent with that: pg_dump emits both > a CREATE SCHEMA command and GRANTs for it, while pg_restore emits > neither. > > So I guess this is working as documented, but it does seem not very > nice that the two programs interpret the "same" switch differently. > I suppose the reasoning is lost in the mists of time :-( Some fooling around on my part found: pg_restore -d test -U postgres -n utility utility_schema.out pg_restore: [archiver (db)] could not execute query: ERROR: schema "utility" does not exist test_(postgres)# create schema utility; CREATE SCHEMA test_(postgres)# \dn+ utility List of schemas Name | Owner | Access privileges | Description ---------+----------+-------------------+------------- utility | postgres | | (1 row) pg_restore -d test -U postgres -n utility utility_schema.out test_(postgres)# \dn+ utility List of schemas Name | Owner | Access privileges | Description ---------+----------+-------------------+------------- utility | postgres | | (1 row) test_(postgres)# drop schema utility cascade; pg_restore -d test -U postgres utility_schema.out test_(postgres)# \dn+ utility List of schemas Name | Owner | Access privileges | Description ---------+----------+-----------------------+------------- utility | postgres | postgres=UC/postgres +| | | production=U/postgres | (1 row) Looks to me the -n argument on restore is for restoring the objects into an existing schema. Leaving it off restores the schema and the objects. > > Another thing that is not very nice is that pg_restore lacks the > ability to use patterns (wildcards) here. Someday maybe somebody > will get around to fixing that. I could see changing the definition > of -n to include the schema itself at the same time. > > regards, tom lane > > -- Adrian Klaver adrian.klaver@aklaver.com