Skip to content

How To Create Users and Roles in PostgreSQL

A warm Hello to all the readers!

I am back with a small tutorial on PostgreSQL. In this I’ll explain how to create roles and users in PostgreSQL database.

User is a fundamental component of database. DB users are different from operating system users. Users are assigned permissions what database objects they can access.

There are roles and users in postgresql. Both are same but the only difference is that a user is allowed to login using psql command while a role is not allowed to login.

Create PostgreSQL Role

CREATE ROLE apex WITH PASSWORD 'use_secure_password:)';
COMMIT;

Note that the password has to be enclosed in single quotes.

Create PostgreSQL User

CREATE USER apex WITH PASSWORD 'use_secure_password:)';
COMMIT;

And we are done.

Have a good day!