Saturday, 23 October 2021

User Vs Role - PostgreSQL

 


In PostgreSQL, user and role can be used interchangeably but only the difference is when we use

"create user syntax" the login privilege will be assigned by default.


But whereas when we create a role which is created by default with no logging. 



 




It means that role may or may not be user.




Creating user





Now role is created 




Role will be never added in pg_user because there is difference between user and role.



By default user comes in with login privilege where roles have no login privileges by default.








Role has been given login privilege 



 







postgres=# CREATE USER librarian;
CREATE ROLE

postgres=# SELECT usename FROM pg_user;
  usename
-----------
 postgres
 librarian
(2 rows)

postgres=#
postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 librarian |                                                            | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

postgres=#
postgres=# ALTER USER librarian WITH SUPERUSER;
ALTER ROLE
postgres=#
postgres=#
postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 librarian | Superuser                                                  | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

postgres=#
postgres=#
postgres=# ALTER USER librarian WITH NOSUPERUSER;
ALTER ROLE

No comments:

Post a Comment

Master and Slave - Sync check - PostgreSQL

  1) Run the below Query on Primary:- SELECT     pid,     usename,     application_name,     client_addr,     state,     sync_state,     sen...