30.06.2013 Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Who is running what, right now?<br />

Chapter 2: Connections, Sessions and Requests<br />

Listing 2.17 makes use of sys.dm_exec_requests and sys.dm_exec_sql_text,<br />

alongside our connections and sessions DMVs to provide a very useful "first look" at<br />

which sessions are running what on a given instance.<br />

-- Who is running what at this instant<br />

SELECT dest.text AS [Command text] ,<br />

des.login_time ,<br />

des.[host_name] ,<br />

des.[program_name] ,<br />

der.session_id ,<br />

dec.client_net_address ,<br />

der.status ,<br />

der.command ,<br />

DB_NAME(der.database_id) AS DatabaseName<br />

FROM sys.dm_exec_requests der<br />

INNER JOIN sys.dm_exec_connections dec<br />

ON der.session_id = dec.session_id<br />

INNER JOIN sys.dm_exec_sessions des<br />

ON des.session_id = der.session_id<br />

CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS dest<br />

WHERE des.is_user_process = 1<br />

Listing 2.17: Who is running what?<br />

A better version of sp_who2<br />

Many of us DBAs are familiar <strong>with</strong> the sp_who and sp_who2 system stored procedures<br />

for interrogating <strong>SQL</strong> <strong>Server</strong> activity. Listing 2.18 provides the syntax, and sample results,<br />

from an execution of sp_who.<br />

67

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!