Centos – Cannot set postgres user password

centoscentos6postgresqlruby

Trying to install PostgreSQL with Ruby on Rails with Nginx on CentOS 6.5 using the following guide:
http://karolgalanciak.com/blog/2013/07/19/centos-6-4-server-setup-with-ruby-on-rails-nginx-and-postgresql/

After install I went to configure the user, so issued command sudo su postgres then psql. When I do this, I get the following error:

could not change directory to "/root": Permission denied
psql (9.3.4)

Ignoring this, I issued the command:

alter user postgres with password 'postgres-user-password';

Then I went to change the auth method to md5 dy doing:

sudo vi /var/lib/pgsql/9.3/data/pg_hba.conf

When I do this I am shown the prompt:

[sudo] password for postgres:

No matter what password I enter, I'm told Sorry, try again. even though the password is exactly the one I just set.

Tried following instructions from this post by user716468, but no luck:
What's the default superuser username/password for postgres after a new install?

When I do sudo -u postgres psql postgres I'm told:

postgres is not in the sudoers file.  This incident will be reported.
You have new mail in /var/spool/mail/root

What is wrong here?

Best Answer

Firstly, always ALWAYS use either the -l or just plain - when using sudo. For example, "sudo su - postgres" not "sudo su postgres". This ensures that you're correctly picking up the target users environment.

Sounds like you're using sudo as the root user. This is unnecessary. The root user already has the required rights.

If you want a user to use sudo, then you'll need an appropriate config entry in /etc/sudoers. As the postgres accoutn is a service account, you'd be better served not creating a sudoers entry for postgres. Better to just do the work as root or sudoing from a 'normal' account.