pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Sherrylyn Branchaw <sbranchaw@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: pg_restore restores privileges differently from psql
Date: Mon, 14 Jan 2019 12:45:41 -0800
Message-ID: <51b12f75-caba-f845-7688-4538cfe41eae@aklaver.com> (raw)
In-Reply-To: <CAB_myF7BjckNexPSLdkwCzZOAwbW-FfSLXEHqAR3-xJeDLXP8g@mail.gmail.com>
References: <CAB_myF5_+Ok=VRkHPyxJ_TfgrG8AHdNjQs2ke5B+hKvTCzmmPQ@mail.gmail.com>
	<95556308-6e54-a5a7-b9f7-591b8a5f87d8@aklaver.com>
	<CAB_myF7BjckNexPSLdkwCzZOAwbW-FfSLXEHqAR3-xJeDLXP8g@mail.gmail.com>

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




view thread (8+ messages)  latest in thread

Message-ID: <51b12f75-caba-f845-7688-4538cfe41eae@aklaver.com>
Permalink:  ../51b12f75-caba-f845-7688-4538cfe41eae@aklaver.com/
Also on:    postgresql.org/message-id/51b12f75-caba-f845-7688-4538cfe41eae@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, sbranchaw@gmail.com
  Subject: Re: pg_restore restores privileges differently from psql
  In-Reply-To: <51b12f75-caba-f845-7688-4538cfe41eae@aklaver.com>
  References: <CAB_myF5_+Ok=VRkHPyxJ_TfgrG8AHdNjQs2ke5B+hKvTCzmmPQ@mail.gmail.com> <95556308-6e54-a5a7-b9f7-591b8a5f87d8@aklaver.com> <CAB_myF7BjckNexPSLdkwCzZOAwbW-FfSLXEHqAR3-xJeDLXP8g@mail.gmail.com> <51b12f75-caba-f845-7688-4538cfe41eae@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox