【问题标题】:PG::ConnectionBad: could not translate host name error after running export DATABASE_URL=postgres://$(whoami)PG::ConnectionBad: 运行 export DATABASE_URL=postgres://$(whoami) 后无法翻译主机名错误
【发布时间】:2016-12-24 13:58:29
【问题描述】:

我在运行后收到此错误

export DATABASE_URL=postgres://$(whoami)

在命令行上。现在当我运行命令时

$$ rake db:migrate

这是完整的错误

rake aborted!
PG::ConnectionBad: could not translate host name "Jillian" to address: nodename nor servname provided, or not known

Tasks: TOP => db:migrate

如何修复 postgres?

PS 我正在按照本教程 https://devcenter.heroku.com/articles/heroku-postgresql#local-setup 为 python 应用程序设置 pg,但我可能有一个旧版本的 pg。我试图至少让 postgres 恢复到我运行它之前的状态^

【问题讨论】:

    标签: database postgresql pg rails-postgresql


    【解决方案1】:

    ....还有你们一直在等待的答案:

    如果您通过运行 export DATABASE_URL=... 弄乱了您的开发环境,如果您处于与上述类似的情况并且已经在每个项目中设置了您的环境,请通过运行解决此问题

    unset DATABASE_URL
    

    【讨论】:

    • 谢谢,好像我对个人资料中的那一行视而不见!
    • 感谢上帝
    • 即使在 Jenkins 实例上也有可能吗?
    【解决方案2】:

    我的解决方案是更改 /etc/hosts 文件

    在我的 application.yml 文件中定义:

    databases:
      crm:
        adapter: postgresql
        host: postgresql
    

    错误看起来像

    PG::ConnectionBad:
      could not translate host name "postgresql" to address: nodename nor servname provided, or not known
    

    因此我编辑了我的 /etc/hosts 文件(使用 sudo): sudo vim /etc/hosts 并添加了下一行

    127.0.0.1       postgresql
    

    之后一切正常

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-12
      • 1970-01-01
      • 2014-09-05
      • 2015-09-11
      • 2012-08-23
      • 1970-01-01
      相关资源
      最近更新 更多