I’m having problems with my application deployed on Heroku. It works fine on local env, but when deployed to Heroku there are often application errors.
The exception in logs are: ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5.000 seconds (waited 5.000 seconds))
The controller and models are nothing fancy, rather simple CRUD operations.
The app is build with Rails 4, its using standard heroku postgres database add-on and WEBrick server.
I've tried to set config like this:
#config/initializers/database_connection.rb
Rails.application.config.after_initialize do
ActiveRecord::Base.connection_pool.disconnect!
ActiveSupport.on_load(:active_record) do
config = Rails.application.config.database_configuration[Rails.env]
config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 5 # seconds
config['pool'] = ENV['DB_POOL'] || 10
config['timeout'] = ENV['DB_TIMEOUT'] || 10
ActiveRecord::Base.establish_connection(config)
end
end
but it did not help.
Do you have any idea what can help?
Heroku Postgres is a managed SQL database service provided directly by Heroku. You can access a Heroku Postgres database from any language with a PostgreSQL driver, including all languages officially supported by Heroku.
Heroku's Postgres open-source database is the most effective service for developers who want to build engaging apps. With all of its features and Heroku's experience managing databases, it guarantees security and compliance with GDPR.
Your DB pool is not the problem. This is a known rails issue. If you are using Rails 4.0.2 then the claim is to use rails master in your Gemfile instead. I am experiencing this issue as well, however I haven't tried this solution yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With