数据库
首页 > 数据库> > SQL 系统进程的运行(status)状态(Runnable、Running、Suspended、Sleeping、Pending、Dormant、Background、Spinlock)

SQL 系统进程的运行(status)状态(Runnable、Running、Suspended、Sleeping、Pending、Dormant、Background、Spinlock)

作者:互联网

SQL 系统进程的运行(status)状态(Runnable、Running、Suspended、Sleeping、Pending、Dormant、Background、Spinlock)

1、状态(status)解释

2、查看的几种方式:

//1
SELECT * FROM sys.sysprocesses;
//2
EXEC sp_who2;
//3
SELECT sqltext.TEXT, req.session_id, req.status, req.command, req.cpu_time, req.blocking_session_id, req.total_elapsed_time 
FROM sys.dm_exec_requests req (NOLOCK)
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext

3、sys.sysprocesses 主要字段解释

4、检查死锁进程的方式

//方式1
declare @spid int,@bl int  
DECLARE s_cur CURSOR FOR   select  0 ,blocked   from (select * from sys.sysprocesses where  blocked>0 ) a  
where not exists(select * from (select * from sys.sysprocesses where  blocked>0 ) b   where a.blocked=spid)   
union 
select spid,blocked from sys.sysprocesses where  blocked>0   OPEN s_cur   FETCH NEXT FROM s_cur INTO @spid,@bl   WHILE @@FETCH_STATUS = 0  
begin   if @spid =0             
select ' 引起数据库死锁的是: '+ CAST(@bl AS VARCHAR(10)) + ' 进程号, 其执行的SQL 语法如下'   else              
select ' 进程号SPID :'+ CAST(@spid AS VARCHAR(10))+ ' 被' + ' 进程号SPID :'+ CAST(@bl AS VARCHAR(10)) +' 阻塞, 其当前进程执行的SQL 语法如下' 
DBCC INPUTBUFFER (@bl )   FETCH NEXT FROM s_cur INTO @spid,@bl   end   CLOSE s_cur  
DEALLOCATE s_cur

//方式2
use master
go
--检索死锁进程
select spid, blocked, loginame, last_batch, status, cmd, hostname, program_name
from sysprocesses
where spid in
( select blocked from sysprocesses where blocked <> 0 ) or (blocked <>0)

参考死锁的解决方式:链接  

  

 

 

创建时间:2022.02.15  更新时间:

 

标签:status,Runnable,spid,process,Background,进程,等待,select,blocked
来源: https://www.cnblogs.com/guorongtao/p/15894977.html