Postgresql:更改所有者对象时出现错误“必须是关系的所有者”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28584640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgresql: error "must be owner of relation" when changing a owner object
提问by gudepier
What is the grant
option/trick I need to give to the current user ("userA") to allow him to change a object's owner which belongs by another user ("userC")?
grant
我需要给当前用户(“ userA”)以允许他更改属于另一个用户(“ userC”)的对象的所有者的选项/技巧是什么?
More precisely, the contacttable is owned by the userCand when I perform the following query for changing the owner to the userB, connected with the userA:
更准确地说,联系表归userC 所有,当我执行以下查询以将所有者更改为userB 时,与userA连接:
alter table contact owner to userB;
I get this error:
我收到此错误:
ERROR: must be owner of relation contact
But userAhas all needed rights to do that normally (the "create on schema" grant option should be enough):
但是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;
Thks
谢谢
Command line output:
命令行输出:
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=>
回答by gudepier
Thanks to Mike's comment, I've re-read the doc and I've realised that my current user (i.e. userA that already has the createprivilege) wasn't a direct/indirect member of the new owning role...
感谢 Mike 的评论,我重新阅读了文档,并且意识到我当前的用户(即已经具有创建权限的userA )不是新所有者角色的直接/间接成员......
So the solution was quite simple - I've just done this grant:
所以解决方案很简单 - 我刚刚完成了这项赠款:
grant userB to userA;
That's all folks ;-)
这就是所有人;-)
Update:更新:
Another requirement is that the object has to be owned by user userAbefore altering it...
另一个要求是该对象必须由用户userA拥有,然后才能更改它...
回答by Mike Sherrill 'Cat Recall'
From the fine manual.
来自精美的手册。
You must own the table to use ALTER TABLE.
您必须拥有该表才能使用 ALTER TABLE。
Or be a database superuser.
或者成为数据库超级用户。
ERROR: must be owner of relation contact
错误:必须是关系联系人的所有者
PostgreSQL error messages are usually spot on. This one is spot on.
PostgreSQL 错误消息通常很明显。这个就在现场。
回答by dobrivoje
This solved my problem : Sample alter table statement to change the ownership.
这解决了我的问题:更改所有权的示例更改表语句。
ALTER TABLE databasechangelog OWNER TO arwin_ash;
ALTER TABLE databasechangeloglock OWNER TO arwin_ash;