首页 > 解决方案 > Heroku Rails 6 multiple connection not working

问题描述

I have a project running on Rails 6 with multiple database configuration.

This is my database.yml configuration

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")%>

bn: &bn
  adapter: postgresql
  database: <%= ENV.fetch('DB_NAME_BN')%>

default: &default
  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS")%>
  timeout: 5000

development:
  primary:
    <<: *default
    database: <%= ENV.fetch("DB_NAME")%>
  bn:
    <<: *bn
production:
  primary:
    url: <%= ENV.fetch('DATABASE_URL') %>
  bn:
    url: <%= ENV.fetch('DB_NAME_BN')%>

This configuration is correctly working in development, however, when deploying it to Heroku the app crashes.

The error looks like this:

Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.6.0/bin/puma)

Seems like rails is not considering the 3-tier configuration so assumes a local server. I've been trying to configure the file in several ways, none of them work in Heroku. I followed the puma.rb configuration suggested in Heroku but it does not make any difference.

Any thoughts on how I could fix this issue? Is it a Rails issue or a PgAdapter issue?

The relevant part of my Gemfile is

ruby '2.6.3'
gem 'rails', '~> 6.0.0'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'

标签: ruby-on-railsherokumulti-database

解决方案


推荐阅读