仅为1个数据库提供Postgres REASSIGN OWNED

时间:2014-11-18 20:28:02

标签: database postgresql alter

我想使用REASSIGN OWNED查询将1个数据库中的所有对象从所有者A更改为所有者B.

假设我有以下数据库:

 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 | 

我想要db1和所有对象,因此它们归user2所有。我跑:

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

所有者更改了db1及其所有对象的应用程序。但该命令也改变了db2的所有者。不是db2中的对象,只是数据库(如和ALTER DATABASE语句):

 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 | 

这是正常行为吗?如何在不改变其他数据库的情况下运行REASSIGN OWNED

1 个答案:

答案 0 :(得分:0)

DanielVérité在评论中引用的文件指出:

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.

所以这是每个规格。如果这不是您想要的,我认为您需要更充分地陈述您的用例。