SQL Swiss Army Knife #11 - Locking, blocking and active transactions - Updated

Blog do Ezequiel
Portuguese PFE SQL Server Team


Latest Updates
17/05/2012 - Latest update on the AdaptiveIndexDefrag procedure v1.4.1. Look for it in the "Ezequiel shortcuts" section on the right or just click HERE.

SQL Swiss Army Knife #11 - Locking, blocking and active transactions - Updated

Rate This
  • Comments 2

Hello all,
Here is another post on SQL scripts that may help DBAs, following the series "SQL Swiss Army Knife". I’ve been using and tweaking this script for years now, and I’ve been asked to share it several times, because I can get a quick overview of query execution on a given SQL Server instance. The script leverages on some known DMVs (sys.dm_exec_requests, sys.dm_exec_sql_text, sys.dm_exec_sessions and sys.dm_tran_locks) to report on all running requests, waiter and blocking, SP execution statistics, and list sessions that have been granted locks or waiting for locks.

The output will look something like below, and you can get further detail on statements and plans by clicking on the XML links:

image

 

On the Waiter and Blocking Report section, you can look into the queries that are blocking or blocked in further detail, by clicking on the XML link, like this:

image

 

Also, just for SQL Server 2012, you can get some details on Stored Procedures statistics, like below:

image

 

And finally, a list of sessions that have been granted locks or waiting for locks:

image

 

Hope you find it useful.

EDIT (08-04-2012): Added more useful information to output, plus revised for SQL 2012 compatibility.

    
Until next time!

Disclaimer: I hope that the information on these pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Ezequiel. Further, Ezequiel shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

Social Media Sharing
|
Leave a Comment
  • Please add 8 and 5 and type the answer here:
  • Post
  • I think that in the third script

    WHEN 'DATABASE' THEN db_name(resource_database_id)

    it's more useful.

  • Sorry about the long delay Gustavo. Didn't notice you had replied. Well, modified it as it fits your needs! :-)

    Cheers!

Page 1 of 1 (2 items)