Home » PSBlitz – Easily outputs SQL Server diagnostics data

PSBlitz – Easily outputs SQL Server diagnostics data

by Vlad Drumea
10 comments

PSBlitz is a PowerShell script that outputs SQL Server health and performance diagnostics data to Excel and saves execution plans and deadlock graphs as .sqlplan and .xdl files.

Introduction

Since I’m a big fan of Brent Ozar’s SQL Server First Responder Kit, and I’ve found myself in many situations where I would have liked a quick way to easily export to Excel the output of sp_Blitz, sp_BlitzCache, sp_BlitzFirst, sp_BlitzIndex, sp_BlitzLock, and sp_BlitzWho, as well as saving to disk the execution plans identified by sp_BlitzCache and sp_BlitzWho together with deadlock graphs from sp_BlitzLock, I’ve decided to put together a PowerShell script that does just that.

The script itself relies on slightly modified versions of Brent’s stored procedures in order to make them portable (they’re no longer stored procedures, just stand-alone scripts)

Features

Outputs the following to an Excel spreadsheet:

  • Wait stats – from sp_BlitzFirst
  • Currently running queries – from sp_BlitzWho
  • Instance health-related findings – from sp_Blitz
  • Index-related issues and recommendations – from sp_BlitzIndex
  • Top 10 most resource intensive queries – from sp_BlitzCache
  • Deadlock related information from the past 15 days – from sp_BlitzLock
  • Statistics details for a given database – when a database-specific check is requested
  • Index Fragmentation information for a given database – when a database-specific check is requested

sp_BlitzWho is called multiple times during the execution of PSBlitz in order to help get a better sense of what’s actively hitting the instance.

Exports the following files:

  • Execution plans (as .sqlplan files) – from the same data set generated by sp_BlitzCache
  • Execution plans (as .sqlplan files) – from the sample execution plans provided by sp_BlitzIndex @Mode = 0 and sp_BlitzIndex @Mode = 4 for missing index suggestions (only on SQL Server 2019)
  • Execution plans (as .sqlplan files) of currently running sessions – from the same data set generated by sp_BlitzWho
  • Deadlock graphs (as .xdl files) – from the same data set generated by sp_BlitzLock

By default, PSBlitz does a fast check which runs the following:

PSBlitz can also has in-depth check mode which runs:

If needed, you can run the checks against a specific database either by specifying the name of the database during the interactive execution or via the -CheckDB parameter.
The database-specific check will modify the executions of sp_Blitz, sp_BlitzCache, sp_BlitzIndex, and sp_BlitzLock as follows:

Running PSBlitz

PSBlitz can be ran in two ways:

  • as any PS script, by calling it either from its directory or using its full path, and providing parameters and values
PowerShell window: PS C:\Users\Vlad> G:\PSBlitz\PSBlitz.ps1 LOCALHOST\VSQL19 -CheckDB StackOverflow ->Host LOCALHOST appears to be... up. Proceeding. Testing connection to instance LOCALHOST\VSQL19... ->Connection to LOCALHOST\VSQL19 - Ok Checking existence of database StackOverflow... ->Database StackOverflow - exists/is online
Executing a database-specific default check
  • in interactive mode by right clicking on the script and then clicking on “Run with PowerShell”, which will cause the script to prompt for input
PowerShell window: Running in interactive mode Server: LOCALHOST\VSQL19 ->Host LOCALHOST appears to be... up. Proceeding. Name of the database you want to check (leave empty for all): SQL login name (leave empty to use integrated security): Perform an in-depth check?[Y/N]: Y Testing connection to instance LOCALHOST\VSQL19... ->Connection to LOCALHOST\VSQL19 - Ok
Executing an instance-wide in-depth check in interactive mode

During execution, PSBlitz will tell you at which step it currently is, and, when it finishes, it will tell you where the output is saved and how long the execution took.

PSBlitz outputs SQL Server diagnostics data
PSBlitz execution against a SQL Server instance

Output

When the script finishes you’ll have a folder in the same location as PSBlitz.ps1 containing an Excel file with the all the output generated and two sub-directories, one containing deadlock graphs and the other execution plans.

Output directory generated by PSBlitz
PSBlitz output directory

The excel file consists of multiple sheets, with the first sheet acting as an index for the rest of the report.

The rest of the sheets contain the output of the sp_Blitz scripts that you’re most likely already familiar with. The findings also include clickable hyperlinks that provide more explanations and solutions.

PSBlitz outputs SQL Server diagnostics data
sp_Blitz sheet
PSBlitz outputs SQL Server diagnostics data
sp_BlitzFirst sheet
PSBlitz outputs SQL Server diagnostics data
Wait Stats sheet

How I use it

I use PSBlitz mainly in three situations:

  • an instance is seeing sudden performance degradation that’s impacting overall response times in production, and I want to output as much performance diagnostics data as possible with minimal effort in order to start troubleshooting
  • I want to collect data to work with and also capture the “before” state of an instance when doing general performance tuning
  • I’m monitoring the effects of performance tuning efforts and any other changes that might impact SQL Server’s performance and reliability

Download and more info

For more info and updated versions check out the PSBlitz repository on GitHub.

Any input is welcome, but, since this is a personal project, I’ll address bugs, suggestions, and requests when my schedule allows it.

There is a dev branch, so If you want to make a contribution feel free to make a pull request to it.

You may also like

10 comments

Ademir September 15, 2022 - 17:47

Amazing! Thanks for sharing it! 🙂

Reply
Thomas October 3, 2022 - 22:54

This has saved me so much manual work. Thanks for sharing!

Reply
Antoine October 30, 2022 - 17:37

Thanks for sharing!

Reply
Paul January 3, 2023 - 13:15

How can I set the parameter @BringThePain = 1 when your script launches the sp_BlitzIndex?
thank you!

Reply
Vlad Drumea January 3, 2023 - 13:37

Hi Paul,
At the moment, there’s no direct way of specifying @BringThePain = 1 through PSBlitz, but you can go into ..\PSBlitz\Resources and edit line 47 of spBlitzIndex_NonSPLatest.sql to set @BringThePain = 1 and then it will be used at the next run of PSBlitz.

If this is something you or anyone from the SQL Server community might need to do more often, I will work on a way to pass it as a custom parameter value when executing PSBlitz.

Reply
Thien Nguyen March 22, 2023 - 17:36

Not sure what I did wrong but when I executed the Powershell
.\psblitzl.ps1 wsfpv02342\mstqip05 -checkdb hgxcore

I got the following message
“script execution was interupted.
Finishing Up….”
and the exel spreadsheet doesn’t have any data.
What I didn’t wrong and how to address it?
Thank you Vlad

Reply
Vlad Drumea April 25, 2023 - 18:45

Sorry for the late reply.
I took a break from the blog for a couple of months.
Can you please get the latest version of PSBlitz and try running it with the -DebugInfo flag?
When it finishes and prompts for you to press Enter, do so, but do not close the PS window. In most cases, the error will be thrown right after the script exits.
By our description alone, I’d estimate that the failure occurs right during the first or second script that is executed, so either GetInstanceInfo.sql or GetTempDBUsageInfo.sql (they’re both in the Resources directory)
You can test this by just running them from SSMS against your instance and seeing if they error out in any way.

Again, sorry for the late reply.

Reply
BrankoH June 9, 2023 - 20:25

Thanks for sharing it! 🙂

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.