Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano postgresql: FATAL: Peer authentication failed for user

I am deploying an app to digital ocean for the first time and ran into two (possible more) issues.

1) I can't bundle install after adding gem 'unicorn' to Gemfile. I found that kgio is not compatible with windows. Do I have to have Gemfile.lock present when I deploy via capistrano? How would I work around this issue?

group :production do
  gem 'pg', '0.14.1'
  gem "nginx"
  gem 'unicorn'
end

2) I am having trouble with authentication on postgresql on the server.

production:
  adapter: postgresql
  encoding: unicode
  database: postgresql
  pool: 5
  username: postgresql
  password: secret

I ran these commands (along with some other variations):

create user postgresql with password 'secret';
create database postgresql with owner postgresql;

Every time I cap deploy, I get this error:

FATAL: Peer authentication failed for user "postgresql"

I tried putting an invalid username that I know doesn't exist, a database that is invalid but the error message is always the same. According to postgresql website, I should be getting different errors for those...

If I can get some help, that'd be amazing. Thank you!

like image 240
user2612027 Avatar asked Jul 23 '13 19:07

user2612027


People also ask

Why peer authentication failed for user postgres?

The connection failed because by default psql connects over UNIX sockets using peer authentication, that requires the current UNIX user to have the same user name as psql .

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.

What is the password for Postgres user?

Login and Connect as Default User For most systems, the default Postgres user is postgres and a password is not required for authentication. Thus, to add a password, we must first login and connect as the postgres user.


2 Answers

You need to specify the host for the password authentication.

production:
  adapter: postgresql
  encoding: unicode
  database: postgresql
  pool: 5
  host: localhost
  username: postgresql
  password: secret

More details here

like image 148
Charles Okara Avatar answered Sep 30 '22 05:09

Charles Okara


You have to set up Postgres for password or md5 (safer: scram-sha-256 since Postgres 11) authentication first - in the pg_hba.conf file.

As long as only ident or peer authentication is allowed, passwords are not prompted. You are only allowed to log in as the db role corresponding to your system user.

BTW, database role and OS user are typically called postgres, not postgresql. That's not a typo there, I assume?

Try in a shell:

sudo -u postgres -i

And then log in as postgres db role with peer authentication.

See:

  • PostgreSQL error: Fatal: role "username" does not exist
  • Run batch file with psql command without password
like image 22
Erwin Brandstetter Avatar answered Sep 30 '22 05:09

Erwin Brandstetter