Postgres create a new user

To create a new user in PostgreSQL, you can use the following command:

CREATE ROLE newuser WITH PASSWORD 'password';

Replace newuser with the desired username and password with the desired password.

If you want to create a new user with a specific role or permissions, you can use the following command:

CREATE ROLE newuser WITH PASSWORD 'password' CREATEDB;

This will create a new user with the ability to create new databases.

You can also specify additional options, such as:

For example:

CREATE ROLE newuser WITH PASSWORD 'password' CREATEDB SUPERUSER;

This will create a new user with the ability to create new databases and with superuser privileges.

Once you have created the new user, you can grant them specific permissions or roles using the GRANT command. For example:

GRANT USAGE ON SCHEMA public TO newuser;

This will grant the new user the ability to use the public schema.

You can also revoke permissions or roles using the REVOKE command. For example:

REVOKE ALL PRIVILEGES ON DATABASE mydatabase FROM newuser;

This will revoke all privileges on the mydatabase database from the new user.

It's also a good practice to create a new user with a specific role, for example:

CREATE ROLE newuser WITH PASSWORD 'password' INHERIT;
CREATE ROLE myapp WITH PASSWORD 'password';
GRANT myapp TO newuser;

This way you can manage the permissions and roles of the new user separately from the default roles.