Help with PostgreSQL and Sustainable Web Development

I’m someone with no fast internet connection and would like to install all my stuff minimally, so I did without Docker in that book (Sustainable Web Development).

All went well until I got to page 38 and got this error when I tried to reset db

PG::ConnectionBad: could not translate host name “db” to address: Unknown host

How to solve it?

1 Like
PG::ConnectionBad: could not translate host name “db” to address: Unknown host

This error is saying the application can’t find the database host it’s trying to connect to. It is assumed that you are using a local database, you may have something like this in your database.yml:

default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # https://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

Enter a new line after pool and state the following line:

host: localhost # Or another IP address that you want to point.

Let me know if you run into additional issues.

Tried putting that line in default: after pool:<%= ENV.fetch(“RAILS_MAX_THREADS”) { 5 } %> and it still failed

Changed my environment variables of .env.development and .env.test from @db to @localhost and it worked!