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 1gj9iY-0000AE-GS for pgsql-general@arkaria.postgresql.org; Mon, 14 Jan 2019 21:24:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gj9iX-00042u-7Y for pgsql-general@arkaria.postgresql.org; Mon, 14 Jan 2019 21:24:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gj9iW-00042n-S4 for pgsql-general@lists.postgresql.org; Mon, 14 Jan 2019 21:24:21 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gj9iT-0005ZN-BD for pgsql-general@postgresql.org; Mon, 14 Jan 2019 21:24:19 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 75EC228C9A; Mon, 14 Jan 2019 16:24:16 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 14 Jan 2019 16:24:16 -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=G pHojPGwBpTQ33j3fNfKdmdHReoDRx9sPoXEh3lZdIo=; b=Fw8P9ZTVSUbSLO+Is kAm1G+yTc4p+aCSSGfIm4X4wxvKqOR5MvvM/rrJr7aB9Y/joNVjYhgJXFz8lNW54 5CCTkLC7vbjd1BuNXQETmr2Jiut98n19q+wnuuITJR5thtcXkYPxB27IR7HkF/Uu 984nj76bLAMPJ+g5FAxpD/pugJtXdBwMpvIn1/2q6cvgco/SJvTLYye/MwLfSUWk eatyBYbnn5pld+ZTzVW93evdFurIy8jZPS/GGKZByJC6J/PseWojwG7i6bCEwjfZ DUYBa4nNzEpzYVk6CT+jpdeWvUV8vpWgaTvAltoxLVaKs4KuGLF4XEnuJblB2aOZ Fh0nw== 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=GpHojPGwBpTQ33j3fNfKdmdHReoDRx9sPoXEh3lZd Io=; b=pmphPcuqiIiIL69Wd8Wi+QKObj/+ABRXv/PlG/f0mws8hl3uFqQ5Q5lnu Q7chY8guLOkPvchP/BUG0TXKwmUG2HOdkXodAgcV3GCs+iNDto300Wn3Svf1akty f4bg9ZgRAV3OsW4d+eP30JcKeoIV5YC0mTSrWvt7daW1hJ/FBa6NpfHOoAd9J+04 t/UWqUJjxQut+W7Wu72nLFWhFc+y+1jKZE6cBJvwE+JKTe3Sh4rhzR7Afqsz5Oge J75UzAcZn6SDexjNJbZifyoqOYLmivqTOsiTa4LKSb/k8pjGj9vxgQTIMFp7tMuO ceRjk7Gr1gw/uC9RmQgyRFLmgxovw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrgedugddugeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhhtnecuuegrihhlohhuthemucef tddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefuvfhfhffkff gfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceo rggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpe hpohhsthhgrhgvshhqlhdrohhrghenucfkphepjedurddvuddvrddufeegrdefnecurfgr rhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrd gtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 84F4FE464F; Mon, 14 Jan 2019 16:24:15 -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> <51b12f75-caba-f845-7688-4538cfe41eae@aklaver.com> From: Adrian Klaver Message-ID: <43e5aea2-16be-6126-c6b0-11fb2f7c64ff@aklaver.com> Date: Mon, 14 Jan 2019 13:24:14 -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: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/14/19 12:57 PM, Sherrylyn Branchaw wrote: > 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 > Yes, if you're going to put all your databases on the same cluster, you > first have to remove dependent objects before dropping the role. There > are multiple ways of going about that: dropping the database, revoking > the privileges on the objects in question, etc. If you put the databases > on different clusters and make sure you create only the > prod_and_dev_user on the second cluster, you won't run into this issue. > > The goal is to make sure the prod_user role exists when the dump is > taken and doesn't exist when the restore is done. You can do this by > putting the databases on separate clusters and creating the appropriate > roles, or by dropping the user on the single cluster. > > Sorry, I considered spelling all this out in the original post, because > there are two different ways of going about making sure the user isn't True. The thing is that there are a lot of moving parts to this and the more detail you give the better the chance that someone trying to replicate actually does replicate your setup. Removes some of the uncertainty when the results diverge. > present for the restore, but it seemed unnecessarily complicated, and I > thought I would let people decide what makes sense in their own > environment for testing. Sorry if that led to more confusion in the end. > Just make sure the user exists when you need it to exist and doesn't > exist when you need it not to exist, and test both the pg_restore and > psql methods, and I expect you'll see the same behavior I did (and if > not, I'll be very curious).' Well if I use two clusters and: DROP ROLE prod_user; on the one that has the dev_* databases then I can replicate. I am interested in this as I have noted another divergence between a text dump and a binary dump, which as yet remains unanswered: https://www.postgresql.org/message-id/b7a24043-1c9c-1876-f06a-8f916293c142%40aklaver.com > > Best, > Sherrylyn -- Adrian Klaver adrian.klaver@aklaver.com