Ruby on Rails Saturday, February 27, 2016

From 'man createuser':

       createuser creates a new PostgreSQL user (or more precisely, a role). Only superusers and users with
       CREATEROLE privilege can create new users, so createuser must be invoked by someone who can connect as a
       superuser or a user with CREATEROLE privilege.

When postgresql is installed, it also creates a user 'postgres' with role 'postgres'. It also creates a system account with same name 'postgres'.
So this is why 'createuser' should be run as 'postgres' user.

It is possible to connect to postgresql only as a database user AND through an existing database.
During installation from the postgresql apt repository, postgresql only creates the 'postgres' user and the 'postgres' database.
The 'psql' allow the current user to connect to the postgresql database named after the user's name.
So, if the system user is 'dave' AND there is a 'dave' database it is possible for 'dave' to connect to the 'dave' database with command 'psql'.
If 'dave' is also a database user but the database 'dave' was not created, for dave to connect to postgresql it is necessary to specify an existing database with:

$ psql -d postgres


Alternatively, it is possible for dave to connect to postgresql executing the 'psql' command as the 'postgres' user with 'sudo':

$ sudo -u postgres psql



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/61bccd53-b2a9-43d2-9b97-9f1e69f96a59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment