How to set a Ruby on Rails 4+ app's default db isolation level

断了今生、忘了曾经 提交于 2019-12-11 10:56:12

问题


I want to make my application serialize every transaction by default. I'd then relax isolation based on performance measurements and knowing what data particular actions/transactions use and change.

I doubt serializable by default would get into the framework, as it'd slow things down and be difficult to explain. But I don't want to deal with db corruption, and do want internally consistent aggregate calculations.

For case-by-case isolation levels there is Rails postgresql how to set transaction isolation level to serializable but I think this approach is wrong for the same reasons html-escaping to protect against xss were wrong and were dropped: whitelisting is safer than blacklisting.

Has anyone done this already? Where would be a good place to hook into rails to do this?


回答1:


If you want this the default, then I suggest setting it in your MySQL config. The setting is described here: https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_transaction-isolation

[mysqld]
default-character-set = utf8
default-storage-engine = InnoDB
default-table-type = InnoDB
transaction-isolation = SERIALIZABLE

For PostgreSQL the setting is called default_transaction_isolation. You can set this in postgresql.conf.



来源:https://stackoverflow.com/questions/29583303/how-to-set-a-ruby-on-rails-4-apps-default-db-isolation-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!