I want to use the REASSIGN OWNED
query to change all objects in 1 database from owner A to owner B.
Let say I have the following databases:
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
db1 | user1 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
db2 | user1 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
db3 | user2 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
I want to db1 and all objects inside so they are owned by user2. I run:
postgres=# \c db1
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
You are now connected to database "db1" as user "postgres".
db1=# REASSIGN OWNED BY user1 TO user2;
REASSIGN OWNED
The owner changed as it should for db1 and all of its objects. But the command also changed the owner of db2. Not the objects in db2, just the database (like and ALTER DATABASE statement):
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
db1 | user2 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
db2 | user2 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
db3 | user2 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
Is this the normal behaviour? How can I run the REASSIGN OWNED
without altering other databases?
The documentation quoted in the comment by Daniel Vérité states:
old_role
The name of a role. The ownership of all the objects within the current database, and of all shared objects (databases, tablespaces), owned by this role will be reassigned to new_role.
so this is per spec. If this is not what you want, I think you need to state your use case more fully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With