我需要给当前用户 ("userA") 的 grant
选项/技巧是什么,以允许他更改属于另一个用户的对象的所有者("userC")?
更准确地说,contact 表归 userC 所有,当我执行以下查询以将所有者更改为 userB 时,与 userA 连接:
alter table contact owner to userB;
我收到这个错误:
ERROR: must be owner of relation contact
但是 userA 拥有正常执行此操作所需的所有权限(“create on schema”授权选项应该足够了):
grant select,insert,update,delete on all tables in schema public to userA;
grant select,usage,update on all sequences in schema public to userA;
grant execute on all functions in schema public to userA;
grant references, trigger on all tables in schema public to userA;
grant create on schema public to userA;
grant usage on schema public to userA;
命令行输出:
root@server:~# psql -U userA myDatabase
myDataBase=>\dt contact
List of relations
Schema | Name | Type | Owner
-------+---------+----------+---------
public | contact | table | userC
(1 row)
myDataBase=>
myDataBase=>alter table contact owner to userB;
ERROR: must be owner of relation public.contact
myDataBase=>
最佳答案
感谢 Mike 的评论,我重新阅读了文档并意识到我当前的用户(即已经拥有 create 权限的 userA)不是 direct/新所有者角色的间接成员...
所以解决方案非常简单 - 我刚刚完成了这项资助:
grant userB to userA;
这就是所有人 ;-)
更新:
另一个要求是在更改对象之前,该对象必须由用户 userA 拥有...
关于Postgresql:更改所有者对象时出现错误 "must be owner of relation",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28584640/