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.
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.shared objects
whereas it seems to be the case of the subject you referenced.