DEV Community

Ben Purinton
Ben Purinton

Posted on

1

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)

Postmark Image

"Please fix this..."

Focus on creating stellar experiences without email headaches. Postmark's reliable API and detailed analytics make your transactional emails as polished as your product.

Start free