【问题标题】:Unable to get through Postgres connection with ActiveRecord无法通过 ActiveRecord 的 Postgres 连接
【发布时间】:2018-01-16 21:32:09
【问题描述】:

看在上帝的份上,我无法理解为什么 postgres 抱怨密码验证(使用 ActiveRecord)。

sudo -u postgres psql rdb 

这项工作(不要求密码)

local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5

但是当连接像 ActiveRecord 这样的 ORM 时,它会报错。

ActiveRecord::Base.establish_connection(adapter: 'postgresql', username: 'postgres', database: 'rdb')

 The server requested password-based authentication, but no password was provided.

这是一个基本设置,我一直希望它能够正常工作。我最后的手段是允许 trustmd5(在 pg_hba.conf 上),但在我继续之前,请向我提供一些关于为什么上述方法不起作用的指针。

刚刚更新 postgres 在 localhost 运行

【问题讨论】:

    标签: ruby-on-rails postgresql activerecord


    【解决方案1】:

    sudo 命令正在触发local all postgres peer 限制,而不是要求输入密码。带有postgresql 适配器的 ActiveRecord 配置使用这个:

    :host - 默认为 /tmp 中的 Unix 域套接字。在没有的机器上 Unix-domain sockets,默认连接localhost。

    您的机器上有工作插座吗? /tmp 可写吗?可能是使用到127.0.0.1 的TCP 连接,触发md5 指示的密码检查。

    【讨论】:

    • 我有一个位于/var/run/postgresql/.s.PGSQL.5432 .s.PGSQL.5432.lock 的unix 套接字
    猜你喜欢
    • 2013-11-21
    • 1970-01-01
    • 2014-10-08
    • 2018-08-14
    • 2018-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多