Normally I would set the pool size as
development:
adapter: postgresql
encoding: unicode
database: openkitchen_development
username: rails
host: localhost
pool: 10
password:
in database.yml. However heroku replaces the config file. I'm using girl_friday to do background db work and need to increase the thread pool size.
Simply add a pool
query parameter to the DATABASE_URL
in your heroku config. To set the pool size to 15 in your heroku app use something like:
heroku config -s | awk '/^DATABASE_URL=/{print $0 "?pool=15"}' | xargs heroku config:add
For what it's worth, using the URL params method as described in other answers here is not recommended by Heroku. They reserve the right to reset or change this URL at any time, and long term this behavior will likely be removed for the Rails build behavior, anyway.
Setting additional parameters via an after-initialize application callback is the recommended way to modify the configuration of your heroku-postgresql databases per this dev center article.
In 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['pool'] = 10
ActiveRecord::Base.establish_connection(config)
end
end
Heroku now has a nice article on managing pool sizes - https://devcenter.heroku.com/articles/concurrency-and-database-connections#connection-pool
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