什么是数据库中的死锁? [英] What is a deadlock in a database?

查看:97
本文介绍了什么是数据库中的死锁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是SQL Server中的死锁?何时死锁?

What is a deadlock in SQL Server and when it arises?

死锁有什么问题,如何解决?

What are the issues with deadlock and how to resolve it?

推荐答案

通常,死锁意味着两个或多个实体阻止了某些源,但它们都无法完成,因为

In general, deadlock means that two or more entities are blocking some sources, and none of them is able to finish, because they are blocking sources in a cyclic way.

一个例子:假设我有表A和表B,我需要在A中进行一些更新,然后在B和I中进行更新决定在使用时锁定两者(这确实是愚蠢的行为,但现在已达到目的)。同时,其他人以相反的顺序执行相同的操作-先锁定B,然后锁定A。

One example: Let's say I have table A and table B, I need to do some update in A and then B and I decide to lock both of them at the moment of usage (this is really stupid behaviour, but it serves it's purpose now). At the same moment, someone else does the same thing in opposite order - locks B first, then locks A.

按时间顺序,这种情况会发生:

Chronologically, this happens:

proc1:锁A

proc2:锁B

proc1:锁B -开始等待直到proc2释放B

proc1: Lock B - starts waiting until proc2 releases B

proc2:锁定A-开始等待直到proc1释放A

proc2: Lock A - starts waiting until proc1 releases A

他们将永远完成。那是一个僵局。在实践中,这通常会导致超时错误,因为不希望任何查询永久挂起,并且基础系统(例如数据库)将杀死未及时完成的​​查询。

Neither of them will ever finish. That's a deadlock. In practice this usually results in timeout errors since it is not desired to have any query hanging forever, and the underlying system (e.g. the database) will kill queries that don't finish in time.

一个现实世界中的死锁示例是,您将房门钥匙锁在汽车中,而车钥匙则锁在房子中。

One real world example of a deadlock is when you lock your house keys in your car, and your car keys in your house.

这篇关于什么是数据库中的死锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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