typicode / hotel

🏩 A simple process manager for developers. Start apps from your browser and access them using local domains
MIT License
9.98k stars 422 forks source link

PG::ConnectionBad on Rails server #168

Closed zaidhuda closed 7 years ago

zaidhuda commented 7 years ago

I could not connect to postgresql when running my rails server through hotel. This is weird because I can start rails server using the same cmd(with fixed port) I set with hotel:

rails server --port $PORT -b 127.0.0.1

The error I got was:

PG::ConnectionBad (fe_sendauth: no password supplied ):

activerecord (5.0.1) lib/active_record/connection_adapters/postgresql_adapter.rb:671:in 'initialize' activerecord (5.0.1) lib/active_record/connection_adapters/postgresql_adapter.rb:671:in 'new' activerecord (5.0.1) lib/active_record/connection_adapters/postgresql_adapter.rb:671:in 'connect' activerecord (5.0.1) lib/active_record/connection_adapters/postgresql_adapter.rb:217:in 'initialize' activerecord (5.0.1) lib/active_record/connection_adapters/postgresql_adapter.rb:37:in 'new' activerecord (5.0.1) lib/active_record/connection_adapters/postgresql_adapter.rb:37:in 'postgresql_connection' ...

Again, this does not happen when I run rails manually.

typicode commented 7 years ago

Hi @hudadiaz,

Could you try setting http_proxy: false in ~/.hotel/conf.json and then running hotel stop && hotel start?

It adds HTTP_PROXY env and may have some side effects.

Another things is that the process started by hotel doesn't have the same environment variables than in your terminal. By default, it only copies PATH.

So if the database client/rails makes use of an environment variable to connect to the database it could be an explanation (like RAILS_ENV).

You can view and edit passed environment in ~/.hotel/servers/your-server.json.

zaidhuda commented 7 years ago

Another things is that the process started by hotel doesn't have the same environment variables than in your terminal. By default, it only copies PATH.

Adding required env variables solves the issue.

typicode commented 7 years ago

Glad it's solved 👍 What was the env variable (in case someone else has the same issue)?

zaidhuda commented 7 years ago

It was the postgresql user and password. Looking back, the error was almost clear about that. 😄

typicode commented 7 years ago

Oh I see, thanks :)