“错误:必须是角色的成员”在 PostgreSQL 中创建模式时

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

"ERROR: must be member of role" When creating schema in PostgreSQL

postgresqlroles

提问by Ultranuke

I'm logged in with a superuser account and this is the process I'm doing:

我使用超级用户帐户登录,这是我正在做的过程:

1-> CREATE ROLE test WITH IN ROLE testroles PASSWORD 'testpasswd'
2-> CREATE SCHEMA AUTHORIZATION test

The role is correctly created but I'm getting this error when trying to create the Schema:

角色已正确创建,但在尝试创建架构时出现此错误:

ERROR:  must be member of role "test"

Thanks in advance!

提前致谢!

回答by David Jones

I ran into this issue when using CREATE DATABASEon Amazon RDS. I think it's essentially the same as using CREATE SCHEMA.

CREATE DATABASE在 Amazon RDS 上使用时遇到了这个问题。我认为它与使用CREATE SCHEMA.

When using Amazon RDS the user issuing the CREATE DATABASEmust be a member of the role that will be the owner of the database. In my case, the superuser account I'm using is called root, and I'm going to create a role owhich is going to own a database d:

使用 Amazon RDS 时,发出 的用户CREATE DATABASE必须是将成为数据库所有者的角色的成员。就我而言,我使用的超级用户帐户名为root,我将创建一个o将拥有数据库的角色d

postgres=> CREATE ROLE o;
CREATE ROLE

postgres=> CREATE DATABASE d OWNER = o;
ERROR:  must be member of role "o"

postgres=> GRANT o TO root;
GRANT ROLE

postgres=> CREATE DATABASE d OWNER = o;
CREATE DATABASE

回答by James Ching

I came across this same problem, it is complaining about the current(master) user you are logged in with is not a member of the user group you are try to create the schema for. You should grant the role access to your master user and it will let you create the SCHEMA without error:

我遇到了同样的问题,它抱怨您登录的当前(主)用户不是您尝试为其创建架构的用户组的成员。您应该将角色访问权限授予您的主用户,它会让您无误地创建 SCHEMA:

GRANT <role> TO <master_user>;

回答by bionicseraph

Are you using RDS? Because I get the same issue when I log in as the "superuser" that they create for you. The way that I was able to fix this was to create a new group role that included my super user and the user who owned the schema. So for you this would mean adding your super user and test user to a new roles group:

你在使用RDS吗?因为当我以他们为您创建的“超级用户”身份登录时,我遇到了同样的问题。我能够解决这个问题的方法是创建一个新的组角色,其中包括我的超级用户和拥有该架构的用户。所以对你来说,这意味着将你的超级用户和测试用户添加到一个新的角色组:

CREATE ROLE users NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
GRANT megausers TO testroles;
GRANT test TO testroles;

Now you should be able to create your schmea

现在你应该能够创建你的schmea

回答by Rafael Oliveira

Had this problem with RDS too.

RDS也有这个问题。

To solve it:

要解决它:

Login as superuser

以超级用户身份登录

psql --host=xxxxxxx.rds.amazonaws.com --port=5432 --username=RDS_SUPERUSER_NAME --password --dbname=postgres

Create the User

创建用户

CREATE USER newuser WITH CREATEDB PASSWORD 'password';

Logout

登出

\q

Login as newuser

登录为 newuser

psql --host=xxxxxxx.rds.amazonaws.com --port=5432 --username=newuser --password --dbname=postgres

Create your DB/Schema

创建您的数据库/架构

CREATE SCHEMA/DATABASE ....

回答by jorfus

Don't we just have to grant the admin user membership to the service role?

我们不是只需要将管理员用户成员资格授予服务角色吗?

create role service_role with password 'some_password';
create database service_db with owner service_role;
ERROR:  must be member of role "service_role"
grant admin_user service_role;
GRANT ROLE
create database service_db with owner service_role;
CREATE DATABASE

回答by Krystian Cybulski

I have encountered this issue on RDS as well. I logged in as the rootuser, created a role named myappuserand then tried creating a schema called superduperwhose owner is myappuser.

我在 RDS 上也遇到过这个问题。我登录的root用户,创建了一个名为角色myappuser,然后试图创建一个名为架构superduper的主人是myappuser

I found a solution which works. Create the myappuserrole, and make sure that this role at least has the permission to create databases (the privilege is called CREATEDB). After creating the myappuserrole, I logged into the database as myappuserand created the superduperschema whose user is myappuser. This worked without any problems.

我找到了一个有效的解决方案。创建myappuser角色,并确保该角色至少具有创建数据库的权限(该权限称为CREATEDB)。创建myappuser角色后,我以身份登录数据库myappuser并创建了superduper用户为myappuser. 这没有任何问题。

回答by Sid

I was facing the same issue. To resolve this, I logged in with the newly created role and created the database. Somehow, grant does not work in RDS Postgres.

我面临着同样的问题。为了解决这个问题,我使用新创建的角色登录并创建了数据库。不知何故,grant 在 RDS Postgres 中不起作用。

回答by sprut

I just ran into this using Amazon RDS.

我刚刚使用 Amazon RDS 遇到了这个问题。

A lot of the answers are already correct, but you can also just alter the role.

很多答案已经是正确的,但你也可以改变角色。

Here was my implementation

这是我的实现

psql -h ${PGHOST} -p ${PGPORT:-5432} -U ${PGUSER:-postgres} -c "ALTER USER renderer WITH CREATEDB PASSWORD '$RENDERPASSWORD'"

psql -h ${PGHOST} -p ${PGPORT:-5432} -U ${PGUSER:-postgres} -c "ALTER USER renderer WITH CREATEDB PASSWORD '$RENDERPASSWORD'"

So while changing the password, I am also adding the CREATEDB role permission to the role.

因此,在更改密码的同时,我还向角色添加了 CREATEDB 角色权限。