English 中文(简体)
库克服务器为什么出现僵局?
原标题:Why do deadlocks happen in SQL Server?

正如我所理解的那样,当一个特殊资源信息数据库忙于处理另一个问题时,它就会陷入僵局,因为现在它非常忙.。 服务器“大多”从要求的资源中挑选出一个问题,以打破僵局,而忽略不计。

我有大约40个案例和后台Windows服务,所有这些都击中了同一个数据库。 我期望减少僵局,以便我能够增加我能够同时运行的镜子数量。

  1. Why can t SQL Server just enqueue the new query and run it when it has time and the resources are available? Most of what I m doing can wait a few seconds on occasion.
  2. Is there a way to set Transaction Isolation Level globally without having to specify it at the onset of each new connection/session?
最佳回答

你对僵局的理解是不正确的。 你所描述的是阻碍。 把这两者混为一谈是一个常见错误。

当两个单独的交易各自需要不同的资源时,就会出现僵局,而这两个交易都不会释放它们所拥有的资源,以便另一方能够运作。 说明:

SPID #1 gets a lock on resource A SPID #2 gets a lock on resource B SPID #1 now needs a lock on resource B in order to complete SPID #2 now needs a lock on resource A in order to complete

SPID #1 can t complete (and therefor release resource A) because SPID #2 has it SPID #2 can t complete (and therefor release resource B) because SPID #1 has it

Since neither SPID can complete one has to give up (i.e. be chosen by the server as the deadlock victim) and will fail.

避免这些交易的最佳办法是使交易少花(需要多少资源)和快捷。

问题回答

死锁是两个加工线同时被另一条管束(可能更多,但两条相当复杂)。 因此,一张桌子就座,然后请求在另一个桌子上锁。 另一表被第二线read锁,由于坐在第一桌上,无法取得进展。

必须消除的原因之一是,在僵局中,它们永远不会结束——两者都不可能取得进展。 唯一的答案是阻止对方完成。

The solution to reducing deadlocks in the sort of situation you are talking about may be to redesign the solution. If you can make sure that less locking occurs, you will have less deadlocks.

之所以出现僵局,是因为两个同时进行的交易可能会重叠,使其他交易需要完成的不同资源中断。

Let s imagine: 1 - Transaction A locks row1 2 - Transaction B locks row2 3 - Transaction A tries to lock row1, and, because of the previous lock, SQL server waits 4 - Transaction B tries to lock row2, and, because of the previous lock, SQL server waits

因此,服务器必须选择交易,将其杀死,并允许对方继续交易。

这一形象很好地说明了这一情况:





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签