数据库事务 - 它们是如何工作的? [英] Database transactions - How do they work?

查看:19
本文介绍了数据库事务 - 它们是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解有关数据库事务的更多信息,我找到了编写事务的 ACID 经验法则并想到了一些问题.

I'm trying to learn more about database transactions, I found the ACID rule of thumb for writing transactions and thought of a few questions.

ACID 经验法则:

交易必须:

  1. 原子 - 它是一个工作单元,不依赖于以前的和跟踪交易.
  2. 一致 - 数据要么提交要么回滚,没有中间"情况已更新,但有些内容尚未更新.
  3. 隔离 - 没有事务看到当前的中间结果交易.
  4. 持久 - 如果数据已提交,即使系统随即崩溃.

我想知道它们在后台是如何工作的,这样我才能更好地理解在编写此类事务时需要考虑的因素.我想具体细节会因可用的数据库实现而异,但某些规则将始终存在.

I was wondering how they work under the hood, so I can better understand the factors that need to be considered when writing such a transaction. I guess the specific details will vary between the database implementations that are avaliable, but certain rules will always be in place.

  1. 数据库如何在支持原子规则的同时处理并发事务?
    • 是否有按顺序处理的交易队列?
    • 如何处理拖延所有其他事务的冗长事务?
  • 或者是否有一些中间表经过更新可以在这样的崩溃中幸存下来?
  • 或者数据库是否允许写入但事务会在提交时覆盖所有更改?

推荐答案

  1. 有很多不同的方法,包括事务排队、乐观并发控制等.这实际上是一个非常复杂的问题,有相关书籍写过:

  1. There are many different ways, including transaction queueing, optimistic concurrency control etc. This is actually a very complex question, there are books written about it:

http://www.amazon.co.uk/Databases-Transaction-Processing-Application-Oriented-Approach/dp/0201708728/ref=sr_1_3?ie=UTF8&s=books&qid=1281609705&sr=8-3

这取决于数据库中的日志记录级别.如果保留严格的预写日志,那么在系统崩溃的情况下,数据库可以恢复到一致状态.

It depends on the level of logging in the database. If strict write-ahead logs are kept then in the case of a system crash, the database can be wound back to a consistent state.

这取决于并发类型.乐观并发不涉及锁,但是如果事务完成后数据库的状态发生了变化,它将被放弃并重新启动.这可以在很少发生冲突的情况下加速 dbs.还有不同级别的锁定:行、表,甚至整个数据库.

It depends on the type of concurrency. Optimistic concurrency involves no locks, but if the state of the db has changed once the transaction has finished, it is abandoned and restarted. This can speed up dbs where collisions are rare. There are also different levels of locking: row,table, or even the entire db.

这些是非常复杂的问题,如果您想完全回答这些问题,我建议您买本书或参加并行系统讲座系列:-)

These are very complex questions, I'd advise buying a book, or attending a concurrent systems lecture series if you want to be able to fully answer them :-)

这篇关于数据库事务 - 它们是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆