Back in October of 2005 (in the long long ago) Microsoft released to market SQL Server 2005. Since this release Microsoft provided DBA’s detailed insight into the server state via dynamic management views (DMV).
In the beginning I did not fully embrace the DMV’s and changes made by Microsoft. In all honesty it was not until the past 3 or 4 years that I started embracing them. Maybe it was part of my natural progression of learning as well as part of my path to becoming a more knowledgeable DBA. I think it is safe to say that each and everyday a good portion of us are learning new uses or even new DMV’s to help resolve issues on our database servers.
One of my all time favorite system tables was sysprocesses. With the release of SQL Server 2005 Microsoft created 3 new DMV’s which have been maintained in all versions of SQL Server since 2005. Dynamic management views sys.dm_exec_connections, sys.dm_exec_sessions, and sys.dm_exec_requests where mapped to the sys.sysprocesses system view. I kicked, I screamed and I resisted these DMV’s convinced that sysprocesses provided me with everything I needed to understand about the connections within my database instance. Yikes! I was so wrong.
A little over 4 weeks ago I was at a shop that had over 2052 + instances of SQL Server 2000. Approximately 75 percent of the environment was SQL Server 2000. We DBA’s at the shop were more likely required to trouble shoot an instance that was SQL Server 2000 requiring the use of sysprocesses since DMV’s were not yet available. I needed to push myself to grab hold of and utilize the server-scope views since my daily routine did not require them. My advice to any of you hold outs is move forward you are being left behind and as difficult as it may seem these server-scope views are our future.
Here are a couple of recommendations and explanations for the views which map back to old faithful sysprocesses. I think at this point it is important to point out that sysprocesses is no longer a system table it has been changed to a system view.
The 1st DMV I always utilize when examining sessions connected to a database instance is sys.dm_exec_sessions. This server-scope view provides us one row per authenticated session and shows information about all active user connections and internal tasks. When returning result sets from sys.dm_exec_sessions I like to look at session_id, Login_time, host_name, program_name, status, transaction_isolation_level and last_request_end_time. There are many other columns that can be returned and are fully documented by Microsoft. You can find detailed documentation about sys.dm_exec_sessions following the provided Microsoft link.
The second DMV I utilize when examining sessions connected to a database instance is sys.dm_exec_requests . This sever-scope view provides us one row for each request executing within a SQL Server Instance. When returning result sets from sys.dm_exec_requests I typically look at session_id, start_time, status, command, sql_handle, plan_handle, blocking_session_id, wait_type and wait_time. There are many other helpful columns that can be included in your result set such as percent_complete (very cool for backups/restores) and reads & writes. You can find detailed documentation about sys.dm_exec_requests following the provided Microsoft link.
The third DMV I utilize when examining sessions connected to a database instance is sys.dm_exec_connections. DMV sys.dm_exec_connections provides us with server-level information about the connections in SQL Server. When returning result sets from sys.dm_exec_connections I typically pull back session_id, connect_time, auth_scheme, client_net_address and client_tcp_port. When we were having Kerberos issues with SSRS we utilized sys.dm_exec_connections in order to identify the SQL Server Authentication scheme being used by our reporting system. You can find detailed documentation about sys.dm_exec_connections following the provided Microsoft link.
I am convinced that once you make the leap into utilizing these DMV’s you will not look back. You can find all the information sysprocesses provided you with some added bonuses. Once you become familiar with sys.dm_exec_connections, sys.dm_exec_sessions, and sys.dm_exec_requests individually have fun writing queries joining them together. Also as of April 2013 we should all see a dramatic drop in the number of SQL Server 2000 database instances we support since it is officially no longer supported by Microsoft. SQL Server 2000 instances will still exist, but the ratio should change dramatically in our favor to SQL Server instances that have DMV’s providing us more detailed information into our server state.
Thank You Flogging Molly for providing blogging inspiration.