【问题标题】: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
【解决方案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
之后一切正常