database 如何更改数据库中表的所有权

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31824658/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 07:58:03  来源:igfitidea点击:

How to change the ownership of a table in database

databasepostgresql

提问by monu

I Have a database rndb and created a new table myname_record which is created with owner "postgres" by default. In my program i should have change the owner to "rndb" but i missed it. Now i need to do it in console so i am login with command

我有一个数据库 rndb 并创建了一个新表 myname_record,默认情况下它是由所有者“postgres”创建的。在我的程序中,我应该将所有者更改为“rndb”,但我错过了。现在我需要在控制台中执行此操作,因此我使用命令登录

psql=>psql -Urndb 

and then changing the owner with following query

然后使用以下查询更改所有者

rndb=>ALTER TABLE public.myname_record OWNER to rndb;

but it is saying you must be owner to do this changes. I can understood because i am login through rndb it is giving this error. But how to make this changes actually.

但它说您必须是所有者才能进行此更改。我可以理解,因为我是通过 rndb 登录的,因此出现此错误。但实际上如何进行这种改变。

回答by Abhishek

Select a role with superuser permission and try to change the owner of your table.

选择具有超级用户权限的角色并尝试更改表的所有者。

ALTER TABLE public.myname_record OWNER TO rndb;

回答by Craig Ringer

You must connect as the currenttable owner, not the user you wish to change the table ownership to. Since that's postgres:

您必须以当前表所有者的身份连接,而不是您希望将表所有权更改为的用户。因为那是postgres

psql -U postgres

or

或者

sudo -u postgres psql

as required.

按要求。

(Also, a superuser can always change table ownerships from anything to anything).

(此外,超级用户始终可以将表所有权从任何内容更改为任何内容)。