Lockedresource,db_name (one) as DBName;--------------------------------------------------------------Lockedresource DBName--------------------------------------------------------------Tb_te_sizeinformation JybgdbExecute the following script to get the SQL script that is executing the session of the lock resource:DBCC InputBuffer (54);--------------------------------------------------------------EventType Parameters EventInfo--------------------------
table Testdeadlock (Id int constraint pk_testdeadlock_id primary Key int constraint uk_testdeadlock_col2 unique , Remark varchar (100 Then use sqlquerystress, open two reply, respectively, according to the clustered index and nonclustered index, delete the same row of data (the test data will be set when the ID and Col2 are 1),As shownFirst let these two sessions execute (Air line), then insert a row of data into the Testdeadlock table (insert into [Testdeadlock] values (1,1,n
Sessions 1 and Session 2 cannot continue until the other party frees resources. Therefore, SQL Server chooses a session in the deadlock as the "deadlock victim."
Note: The deadlock victim's session will be killed and the transaction will be rolled back.
Note: deadlocks and
column C2 on table T1. In addition, two SP instances are created, namely select data and update data from t1.
Okay. Open a new query window and we will start executing the following query:
-- Batch #2
Use deadlocktest
Set nocount on
While (11 = 1) exec P2 4
Go
After the execution starts, we open the third query window and execute the following query:
-- Batch #3
Use deadlocktest
Set nocount on
Create Table # T1 (C2 int, C3 INT)
Go
W
blocking and deadlock information ' as message --Cycle startWhile @intCounter Begin--Take the first recordSelect @spid = spid, @bl = blFrom #tmp_lock_who where Id = @intCounterBeginIf @spid =0Select ' Causes the database deadlock: ' + CAST (@bl as VARCHAR (10) + ' process number, which executes the SQL syntax as follows 'ElseSelect ' Process number spid: ' + cas
,
Domain =nt_domain, network card address =net_address
Into #t from (
Select flag = ' Deadlock process ',
Spid,kpid,a.blocked,dbid,uid,loginame,cpu,login_time,open_tran,
Status,hostname,program_name,hostprocess,nt_domain,net_address,
S1=a.spid,s2=0
From Master.. sysprocesses a Join (
Select blocked from master. sysprocesses GROUP by blocked
) b on a.spid=b.blocked where a.blocked=0
UNION ALL
Select ' |_
on the first connection. The application then starts other transactions, issue queries on another connection, and wait for the results. When SQL Server Returns a connection result, the application starts to process the result. The application processes the results in this way until the query of the generated results is blocked by the query executed on another connection, resulting in no available results. At this time, the first connection is blocked
Find the source of SQL Server deadlock and blocking-find the source of SQL Server deadlock and blocking
Copy codeThe Code is as follows:Use masterGoDeclare @ spid int, @ bl intDECLARE s_cur CURSORSelect 0, blockedFrom (select * from sysprocesses where blocked> 0)Where not exists (select * from sysprocesses where blocke
box inside the details, in fact, there are a lot of friends to understand the deadlock after the basic has been understood.1. Every deadlock XML file has a root node: deadlock-list.2, under the root node, there is a node deadlock victim= "process59bcbc8", where the
Deadlock) refers to the state in which processes are permanently blocked. SQL can detect deadlocks and terminate a transaction to intervene in the deadlock State. A typical example of A deadlock between two processes is: Obtain lock A in process T1 and apply for lock B; obtain lock B in process T2 and apply for lock A.
Tags: clean tag exclusive lock nbsp Date started SPI net designationOriginal: SQL Server deadlock troubleshootingRemember the previous customer in the use of software, there are occasional deadlock problems, because the time is uncertain, not good to reproduce the problem, at that time to solve the problem is a bit tricky.Here is a summary of the two common ways
Tags: exe SQL buffer value monitoring database called related permissions heightBackground we monitor the database blocking situation in the database blocking timely email alert alert, in order to better maintain the database, especially to enhance the end customer user experience, we should try to avoid the deadlock in the database situation. We know that collecting deadlocks can turn on trace flags such a
Detailed description of SQL Deadlock Detection Methods, detailed description of SQL lock Detection
The deadlock in SQL server refers to the state in which processes are permanently blocked. The following describes how to detect SQL
, application name =program_name, workstation process id=hostprocess, domain name =nt_domain, nic address =net_address into #t from (SELECT flag = ' deadlock process ', spid, Kpid,a.blocked,dbid,uid,loginame,cpu,login_time,open_tran, Status,hostname,program_name,hostprocess,nt_domain, Net_address, S1=a.spid,s2=0from Master. sysprocesses a join (select blocked Frommaster: sysprocesses GROUP by blocked) B on a.spid=b.blocked where A.blocked=0union all s
SELECT statement in each window attempts to read all the data in the authors table, looking for data similar to the "test%" format in the Au_lname field value. Therefore, the SELECT statements in the two windows will attempt to read the inserted data in their connection-and also read the insertion data from the other connection.
The Read Committed isolation level ensures that the SELECT statement never reads the uncommitted data by publishing the shared lock. For the same resource, the shared
SQL Server Performance Analysis-deadlock detection database blocking statementsWork in the database often appear in memory, found an articleRefer to Csdn, China Wind (Roy) A deadlock article block: One of the transactions is blocked, other transactions wait for the other party to release their locks, and can cause deadlock
/* -- Handle deadlocks
View the current process or deadlock process and automatically kill the dead Process
Because it is intended for dead, if there is a deadlock process, you can only view the deadlock ProcessOf course, you can use Parameter Control to check only the deadlock process, whether there is a
Label:First, a scalar-valued function, Diglock, is used to recursively detect if there is a lock loop for each session in SQL Server, and if the function eventually returns 1, the lock loop is detected (that is, a deadlock is detected), and if the final return of 0 indicates that no lock loop is detected. 1 CREATE FUNCTION [dbo].[Diglock]
2 (
3 @spid int,
4 @orginSpid int
5 )
6 RETURNS bit
7 as
8 B
. sysprocesses a Join (Select blocked from master. sysprocesses GROUP by blocked) b on a.spid=b.blocked where a.blocked=0UNION ALLSelect ' |_ victim _> ',Spid,kpid,blocked,dbid,uid,loginame,cpu,login_time,open_tran,Status,hostname,program_name,hostprocess,nt_domain,net_address,S1=blocked,s2=1From Master. sysprocesses a where blocked) A ORDER by s1,s2Select @[email protected] @rowcount, @i=1If @count =0 and @show_spid_if_nolock =1BeginInsert #tSelect f
1. Create the storage process sp_killlock
Create proc sp_killlock
@ Kill_lock_spid bit = 1, -- whether to kill the deadlock process; 1: Kill; 0: only show
@ Show_spid_if_nolock bit = 1 -- if there is no deadlock in the process, whether the normal process information is displayed, 1 is displayed, 0 is not displayed
As
Declare @ count int, @ s nvarchar (1000), @ I int
Select id = identity (INT, 1,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.