PostgreSQL fe_sendauth: no password supplied

2019-03-23 19:10发布

问题:

I know there are thousands of questsions like this one here on SO but i've seen them all and i'm still not able to deal with my problem.

I'm doing everything using ansible so it's quite automated but, anyway, here are my files:

pg_hba.conf

local   all             all                                     trust
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5
host    all             all             10.11.12.0/24           md5

database.yml

production:
  database: my_db
  adapter: postgresql
  host: localhost
  username: deploy
  encoding: unicode
  min_messages: WARNING
  template: template0

And i have a deploy user (and postgres user without a password set) in my system created. And now, while i'm totally able to sign in to postgres from bash using psql -d my_db (on server), i'm not able to connect to the db with my rails app. Running rake db:migrateMigration gives me

PG::ConnectionBad: fe_sendauth: no password supplied

I'm quite terrible at beeing a devop and i'm fighting with that issue from the day before yesterday's morning and it's still here so if there is anyone who can help me with that, i would be be more than grateful.

回答1:

psql is using a local socket connection, rails is using localhost over TCP/IP. Local is trusted, localhost requires an password (using md5). You could setup a pgpass file for your rails user: http://www.postgresql.org/docs/current/static/libpq-pgpass.html



回答2:

In C you can do it like this, I don't even know what Rails is

conninfo = "hostaddr = 127.0.0.1 dbname = bitcoin user = alan password = mypass";
conn = PQconnectdb(conninfo);

I had exactly the same error message.