2

I'm in postgres 9.2. The documentation https://www.postgresql.org/docs/9.2/static/sql-reassign-owned.html states : REASSIGN OWNED only affects the objects in the current database. Exactly what I need but it seems false.
This command changes also the ownership of all databases owned by the old user.

Here is what I did :

Copy the database :

$ sudo -u postgres -i
$ createdb -O faire-pp -T vozatou_db1 test_db
postgres=# \l
                              List of databases
    Name     |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-------------+----------+----------+-------------+-------------+-----------------------
test_db      | faire-pp | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
vozatou_db1  | vozatou  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 

Permissions of tables in new database are wrong (still the old user) :

postgres=# \c test_db
You are now connected to database "test_db" as user "postgres".
test_db=# \d
                        List of relations
 Schema |                   Name                   |   Type   |  Owner  
--------+------------------------------------------+----------+---------
 public | auth_group                               | table    | vozatou
 public | auth_group_id_seq                        | sequence | vozatou

Change it :

test_db=# REASSIGN OWNED BY "vozatou" TO "faire-pp";
REASSIGN OWNED
test_db=# \d
                     List of relations
 Schema |                   Name                   |   Type   |  Owner   
--------+------------------------------------------+----------+----------
 public | auth_group                               | table    | faire-pp
 public | auth_group_id_seq                        | sequence | faire-pp

Everything looks good, but :

postgres=# \l
                              List of databases
    Name     |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-------------+----------+----------+-------------+-------------+-----------------------
test_db      | faire-pp | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
vozatou_db1  | faire-pp | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 

Why the owner of my original database changed ?

The documentation specifically says : The REASSIGN OWNED command does not affect the ownership of any databases owned by the role.

Any insights ?

UPDATE: According to a comment below the problem could be related to shared objects, I tried to identify what was the shared object in question with SELECT * FROM pg_shdepend; but it didn't show me something exploitable.

5
  • 1
    I just use ALTER DATABASE to restore the ownership of the others databases. As it didn't change the ownership of the databases content. I hope there is no other side effects.
    – Plup
    Apr 1, 2017 at 18:52
  • Please report this as a PostgreSQL bug. Apr 3, 2017 at 1:18
  • 1
  • This is no bug. Apr 3, 2017 at 9:48
  • I don't see why it would be a duplicate. The documentation relevant to my version 9.2, doesn't speak about shared objects whereas it seems to be the case of the subject you referenced.
    – Plup
    Apr 3, 2017 at 19:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.