Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

database.yml in Rails reconnect set to true or false

In database.yml, the default settings for reconnect on Rails 3 and 4 is false. What is the common setting, and in what circumstances we should set it to true? Thanks.

like image 691
Victor Avatar asked Feb 06 '14 05:02

Victor


1 Answers

You can set it true. This option is introduced in Rails 2.3

MySQL supports a reconnect flag in its connections - if set to true, then the client will try reconnecting to the server before giving up in case of a lost connection. You can now set reconnect = true for your MySQL connections in database.yml to get this behavior from a Rails application.

Rails team set this option default as 'false' because, they don't want to change the behavior of existing applications.

But some side effects are there if we set reconnect = true. It is not transaction-safe.The MySQL documentation in fact explicitly states that the auto-reconnect feature affects transactions.

Any active transactions are rolled back and autocommit mode is reset.

Applications that are not written to deal with this could easily break. The documentation also lists a number of other side effects caused by the auto-reconnect feature, all of which could cause applications not written to anticipate the behavior to function incorrectly or fail.

check:

rails 2.3 release notes

mysql-reconnect-value-doesnt-stick

see this StackOverflow question

like image 175
Abhi Avatar answered Oct 23 '22 14:10

Abhi