PG::ConnectionBad: could not translate host name error after running export DATABASE_URL=postgres://$(whoami)
Asked Answered
F

2

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^

Fealty answered 17/8, 2016 at 19:18 Comment(0)
F
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
Fealty answered 9/9, 2016 at 3:5 Comment(3)
Thanks, its like I was blind to that line in my profile!Vitellin
Thank god for youGilgai
Is that possible even on Jenkins instance ?Hibernia
B
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

Bulbil answered 14/1, 2020 at 1:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.