【问题标题】:PostgreSQL fe_sendauth: no password suppliedPostgreSQL fe_sendauth:未提供密码
【发布时间】:2019-06-04 00:37:19
【问题描述】:

我知道 SO 上有成千上万个类似这样的问题,但我都看过了,但我仍然无法解决我的问题。

我正在使用 ansible 做所有事情,所以它非常自动化,但无论如何,这是我的文件:

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

我在我的系统中创建了一个deploy 用户(和没有设置密码的 postgres 用户)。现在,虽然我完全可以使用psql -d my_db(在服务器上)从bash 登录postgres,但我无法使用我的rails 应用程序连接到数据库。运行 rake db:migrateMigration 给了我

PG::ConnectionBad: fe_sendauth: no password supplied

我在做一个开发者方面非常糟糕,我从前天早上开始就在与这个问题作斗争,它仍然存在,所以如果有人可以帮助我解决这个问题,我将不胜感激。

【问题讨论】:

  • psql 使用本地套接字连接,rails 使用 localhost over TCP/IP。本地受信任,localhost 需要密码(使用 md5)。你可以为你的 Rails 用户设置一个 pgpass 文件:postgresql.org/docs/current/static/libpq-pgpass.html
  • 是的,就是这样!我不知道 rails 连接到 postgres 的方式与用户不同。谢谢!请将其添加为答案,以便我将其标记为已接受:)

标签: postgresql unix ansible


【解决方案1】:

psql 使用本地套接字连接,rails 使用 localhost over TCP/IP。本地受信任,localhost 需要密码(使用 md5)。你可以为你的 Rails 用户设置一个 pgpass 文件:http://www.postgresql.org/docs/current/static/libpq-pgpass.html

【讨论】:

  • 在我的情况下,psql 在通过 localhost:5432 连接时抱怨密码为空,但是在使用 pgAdmin III 时,通过 localhost:5432 连接有效?
【解决方案2】:

在C里你可以这样做,我什至不知道Rails是什么

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

我收到了完全相同的错误消息。

【讨论】:

    猜你喜欢
    • 2013-08-02
    • 2020-06-08
    • 1970-01-01
    • 2014-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    相关资源
    最近更新 更多