亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

減少SQL Server 死鎖

系統 2256 0

Deadlocking ?occurs when two user processes have locks on separate objects and each process is trying to acquire a lock on the object that the other process has. When this happens, SQL Server identifies the problem and ends the deadlock by automatically choosing one process and aborting the other process, allowing the other process to continue. The aborted transaction is rolled back and an error message is sent to the user of the aborted process. Generally, the transaction that requires the least amount of overhead to rollback is the transaction that is aborted.

As you might imagine, deadlocks can use up SQL Server’s resources, especially CPU power, wasting it unnecessarily.

Most well-designed applications, after receiving a deadlock message, will resubmit the aborted transaction, which most likely can now run successfully. This process, if it happens often on your server, can drag down performance. If the application has not been written to trap deadlock errors and to automatically resubmit the aborted transaction, users may very well become confused as to what is happening when they receive deadlock error messages on their computer.

Here are some tips on how to avoid deadlocking on your SQL Server:

  • Ensure the database design is properly normalized.
  • Have the application access server objects in the same order each time.
  • During transactions, don’t allow any user input. Collect it before the transaction begins.
  • Avoid cursors.
  • Keep transactions as short as possible. One way to help accomplish this is to reduce the number of round trips between your application and SQL Server by using stored procedures or keeping transactions with a single batch. Another way of reducing the time a transaction takes to complete is to make sure you are not performing the same reads over and over again. If your application does need to read the same data more than once, cache it by storing it in a variable or an array, and then re-reading it from there, not from SQL Server.
  • Reduce lock time. Try to develop your application so that it grabs locks at the latest possible time, and then releases them at the very earliest time.
  • If appropriate, reduce lock escalation by using the ROWLOCK or PAGLOCK.
  • Consider using the NOLOCK hint to prevent locking if the data being locked is not modified often.
  • If appropriate, use as low of an isolation level as possible for the user connection running the transaction.??
  • Consider using bound connections.

[6.5, 7.0, 2000, 2005]? Updated 6-6-2005

*****

When a deadlock occurs, by default, SQL Server choose a deadlock “victim” by identifying which of the two processes will use the least amount of resources to rollback, and then returns error message 1205.

But what if you don’t like default behavior? Can you change it? ?Yes, you can, by using the following command:

SET DEADLOCK_PRIORITY {? LOW | NORMAL | @deadlock_var ?}

WHERE:

Low ?tells SQL Server that the current session should be the preferred deadlock victim, not the session that incurs the least amount of rollback resources. The standard deadlock error message 1205 is returned.

Normal ?tells SQL Server to use the default deadlock method.

@deadlock_var ?is a character variable specifying which deadlock method you want to use. Specify “3″ for low, or “6″ for normal.

This command is set a runtime for a specified user connection. [2000]? Updated 9-1-2005

*****

To help identify deadlock problems , use the SQL Server Profiler’s Create Trace Wizard to run the “Identify The Cause of a Deadlock” trace. This will provide you with the raw data you need to help isolate the causes of deadlocks in your databases.? [7.0]

*****

To help identify which tables or stored procedures are causing deadlock problems , turn on trace flag 1204 (outputs basic trace data) or trace flag 1205 (outputs more detailed trace data).

DBCC TRACEON (3605,1204,-1)

Be sure to turn off this trace flag when you are done, as this trace can eat up SQL Server’s resources unnecessarily, hurting performance. [6.5, 7.0, 2000]? Updated 11-6-2006

*****

Ideally, deadlocks should be eliminated from your applications.? But if you are unable to eliminate all deadlocks ?in your application, be sure to include program logic in your application to deal with killed deadlock transactions in a user-friendly way.

For example, let’s say that two transactions are deadlocked and that SQL Server kills one of the transactions. In this case, SQL Server will raise an error message that your application needs to respond to. In most cases, you will want your application to wait a random amount of time after the deadlock in order to resubmit the killed transaction to SQL Server.

It is important that there is a random waiting period because it is possible that another contending transaction could also be waiting, and you don’t want both contending transactions to wait the same amount of time and then both try to execute at the same time, causing another deadlock.

減少SQL Server 死鎖


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 老司机午夜精品视频在线观看免费 | 欧美精品日韩一区二区三区 | 网友自拍视频悠悠在线 | 男女一级毛片 | 国产永久在线 | 四虎2019| 国产精品伦理久久久久久 | 美女黄频| 91长腿女神清纯大又嫩在线 | 4虎影院永久地址www | 亚洲国产欧美日韩一区二区 | 高清影院|精品秒播3 | 99热精品久久| 日本一级www乱码在线 | 色综合久久最新中文字幕 | 综合图区亚洲白拍在线 | 香港三级做爰大爽视频 | 在线免费亚洲 | 久久99亚洲精品久久99 | 免费高清在线影片一区 | 国产成人永久在线播放 | 欧美日韩综合精品一区二区三区 | 一级呦女专区毛片 | 国产精品91av| 日本又黄又爽又色的免费视频 | 国产精品一区二区三区久久 | 欧美精品一区二区三区在线 | 成人97在线观看免费高清 | 美女羞羞视频 | 66精品综合久久久久久久 | 亚洲精品第五页中文字幕 | 亚洲精品国产美女在线观看 | 久久机热这里只有精品无需 | 免费视频福利 | 日韩精品你懂的在线播放 | 亚洲美女性生活视频 | 在线成人播放毛片 | 亚洲狠狠成人综合网 | 色鬼久久| 成人小视频免费观看 | 最新国产中文字幕 |