Postgresql:更改所有者对象时出错“必须是关系的所有者”

问题描述 投票:47回答:2

什么是我需要给当前用户(“userA”)的grant选项/技巧,以允许他更改属于另一个用户(“userC”)的对象所有者?

更确切地说,联系表由userC拥有,当我执行以下查询以将所有者更改为userB时,与userA连接:

alter table contact owner to userB;

我收到此错误:

ERROR:  must be owner of relation contact

但是userA通常都需要权限(“在模式上创建”授权选项应该足够了):

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;

THKS


命令行输出:

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=>
postgresql grant
2个回答
80
投票

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

所以解决方案很简单 - 我刚刚完成了这笔补助金:

grant userB to userA;

那是所有人;-)


Update:

另一个要求是在更改对象之前,对象必须由用户userA拥有...


11
投票

来自the fine manual

您必须拥有该表才能使用ALTER TABLE。

或者是数据库超级用户。

错误:必须是关系联系人的所有者

PostgreSQL错误消息通常是现货。这个是现货。

© www.soinside.com 2019 - 2024. All rights reserved.