Sachin Gevariya
Sachin Gevariya

Reputation: 1167

How to override pool and reaping_frequency in heroku's database.yml

I am using heroku with Rails 4.1.1 and Ruby 2.1.1. I am using default database configuration for heroku. That's why I have put database.yml into .gitignore and I am not using database.yml for production.

I am facing issue for PG::ConnectionBad: PQsocket() can't get socket descriptor and for solve this error i need to set reaping_frequency.

The reaping_frequency can tell Active Record to check to see if connections are hung or dead every N seconds and terminate them. While it is likely that over time your application may have a few connections that hang, if something in your code is causing hung connections, the reaper will not be a permanent fix to the problem.

Now I want to add this configuration into database.yml.

  reaping_frequency: 10

so should I directly add this configuration over database.yml for override or is there any another better way to set this frequency into heroku?

Thanks in advance for suggestion.

Upvotes: 6

Views: 7051

Answers (2)

Juanito Fatas
Juanito Fatas

Reputation: 9969

Rails 4.0+ can directly specify pool and reaping_frequency in config/database.yml.

See Options in following API links:

Upvotes: 4

Musaffa
Musaffa

Reputation: 702

In your config/unicorn.rb or config/puma.rb set pool and reaping_frequency in the config:

config = ActiveRecord::Base.configurations[Rails.env] ||
            Rails.application.config.database_configuration[Rails.env]
config['pool']              = ENV['DB_POOL'] || 5
config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
ActiveRecord::Base.establish_connection(config)

Upvotes: 6

Related Questions