12

I am running a rails application with postgresql as a database, I have a user on the database with empty password. The application runs successfully but when I am trying to use a model from the console I am getting the following error.

PG::ConnectionBad: fe_sendauth: no password supplied
user3814030
  • 1,263
  • 3
  • 20
  • 37

1 Answers1

33

Short answer, in your database.yml file, replace:

host: localhost with host: ''

This should do the trick.

For long answer and explanation, look at this answer

Community
  • 1
  • 1
K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110
  • This will likely cause a problem with various CI environments. I get around that by doing this `host: <%= ENV['MYAPP_DATABASE_HOST'] || 'localhost' %>`. Then set the `MYAPP_DATABASE_HOST` environment variable on your development machine `MYAPP_DATABASE_HOST=""`. Do not set this envar in production or in CI. – IAmNaN Dec 16 '18 at 20:11
  • You are a genius! – Philippe Delteil Apr 03 '19 at 01:48
  • It also returns `Caused by: PG::ConnectionBad: FATAL: Peer authentication failed for user "postgres"`. By default the superuser postgres has no password I shouldnt have to change `peer` to `md5` in `pg_hba.conf` – Ridhwaan Shakeel Oct 20 '20 at 22:04