Hello everybody!
How are you?
In today's post, I will show you how to return active SQL Server sessions, showing CPU usage, read and write quantity, which user is performing the query, what is being performed by this session, which software is used , what is the hostname, and a lot of other session and query information. For those who already know sp_WhoIsActive (If you don't know, learn more accessing this post), you will notice that they have a very similar return, and that was the purpose of the query itself.
Several times, I've had slow issues running sp_WhoIsActive in environments with high processing and disk containment and / or TempDB, causing the SP return to take several seconds, even a few minutes, as this SP is very busy. using TempDB to return results as it currently returns.
In order to provide a similar but lightweight solution that does not use TempDB, allowing it to run quickly even in scenarios like the one above, me and Tiago Neves we created this more "lean" version, returning the main information and without using the various parameters that the original SP provides us.
What is the difference for sp_WhoIsActive?
- Does not use TempDB
- Faster execution
- Simpler code to understand
- It can be easily used as a view, table-valued function or scalar function, allowing you to use order by, select into, where, etc.
- In addition to showing the running query, it also shows the Outer Command (sp_WhoIsActive also shows if @get_outer_command = 1 is used)
- If the session is from a job, shows the job name in the program_name column
- Returns the execution plan XML (sp_WhoIsActive also shows if the @get_plans = 1 parameter is used)
Source code for “sp_Tiny_WhoIsActive”
With the source code below, you can return information from running sessions with just 1 SELECT, and you can even create a view to make future queries easier.
View source (Full version - SQL Server 2012 +)If you want an even lighter and faster version, I've removed some features (such as execution plan XML view, lock session count, etc.) and made the code below available:
View source (Faster version with few features less)As you may have noticed, I use the FORMAT function, available from SQL Server 2012. If you are in an earlier version, running the code below will generate an error for you. Just remove this function to be able to use the query normally (The numbers just won't have the thousand separators, but that's even good for sorting), or use the version below:
View source (SQL Server 2008 and earlier)Query Execution Result
That's it folks!
If you have any suggestions or improvements, feel free to let me know in the comments or submit your change on the link. https://github.com/dirceuresende/tiny-sp_whoisactive.
Hope you enjoyed, a hug and see you next time!
sql server lightweight tiny sp_whoisactive identify query session running lighter without consuming tempdb low consumption
sql server lightweight tiny sp_whoisactive identify query session running lighter without consuming tempdb low consumption
Note 10 Dirceu. Thank you!