Sqlserver 2005+:【当前】【正在运行】的【进程会话的请求信息】
set nocount on set transaction isolation level read uncommitted ;with cte as ( select t.session_id as spid,t.status,t.blocking_session_id as blocked ,t.program_name ,str(1.0* t.total_elapsed_time/1000,16,0) as duration_s ,str(1.0*(t.cpu_time+t.wait_time)/1000,16,0) as inter_duration_s ,str(1.0*(t.cpu_time)/1000,16,0) as cpu_time_s ,str(1.0*(t.wait_time)/1000,16,0) as wait_time_s ,t.granted_query_memory*8/1024 as mb,t.logical_reads,t.reads,t.writes ,t.start_time,t.login_time ,t.command,t.wait_type,t.wait_resource,s.text from ( select b.session_id,b.status,a.blocking_session_id,b.program_name ,a.command,a.sql_handle ,a.cpu_time,a.wait_time,a.total_elapsed_time,a.granted_query_memory ,a.start_time,b.login_time ,a.logical_reads,a.reads,a.writes ,a.wait_type,a.wait_resource from sys.dm_exec_requests a inner join sys.dm_exec_sessions b on b.session_id=a.session_id where b.program_name is not null and b.session_id <> @@spid ) t cross apply sys.dm_exec_sql_text(t.sql_handle) s ) select (case when exists(select * from cte b where b.spid=a.spid and b.blocked=0 and (a.spid in (select blocked from cte c))) then 'yes' else '' end) as is_blocker ,* from cte a where (blocked>0) or (spid in (select blocked from cte)) or duration_s>5 order by blocked,program_name,spid /* select spid,program_name,blocked,open_tran,a.status,str((waittime + cpu)/1000.0,16,0) as duration,waittime,cpu,physical_io,last_batch,a.login_time--,b.text ,a.lastwaittype,a.waitresource from master..sysprocesses a cross apply sys.dm_exec_sql_text (a.sql_handle) b where spid<>@@SPID and spid>50 order by program_name and program_name like '.Net%' */
分类:
Sqlserver
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)