DEV Community

Ben Purinton
Ben Purinton

Posted on

Setting the correct database connection on production with Render

While deploying a Rails 8 app on Render today, I faced this issue in the deployment log:

ActiveRecord::ConnectionNotEstablished: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory (ActiveRecord::ConnectionNotEstablished) Is the server running locally and accepting connections on that socket? Caused by: PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory (PG::ConnectionBad) Is the server running locally and accepting connections on that socket? Tasks: TOP => db:migrate (See full trace by running task with --trace) ==> Pre-deploy has failed ==> Exited with status 1 
Enter fullscreen mode Exit fullscreen mode

That was confusing because I did deploy my Render app with a database connection.

But I did the logical thing which was:

  • Check the database existed on Render and was connected via the Environment Variables to my deployed web service. It was!
  • Go to the config/database.yml and see what the connection was expecting...

In the config/database.yml, I found:

# ... production: primary: &primary_production <<: *default database: news_production username: news password: <%= ENV["NEWS_DATABASE_PASSWORD"] %> # ... 
Enter fullscreen mode Exit fullscreen mode

Oops! By default, when I created my app Rails 8 app with rails new ..., it set the production database.

But what I actually want in those lines is:

# ... production: primary: &primary_production <<: *default url: <%= ENV["DATABASE_URL"] %> # ... 
Enter fullscreen mode Exit fullscreen mode

I made that change, pushed a commit, and the app is up and running!

Top comments (0)