User and Role in PostgreSQL

User and Role in PostgreSQL

In PostgreSQL users and roles are essentially the same thing with the only difference being users have permission to log in by default.

 USER = ROLE + LOGIN PERMISSION

According to PostgreSQL, both of the below statements are the same.

CREATE USER <USERNAME> WITH PASSWORD <PASSWORD>
CREATE ROLE <ROLENAME> WITH LOGIN PASSWORD <PASSWORD>

It is usually preferred to create a role with the least set of permissions and attach it to the user. All the new role and user inherits permission from the public role. This means that the new user and role can create the objects in the public schema

Any user, or role can have permission at the database, schema, and schema object levels. If the user or role has permission on the table but not on schema then it won't be able to access the table.

image.png

For more details please look at this documentation from AWS link