11

I received this error after running

export DATABASE_URL=postgres://$(whoami)

on the command line. Now when I run the command

$$ rake db:migrate

This is the full error

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

Tasks: TOP => db:migrate

How can I fix postgres?

PS I was following this tutorial https://devcenter.heroku.com/articles/heroku-postgresql#local-setup to set up pg for a python app, but I may have an old version of pg. I'm trying to at least get postgres back to how it was before I ran that^

Jillian Hoenig
  • 137
  • 1
  • 6
  • 28

2 Answers2

14

....And the answer you've all been waiting for:

If you've messed up your development environment by running export DATABASE_URL=..., if you'e in a similar sitaution to the one above and already set up your environments within each project, resolve this issue by running

unset DATABASE_URL
Jillian Hoenig
  • 137
  • 1
  • 6
  • 28
3

My solution was to change /etc/hosts file

In my application.yml file was defined:

databases:
  crm:
    adapter: postgresql
    host: postgresql

and error was looked like

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

therefore I've edit my /etc/hosts file (with sudo): sudo vim /etc/hosts and have added next row

127.0.0.1       postgresql

after that everything works fine

Ruslan Valeev
  • 1,529
  • 13
  • 24