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

前端 未结 9 570
粉色の甜心
粉色の甜心 2021-01-31 13:01

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 S         


        
相关标签:
9条回答
  • 2021-01-31 13:32

    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:

    GRANT <role> TO <master_user>;
    
    0 讨论(0)
  • 2021-01-31 13:32

    I have encountered this issue on RDS as well. I logged in as the root user, created a role named myappuser and then tried creating a schema called superduper whose owner is myappuser.

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

    0 讨论(0)
  • 2021-01-31 13:34

    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
    
    0 讨论(0)
  • 2021-01-31 13:48

    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:

    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

    0 讨论(0)
  • 2021-01-31 13:50

    Had this problem with RDS too.

    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

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

    Create your DB/Schema

    CREATE SCHEMA/DATABASE ....
    
    0 讨论(0)
  • 2021-01-31 13:50

    I fixed it by logging in with postgres user (and then apply my changes, which was changing ownership in my case):

    sudo -u postgres psql
    ALTER DATABASE my_database OWNER TO new_user;
    
    0 讨论(0)
提交回复
热议问题