Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 606
Sachin Gevariya Avatar asked Dec 09 '14 12:12

Sachin Gevariya


People also ask

What is pool in database Yml?

pool is the config of size of connection pool, which is 5 by default.

What is Connection limit in PostgreSQL Heroku?

Heroku provides managed Postgres databases. Different tiered databases have different connection limits. The Hobby Tier databases are limited to 20 connections. Standard and higher tier databases have higher limits.

What is ActiveRecord base?

ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending.

What is Active Record in Ruby?

1 What is Active Record? Active Record is the M in MVC - the model - which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.


2 Answers

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)
like image 163
Musaffa Avatar answered Nov 11 '22 04:11

Musaffa


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

See Options in following API links:

  • Rails 4.2.4 ConnectionPool API doc
  • Rails 4.1.13 ConnectionPool API doc
  • Rails 4.0.13 ConnectionPool API doc
like image 45
Juanito Fatas Avatar answered Nov 11 '22 04:11

Juanito Fatas