Question

I am running pretty often into the MySQL max_user_connections limitation.

Probably after a deploy when I try to run some kind of command like rake db:migrate or trying to access the console.

I understand the limitation and that it might be better to upgrade to a paid plan... but at the same time I was running into this when I try to initial deploy the Rails application.

is there anything I can do to prevent it?

full error:

Mysql2::Error: User 'xxxxxx' has exceeded the 'max_user_connections' resource (current value: 2)
Was it helpful?

Solution

The reason for this is, that for the zero-downtime-deploy the old and the new version run at the same time for up to two minutes while the routing tier makes sure new requests go to the new version while the old one finishes any pending requests.

To avoid running into connection errors with the free MySQLs Add-on you'd have to setup the rails connection pool to only open 1 connection max.

Your database.yml should look something like this for the production environment:

production:
  adapter: mysql2
  encoding: utf8
  pool: 1
  database: <%= "'#{ ENV['MYSQLS_DATABASE'] }'" %>
  host: <%= "'#{ ENV['MYSQLS_HOSTNAME'] }'" %>
  port: <%= ENV["MYSQLS_PORT"] %>
  username: <%= "'#{ ENV['MYSQLS_USERNAME'] }'" %>
  password: <%= "'#{ ENV['MYSQLS_PASSWORD'] }'" %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top