Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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" 
like image 469
Ultranuke Avatar asked Oct 31 '14 23:10

Ultranuke


People also ask

How do I create a PostgreSQL schema?

PostgreSQL has a CREATE SCHEMA statement that is used to create a new schema in a database. Syntax: CREATE SCHEMA [IF NOT EXISTS] schema_name; Let's analyze the above syntax: First, specify the name of the schema after the CREATE SCHEMA keywords.

Is role same as user in Postgres?

Users, groups, and roles are the same thing in PostgreSQL, with the only difference being that users have permission to log in by default. The CREATE USER and CREATE GROUP statements are actually aliases for the CREATE ROLE statement.


1 Answers

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

When using Amazon RDS, the user issuing the CREATE DATABASE must 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 o which is going to own a database 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 
like image 171
David Jones Avatar answered Oct 22 '22 00:10

David Jones