2

When I try to create a new user or role I am getting

[42501] ERROR: permission denied to create role

I am executing

CREATE user test with PASSWORD 'xyz1234reee'

I am logged in as a superuser

2
  • have you granted the correct permissions to the current user? GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO your_user; ... postgresql.org/docs/13/sql-grant.html ... stackoverflow.com/questions/26277356/… Commented Feb 19, 2021 at 16:28
  • 1
    Not reproducible. Superusers can create users. Maybe you aren't really a superuser. Maybe you aren't really connected to PostgreSQL, but rather some hacked up fork. Commented Feb 19, 2021 at 19:46

3 Answers 3

4

You need to login as superuser postgees or else any other user who has privilege to create role.

Once you login as superuser, either you can create desired role or else you can grant createrole permission to a user in postgres.

If anyuser don't have permission to create role, it will throw error: permission denied to create role.

To assign permission to create role:

ALTER USER user_name CREATEROLE;

Now, you can login using above user and create role.

Sign up to request clarification or add additional context in comments.

Comments

1

You are not logged in as a superuser.

Perhaps you are on a hosted database, and they gave you a user like rds_superuser. That sounds like a superuser, but isn't.

Comments

0

For example, you can create the user(role) john with CREATEROLE privilege or add CREATEROLE privilege to the user(role) john as shown below. *You probably need to log in with any superusers(e.g., postgres) and you can omit WITH which is optional:

CREATE ROLE john WITH LOGIN PASSWORD 'apple' CREATEROLE;

Or:

ALTER ROLE john WITH CREATEROLE;

Then, you can create, alter and drop the user(role) david by logging in with john as shown below. *Be careful, there is the restriction to add some privileges and my answer explains how to create a database:

CREATE ROLE david WITH LOGIN PASSWORD 'orange';
ALTER ROLE david WITH PASSWORD 'kiwi';
DROP ROLE david;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.