SqlServer 查看死锁的进程以及处理

SqlServer 查看死锁的进程以及处理

在进程中的头阻塞显示了1,说明有死锁。

SqlServer 查看死锁的进程以及处理

查看当前死锁

1 SELECT
2     request_session_id spid,
3     OBJECT_NAME(
4         resource_associated_entity_id
5     ) tableName
6 FROM
7     sys.dm_tran_locks
8 WHERE
9     resource_type = OBJECT

查看死锁信息

1 exec master.dbo.sp_who_lock;--查看当前死锁进程
2 exec master.dbo.p_killspid ytsafety;--杀掉引起死锁的进程

查看进程信息

 1 SELECT * FROM sys.dm_exec_connections;
 2 SELECT * FROM sys.dm_exec_sessions;
 3 SELECT
 4     spid,
 5     blocked,
 6     DB_NAME(sp.dbid) AS DBName,
 7     program_name,
 8     waitresource,
 9     lastwaittype,
10     sp.loginame,
11     sp.hostname,
12     a.[Text] AS [TextData],
13     SUBSTRING (
14         A. TEXT,
15         sp.stmt_start / 2,
16         (
17             CASE WHEN sp.stmt_end = - 1 THEN DATALENGTH (A. TEXT) ELSE sp.stmt_end END - sp.stmt_start
18         ) / 2
19     ) AS [current_cmd] FROM sys.sysprocesses AS sp OUTER APPLY sys.dm_exec_sql_text (sp.sql_handle) AS A WHERE spid > 50 ORDER BY blocked DESC,
20     DB_NAME(sp.dbid) ASC,
21     a.[text];

杀掉死锁进程

1 kill spid

 

 

 

 

 

感谢原文:https://blog.csdn.net/lz6363/article/details/84795712

SqlServer 查看死锁的进程以及处理

上一篇:08 学生课程分数的Spark SQL分析


下一篇:.net5 配置提供程序包 WeTools.SqlSugarMysqlConfigProvider,使用sqlsugar读取mysql数据库