Postgresql:更改所有者对象时出错 "must be owner of relation"

Postgresql: error "must be owner of relation" when changing a owner object

什么是 grant option/trick 我需要给当前用户 ("userA") 以允许他更改对象的所有者属于另一个用户 ("userC")?

更准确地说,contact table 归 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=>

来自 the fine manual.

You must own the table to use ALTER TABLE.

或者成为数据库超级用户。

ERROR: must be owner of relation contact

PostgreSQL 错误消息通常是准确的。这个是正确的。

感谢 Mike 的评论,我重新阅读了文档,我意识到我当前的用户(即已经拥有 create 权限的 userA)不是新所有者角色的 direct/indirect 成员...

所以解决方案非常简单 - 我刚刚完成了这项资助:

grant userB to userA;

这就是所有人 ;-)


更新:

另一个要求是对象必须由用户 userA 拥有才能更改它...

这解决了我的问题:ALTER TABLE 声明更改所有权。

ALTER TABLE databasechangelog OWNER TO arwin_ash;
ALTER TABLE databasechangeloglock OWNER TO arwin_ash;