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
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.
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;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO your_user;... postgresql.org/docs/13/sql-grant.html ... stackoverflow.com/questions/26277356/…