Pivotal Knowledge Base


How to Override the Default Connection Pool size in Ruby on Rails


Pivotal Cloud Foundry® (PCF) Version 1.7.x


When reviewing database services in the marketplace, choosing a higher plan is preferred in order to allow a larger concurrent connection size. However, it is not enough to increase the concurrent connection size on the database side only. As far as Ruby on Rails is concerned, the connection pool size should also be adjusted to match the connection size on the database side as well. The default connection pool size is 5 in Ruby on Rails. We have to change the default value in order to achieve maximum concurrent connections.


For Rails versions 4 or before, connection information would read from ENV["DATABASE_URL"]. Ruby buildpack ignores the contents of any database.yml that you provide and overwrites it during staging. So you have to specify the connection pool size in ENV["DATABASE_URL"]. Here is a sample, which connects a MySQL database and the connection pool size is set to 15.

cf set-env <application-name> DATABASE_URL "mysql://username:password@hostname:3306/dbname?reconnect=true&pool=15"
cf restage <application-name>

For Rails versions 4.1 and later, you have to set connection information in config/database.yml.

For example:

Daivd-Office-Mac:rails4_web_app ubuntu$ more config/database.yml 
  adapter: postgresql
  database: hope-dev

  adapter: postgresql
  database: hope-test

  adapter: mysql2
  database: hope
  user: hope
  pool: 15

Additional Information

For additional information, refer to:

Configure Service Connections for Ruby


Powered by Zendesk