I am a big fan of Adam Machanic’sWhoIsActive script, and when customers have issues with performance, it’s one of the first tools I recommend because it’s so simple to use and provides great information. Very often it helps with quickly determining an issue, but sometimes there’s a need to capture more information, particularly when locking and blocking is part of the issue. Adam’s script has an option to include blocking information, for example including the [blocking_session_id] column in the output and using @find_block_leaders = 1as an parameter. But sometimes you need more information, like the blocked process report. I’ve found one of the easiest ways to get that in SQL Server 2012 and higher is Extended Events. If you’re running SQL Server 2005 and higher, you can use Event Notifications to capture the blocked process report. This option is nice because you are notified when the problem occurs. For those of you using SQL Server 2008R2 and below, you also have the option of capturing the blocked process report event through a server-side Trace. But if you’re on SQL Server 2012 and higher, you can use Extended Events and the blocked process report. Note: the blocked_process_report event does not exist in SQL Server 2008 or SQL Server 2008R2, which is why Trace is the method there. The drawback to Extended Events is that you don’t get a notification that blocking occurred, but for those who are not as comfortable with Event Notifications – for whatever reason – Extended Events is a very simple alternative.

The Setup

In order to capture a blocked process report, you must have the blocked process threshold system configuration option enabled. A good starting value is 15, which is the threshold in seconds at which the report is generated. To set this value, run the following code:

The following code will create the event session and then start it. Note that you can create the event session and just have it defined in your system without running it. Then, if you start to have blocking you can set the blocked process threshold and start the event session.

To view the output from extended events you can open the .xel file in Management Studio or query the data using the sys.fn_xe_file_target_read_file function. I typically prefer the UI, but there’s currently no great way to copy the blocking report text and view it in the format you’re used to. But if you use the function to read and parse the XML from the file, you can…

Depending on how long you let the blocking continue, you may have captured more than one event and therefore have multiple reports in the output:

Retrieving the blocked process report

You can click on the output for any row to see the blocked process in XML format, and then work through the blocking:

The blocked process report

[Huge thanks to Jonathan for help with the XML. I don’t think XML and I will ever be friends. Geez.]

Summary

If you’re in need of the blocked process report and running SQL Server 2012, you now have another option for getting that information. If you’re still new to extended events, check out the first two stairways in my XE series on SQLServerCentral