Car*_*uez 5 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 |
Run Code Online (Sandbox Code Playgroud)
我想要 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
Run Code Online (Sandbox Code Playgroud)
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 |
Run Code Online (Sandbox Code Playgroud)
这是正常行为吗?如何在REASSIGN OWNED不改变其他数据库的情况下运行?
Daniel V\xc3\xa9rit\xc3\xa9 的评论中引用的文档指出:
\n\nold_role\n\nThe 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.\nRun Code Online (Sandbox Code Playgroud)\n\n所以这是根据规格。如果这不是您想要的,我认为您需要更全面地陈述您的用例。
\n| 归档时间: |
|
| 查看次数: |
2175 次 |
| 最近记录: |