zoukankan      html  css  js  c++  java
  • 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%'
        
    */        
  • 相关阅读:
    项目测试与部署
    使用技术及部分代码截选
    校园电子设备报修回收系统需求分析
    java lambda expression
    Domain logic approaches
    Spring AOP Capabilities ang goals
    CDI Features
    JAVA DESIGN PATTERN
    LDAP & Implementation
    spring ref &history&design philosophy
  • 原文地址:https://www.cnblogs.com/jinzhenshui/p/2779281.html
Copyright © 2011-2022 走看看