Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FATAL: Peer authentication failed for user "rails"

I'm trying to run rake db:create with postgresql on a DigitalOcean server.

However, it's returning the error Peer authentication failed for user "rails", referring to config/database.yml where the credentials to log in are stored

What's strange is that these are the exact credentials displayed to me in plain text when I log into the server through SSH. I've tried both <%= ENV['APP_DATABASE_PASSWORD'] %> and the password displayed to me in plain text and the same thing happens.

The environment is in production, which I have to enforce manually because the app is in development on startup and forcing it to change in config/environments.rb isn't working.

If I had to guess I might say that something funny is happening with the environment, because DigitalOcean will continue to serve a cached version of the site until the server is restarted and it might still think it's in development as far as it's concerned. But I'm in kind of a catch-22 until I figure out how to force it into production on startup.

This question is what I've arrived at after a lot of tribulation with postgres and trying to set up a database on the backend, so I need to be walked through a couple things.

Many thanks.

like image 408
JackHasaKeyboard Avatar asked Nov 27 '15 06:11

JackHasaKeyboard


People also ask

How do you change peer to md5?

Find that PostgreSQL configuration file by typing: 'sudo nano /etc/postgresql/11/main/pg_hba. conf'. look for the user 'postgres' in white and look to the right for the 'md5'. That's where you set the authentication method for that PostgreSQL user.

What is peer authentication in Postgres?

The peer authentication method works by obtaining the client's operating system user name from the kernel and using it as the allowed database user name (with optional user name mapping). This method is only supported on local connections. The following configuration options are supported for peer : map.


1 Answers

The problem is with your pg_hba.conf file. Which you can find in /etc/postgresql/9.3/main/pg_hba.conf. Here 9.3 is postgres version, you can change with your postgres version. More detail about authentication is here.

You have code something like :

# TYPE  DATABASE        USER    ADDRESS             METHOD

# "local" is for Unix domain socket connections only
local    all             all                        peer

You can either change it to md5 or trust.

# TYPE  DATABASE        USER    ADDRESS             METHOD

# "local" is for Unix domain socket connections only
local    all             all                        trust

It will fix your problem.

Note : To edit pg_hba.conf file you should have sudo permission on server.

like image 165
Dipak Gupta Avatar answered Sep 28 '22 01:09

Dipak Gupta