24

Please explain what is the meaning of Create User and Create Role in PostgreSQL i am new at PostgreSQL.

I try to learn bye myself i understand Create User mean that user who are able to access database cluster and mange it in with in same computer where database cluster is created or from another computer with username and password.

And I think create Role mean which new user i create that user have which kind of role. If i set create role to user that he is not able to change database so he can't. But if i set create role this user are able to change database he can.

Can anyone explain more clearly?

Thanks in advance

Muhammad Raza
  • 847
  • 1
  • 8
  • 22

1 Answers1

51

In PostgreSQL 9.4 documentation it says:

CREATE USER is now an alias for CREATE ROLE. The only difference is that when the command is spelled CREATE USER, LOGIN is assumed by default, whereas NOLOGIN is assumed when the command is spelled CREATE ROLE.

So your question about CREATE ROLE and CREATE USER transfers to the question about the difference between the LOGIN and NOLOGIN attribute as PostgreSQL knows only roles.

According to the description the LOGIN/NOLOGIN attribute determines whether or not a role can be used to connect from a client. A client can be anything from your pgAdmin III to lets say a web application. To test this you might want to create a role with LOGIN attribute and use it instead of your postgres role to connect to your server via pdAdmin III.

A role with NOLOGIN attribute can't do this. This type of role can be regarded as an object you can add privileges to. LOGIN roles might then inherit those privileges by adding them as a member. One can think of the whole matter in terms of groups and users being members of groups.

So after all I think this is just another way of expressing what you already said.

Arad Alvand
  • 8,607
  • 10
  • 51
  • 71
MyBrainHurts
  • 2,480
  • 2
  • 27
  • 27