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 1gj97P-00063C-3N for pgsql-general@arkaria.postgresql.org; Mon, 14 Jan 2019 20:45:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gj97M-0000un-DX for pgsql-general@arkaria.postgresql.org; Mon, 14 Jan 2019 20:45:56 +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 1gj97K-0000tt-K9 for pgsql-general@lists.postgresql.org; Mon, 14 Jan 2019 20:45:56 +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 1gj97B-00085j-NZ for pgsql-general@postgresql.org; Mon, 14 Jan 2019 20:45:53 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 74D7225183; Mon, 14 Jan 2019 15:45:43 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 14 Jan 2019 15:45:43 -0500 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=0 G+Rf6TLsXozHvDh/KJn5G0uGAiIzBqc4Opg0g12TcA=; b=R2yvD4g5R04qxAICz UsEWVrCuU7q+y5tVYKCJzvgKjbk1ipYy+T5KzCZfIP/hTev09DMefQdXRH4JWdzQ Ql2B1Gza7DWSdKEOucWul0sqM67YLWFRKAKzO5/SsHamf/2qRw8220tyc9HnfEIo 3LUIia6lH7uoMCQn+IjLHWI2v+XFgpVxzZP65FuNBDhMFG1YXagQYLY5mxbpZoJf QjmaIj//NwX42RuRSZsClYF7zGJmkLEMSyIgv6fTCCkdqhdN52+TD7gwrHzew4RH M1kntbEb+F5Ar5LLJo0m2bf3+Bnzt/ZN2K7W7Ace+5oGb5fpXpT97zT7Qw6ntWdq a+Kgw== 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=fm1; bh=0G+Rf6TLsXozHvDh/KJn5G0uGAiIzBqc4Opg0g12T cA=; b=HA7fF9sXANRQuPilp+aOlpAKunrQwYGWoLYAw8/GXAFP9USMB+QFlBfhP ahw3Wus6aicLQdrTDQd8Wnicx9lV3vvJySp8KoAwYr5Wsn5rc5xOeKqkV0APhdfV X61cF0dGBHHx1C5ce6OjGgNth7fUIMd44nBpXwiHWXfuq9/NfhyCVKuQaw+UWU+V LRi/w6eLYatEf/MmBOlU/1iD9JgdKvFT/1cYf24LJU2AO0oJSY5plgszsTL4puTc 6Hfw6pljedEX8so1b/v+nNg6FIDLPR9zxshPKQFVKLM8tdmy6Lqg98vGKV9K/Hgr 0O1FqA0RcEJNzKsCl9I9nbj7sfM5Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrgedugddufeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhhtnecuuegrihhlohhuthemucef tddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefuvfhfhffkff gfgggjtgfgsehtjeertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceo rggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecukfhppeejuddrvd duvddrudefgedrfeenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 5283DE4598; Mon, 14 Jan 2019 15:45:42 -0500 (EST) Subject: Re: pg_restore restores privileges differently from psql To: Sherrylyn Branchaw Cc: pgsql-general@postgresql.org References: <95556308-6e54-a5a7-b9f7-591b8a5f87d8@aklaver.com> From: Adrian Klaver Message-ID: <51b12f75-caba-f845-7688-4538cfe41eae@aklaver.com> Date: Mon, 14 Jan 2019 12:45:41 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: 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 1/14/19 12:04 PM, Sherrylyn Branchaw wrote: > The above needs more information: > > 1) Are the dev_* databases on a different cluster? > > 2) If so did you run: > > CREATE ROLE prod_user; > CREATE ROLE prod_and_dev_user; > > on that cluster first? > > I happened to put them all on the same cluster for my test case, in > order to reproduce the unexpected behavior I encountered in the wild, > where the prod and dev dbs happened to live on different clusters. In I don't see how that can work: test=# \c prod_db You are now connected to database "prod_db" as user "postgres". prod_db=# CREATE SCHEMA test; CREATE SCHEMA prod_db=# GRANT ALL ON SCHEMA test TO prod_user; GRANT prod_db=# GRANT USAGE ON SCHEMA test TO prod_and_dev_user; GRANT prod_db=# \c dev_db_psql You are now connected to database "dev_db_psql" as user "postgres". dev_db_psql=# DROP ROLE prod_user; ERROR: role "prod_user" cannot be dropped because some objects depend on it DETAIL: 1 object in database prod_db > short, as long as you make sure the /prod_user/ exists on the source > cluster at the time when the dump is taken, and doesn't exist on the > target cluster when the restore is carried out, you get the behavior I saw. > > Also if so: > > In the restores below are you sure you are pointed at the same cluster > in each case? > > Yes, I am sure. Both for the test case I was creating for the mailing > list, and for the script where I first encountered this in the wild. > Worked like a charm when I used /psql/, didn't do what I expected when I > used /pg_restore/. > > What do you see if you do: > > pg_restore -f prod_dump_restore.sql prod_dump.bin > > and look in prod_dump_res?tore.sql? > > This is exactly what I did when I was first trying to figure out what > was going on. I see > > GRANT USAGE ON SCHEMA test TO prod_and_dev_user; > GRANT ALL ON SCHEMA test TO prod_user; > > If I then use /psql/ to load /prod_dump_restore.sql/ to a cluster that > doesn't have the /prod_user /role, I get the expected behavior > (/prod_and_dev_user/ has usage on the schema /test/), because /psql/ > treats each of those statements as a separate command. /pg_restore/ > seems to treat them as a single command, judging by the error message > and the behavior. > > Best, > Sherrylyn -- Adrian Klaver adrian.klaver@aklaver.com