Wednesday, November 27, 2013

Quick check : What is running on my server at the moment

You can quickly run SP_Who2 to see what is running on your server at the moment. Of course it will give you  current transactions and pending (currently processing) transactions also called as open transactions.

If you use SP_Who2 Active, you will just get Current transactions.

Apart from these commands you can get interesting information with dmv's, introduced in sql 2005 and also applicable for later versions of 2005.

DECLARE @TimeStamp DATETIME
SET @TimeStamp = DATEADD(MINUTE,-10,getdate())  -- You can pass your own string here

SELECT login_time
        ,last_request_start_time
        ,last_request_end_time
        ,DATEDIFF(millisecond,last_request_start_time,last_request_end_time) AS 'Milli'  -- Dynamic column
        ,host_name
        ,PROGRAM_NAME
        ,host_process_id
        ,client_interface_name
        ,login_name
        ,nt_user_name
        ,total_scheduled_time
        ,total_elapsed_time
        ,reads
        ,writes
        ,logical_reads
        ,original_login_name
    FROM sys.dm_exec_sessions WHERE
    last_request_end_time > @timeStamp
    ORDER BY login_time

No comments:

Post a Comment