Reputation: 682
I use PostgreSQL for my Rails application. The authentification to the PostgreSQL server via pgAdmin and console is successful, but when I run Rails application I get the following error:
FATAL: Peer authentication failed for user "postgres"
My database.yml
:
development:
adapter: postgresql
encoding: unicode
database: app_dating
pool: 5
timeout: 5000
username: postgres
password: '123456'
The pg_hba.conf
:
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
I use Rails 4.0.1 and PotgreSQL 9.1.
Upvotes: 0
Views: 88
Reputation: 55908
The pg_hba.conf
you posted appears to not be complete. You probably have another entry similar to this in it (probably a bit more to the top):
# Database administrative login by Unix domain socket
local all postgres peer
The Postgres documentation for the pg_hba.conf state regarding peer authentication:
peer
Obtain the client's operating system user name from the operating system and check if it matches the requested database user name. This is only available for local connections. See Section 19.3.7 for details.
Thus, you have to make sure, that you use the local unix socket (not a TCP connection) with this configuration. Also, you need to have a postgres
user in your Postgres database.
An alternative would be to instead remove that line from the pg_hba.conf
to fallback to the other mechanisms defined. Make sure that your postgres
user has a valid password set though.
Note that is is common to have a predefined superuser named postgres
which has all the rights without any permission checks. It is not wise to use that user for applications (e.g. your Rails app). instead, create a new dadicated user in your Postgres database and use that one for your app.
Upvotes: 2