简体   繁体   English

选择事务隔离级别

[英]Choosing transaction isolation levels

I don't have a specific example here, I was just trying to understand the different levels of transaction isolation and how one might go about deciding which is best for a given situation. 我在这里没有具体的示例,我只是想了解事务隔离不同级别,以及如何决定哪种情况最适合给定的情况。

I'm trying to think of situations in which I would want a transaction that is not serializable, other than to possibly increase performance in situations where I'm willing to give up a little data integrity. 我试图考虑一种情况,在这种情况下,我希望事务不可序列化,而在我愿意放弃一点数据完整性的情况下,可能会提高性能。

Can anybody provide an example of a situation in which "read uncommitted", "read committed", and/or "repeatable read" would be the preferable isolation level? 谁能提供一个例子,其中“未提交读”,“已提交读”和/或“可重复读”是更好的隔离级别?

Using the serializable isolation level does not only have advantages, but also disadvantages: 使用可序列化隔离级别不仅有优点,而且也有缺点:

  • You have to accept increased performance overhead. 您必须接受增加的性能开销。

  • You have to handle serialization errors by redoing transactions, which complicates your application code and hurts performance if it happens often. 您必须通过重做事务来处理序列化错误,这会使您的应用程序代码复杂化,并且如果经常发生,则会损害性能。

I'll come up with use cases for the other transaction levels. 我将提出其他事务级别的用例。 This list is of course not complete: 此列表当然是不完整的:

  1. READ UNCOMMITTED : If you request this isolation level, you will actually get READ COMMITTED . READ UNCOMMITTED :如果您请求此隔离级别,则实际上将获得READ COMMITTED So this isolation level is irrelevant. 因此,此隔离级别无关紧要。 On database systems that use read locks, you use that isolation level to avoid them. 在使用读取锁的数据库系统上,可以使用隔离级别来避免它们。

  2. READ COMMITTED : This is the best isolation level if you are ready to deal with concurrent transactions yourself by locking rows that you want to be stable. READ COMMITTED :如果您准备通过锁定要稳定的行自己处理并发事务,则这是最佳的隔离级别。 The big advantage is that you never have to deal with serialization errors (except when you get a deadlock). 最大的优点是您不必处理序列化错误(除非遇到死锁)。

  3. REPEATABLE READ : This isolation level is perfect for long running read-only transactions that want to see a consistent state of the database. REPEATABLE READ :此隔离级别非常适合希望查看数据库状态一致的长时间运行的只读事务。 The prime example is pg_dump . 最主要的例子是pg_dump

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM