如何设置Ruby on Rails 4+应用程序的默认数据库隔离级别 [英] How to set a Ruby on Rails 4+ app's default db isolation level
问题描述
我想让我的应用程序对每笔交易进行序列化默认。然后,我将基于性能度量放松隔离,并知道特定操作/事务使用和更改哪些数据。
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.
对于每个案例,隔离级别为Rails postgresql如何将事务隔离级别设置为可序列化,但我认为出于相同的原因,这种方法是错误的,以防止html转义以防止xss错误并被丢弃:白名单比黑名单更安全。
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?
推荐答案
如果要使用默认设置,那么我建议在您的MySQL配置中进行设置。此处描述了该设置: https:// dev .mysql.com / doc / refman / 5.7 / en / server-options.html#option_mysqld_transaction-isolation
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
对于PostgreSQL,该设置称为 default_transaction_isolation 。您可以在 postgresql.conf <中进行设置/ a>。
For PostgreSQL the setting is called default_transaction_isolation. You can set this in postgresql.conf.
这篇关于如何设置Ruby on Rails 4+应用程序的默认数据库隔离级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!