【问题标题】:I can connect to server's postgres with Rails, but am unable to through the command line我可以使用 Rails 连接到服务器的 postgres,但无法通过命令行
【发布时间】:2019-07-08 20:37:41
【问题描述】:

我正在尝试通过脚本连接到服务器的 Postgres 数据库。我已经 ssh-ed 进入盒子并尝试过

$ psql postgres -U my_username -W   #And then entered the password

并得到错误:

psql: FATAL:  Peer authentication failed for user "my_username"

但是,在此服务器上运行的 Rails 应用程序正在使用这些相同的凭据。我在 Rails 控制台中使用了ActiveRecord::Base.connection_config,并完全按照尝试使用psql 时的方式使用了凭据。在 Rails 控制台中,我可以查询数据库,所以我知道连接在那里工作。

是否有可能某处存在阻止我通过psql 连接的限制?还是我做错了什么?

【问题讨论】:

    标签: ruby-on-rails postgresql psql


    【解决方案1】:

    你有没有这样尝试过:

    psql --username="postgres"
    

    另一种可能性是通知更多参数

    psql --username="postgres" --host="<ip or host name>" --port="<port, default 5432>" -W <db name>
    

    好看!

    【讨论】:

      【解决方案2】:

      尝试像这样连接:

       psql postgres -U my_username -h 127.0.0.1 -W   #And then entered the password
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-04
        • 2023-03-10
        • 2014-06-19
        • 2018-01-20
        • 2018-08-14
        • 2017-05-19
        • 2021-06-14
        相关资源
        最近更新 更多