While configuring a new hosting setup with ROR and PostgreSQL. I faced following issue when application tried to connect postgres database server.
Advertisement
Error:-
Solution:-
First I set the the password for postgres user in PostgreSQL using following commands.
$ sudo -u postgres psql
Now set the password using following command.
postgres=# password
Let’s create a new user account for your application using following command. Also crate a database with ownership of that account.
postgres=# create user "myappusr" with password '_password_'; postgres=# create database "myapp_development" owner "myappusr";
Now edit pg_hba postgresql configuration file and update configuration. By default PostgreSQL uses IDENT-based authentication. You need to allow username and password based authentication. IDENT will never allow you to login via -U and -W options.
# vim /var/lib/pgsql/9.4/data/pg_hba.conf
local all postgres trust local all myapp_usr trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: #host all all ::1/128 trust
2 Comments
The second command – to change the password – does not work at all.
Really? Trust? This is very dangerous. Even when database server listen on localhost.
Better replace trust with md5.
This is from documentation – “Allow the connection unconditionally. This method allows anyone that can connect to the PostgreSQL database server to login as any PostgreSQL user they wish, without the need for a password or any other authentication. See Section 19.3.1 for details.”