Home

Awesome

SQL Server First Responder Kit

<a name="header1"></a> licence badge stars badge forks badge issues badge contributors_badge

Navigation

You're a DBA, sysadmin, or developer who manages Microsoft SQL Servers. It's your fault if they're down or slow. These tools help you understand what's going on in your server.

To install, download the latest release ZIP, then run the SQL files in the master database. (You can use other databases if you prefer.)

The First Responder Kit runs on:

If you're stuck with versions of SQL Server that Microsoft no longer supports, like SQL Server 2008, check the Deprecated folder for older versions of the scripts which may work, depending on your versions and compatibility levels.

How to Install the Scripts

For SQL Server, to install all of the scripts at once, open Install-All-Scripts.sql in SSMS or Azure Data Studio, switch to the database where you want to install the procs, and run it. It will install the stored procedures if they don't already exist, or update them to the current version if they do exist.

For Azure SQL DB, use Install-Azure.sql, which will only install the procs that are compatible with Azure SQL DB.

If you hit an error when running Install-All-Scripts, it's likely because you're using an older version of SQL Server that Microsoft no longer supports. In that case, check out the Deprecated folder. That's where we keep old versions of the scripts around as a last-ditch effort - but really, if Microsoft won't support their own old stuff, you shouldn't try to do it either.

We recommend installing these stored procedures in the master database, but if you want to use another one, that's totally fine - they're all supported in any database - but just be aware that you can run into problems if you have these procs in multiple databases. You may not keep them all up to date, and you may hit an issue when you're running an older version.

There are a couple of Install-Core scripts included for legacy purposes, for folks with installers they've built. You can ignore those.

How to Get Support

Everyone here is expected to abide by the Contributor Covenant Code of Conduct.

When you have questions about how the tools work, talk with the community in the #FirstResponderKit Slack channel. If you need a free invite, hit SQLslack.com. Be patient - it's staffed with volunteers who have day jobs, heh.

When you find a bug or want something changed, read the contributing.md file.

When you have a question about what the scripts found, first make sure you read the "More Details" URL for any warning you find. We put a lot of work into documentation, and we wouldn't want someone to yell at you to go read the fine manual. After that, when you've still got questions about how something works in SQL Server, post a question at DBA.StackExchange.com and the community (that includes us!) will help. Include exact errors and any applicable screenshots, your SQL Server version number (including the build #), and the version of the tool you're working with.

Back to top

sp_Blitz: Overall Health Check

Run sp_Blitz daily or weekly for an overall health check. Just run it from SQL Server Management Studio, and you'll get a prioritized list of issues on your server right now.

Output columns include:

Commonly used parameters:

Advanced tips:

Back to top

Advanced sp_Blitz Parameters

In addition to the parameters common to many of the stored procedures, here are the ones specific to sp_Blitz:

Back to top

Writing sp_Blitz Output to a Table

EXEC sp_Blitz @OutputDatabaseName = 'DBAtools', @OutputSchemaName = 'dbo', @OutputTableName = 'BlitzResults';

Checks for the existence of a table DBAtools.dbo.BlitzResults, creates it if necessary, then adds the output of sp_Blitz into this table. This table is designed to support multiple outputs from multiple servers, so you can track your server's configuration history over time.

Back to top

Skipping Checks or Databases

CREATE TABLE dbo.BlitzChecksToSkip (
    ServerName NVARCHAR(128),
    DatabaseName NVARCHAR(128),
    CheckID INT
);
GO
INSERT INTO dbo.BlitzChecksToSkip (ServerName, DatabaseName, CheckID)
VALUES (NULL, 'SalesDB', 50)
sp_Blitz @SkipChecksDatabase = 'DBAtools', @SkipChecksSchema = 'dbo', @SkipChecksTable = 'BlitzChecksToSkip';

Checks for the existence of a table named Fred - just kidding, named DBAtools.dbo.BlitzChecksToSkip. The table needs at least the columns shown above (ServerName, DatabaseName, and CheckID). For each row:

Back to top

sp_BlitzCache: Find the Most Resource-Intensive Queries

sp_BlitzCache looks at your plan cache where SQL Server keeps track of which queries have run recently, and how much impact they've had on the server.

By default, it includes two result sets:

Output columns include:

Common sp_BlitzCache Parameters

The @SortOrder parameter lets you pick which top 10 queries you want to examine:

Other common parameters include:

Back to top

Advanced sp_BlitzCache Parameters

In addition to the parameters common to many of the stored procedures, here are the ones specific to sp_BlitzCache:

sp_BlitzCache Known Issues

Back to top

sp_BlitzFirst: Real-Time Performance Advice

When performance emergencies strike, this should be the first stored proc in the kit you run.

It takes a sample from a bunch of DMVs (wait stats, Perfmon counters, plan cache), waits 5 seconds, and then takes another sample. It examines the differences between the samples, and then gives you a prioritized list of things that might be causing performance issues right now. Examples include:

If no problems are found, it'll tell you that too. That's one of our favorite features because you can have your help desk team run sp_BlitzFirst and read the output to you over the phone. If no problems are found, you can keep right on drinking at the bar. (Ha! Just kidding, you'll still have to close out your tab, but at least you'll feel better about finishing that drink rather than trying to sober up.)

Common sp_BlitzFirst parameters include:

Logging sp_BlitzFirst to Tables

You can log sp_BlitzFirst performance data to tables by scheduling an Agent job to run sp_BlitzFirst every 15 minutes with these parameters populated:

All of the above OutputTableName parameters are optional: if you don't want to collect all of the stats, you don't have to. Keep in mind that the sp_BlitzCache results will get large, fast, because each execution plan is megabytes in size.

Logging Performance Tuning Activities

You can also log your own activities like tuning queries, adding indexes, or changing configuration settings. To do it, run sp_BlitzFirst with these parameters:

Optionally, you can also pass in:

Back to top

sp_BlitzIndex: Tune Your Indexes

SQL Server tracks your indexes: how big they are, how often they change, whether they're used to make queries go faster, and which indexes you should consider adding. The results columns are fairly self-explanatory.

By default, sp_BlitzIndex analyzes the indexes of the database you're in (your current context.)

Common parameters include:

sp_BlitzIndex focuses on mainstream index types. Other index types have varying amounts of support:

Back to top

Advanced sp_BlitzIndex Parameters

In addition to the parameters common to many of the stored procedures, here are the ones specific to sp_BlitzIndex:

Back to top

sp_BlitzLock: Deadlock Analysis

Checks either the System Health session or a specific Extended Event session that captures deadlocks and parses out all the XML for you.

Parameters you can use:

Known issues:

Back to top

sp_BlitzWho: What Queries are Running Now

This is like sp_who, except it goes into way, way, way more details.

It's designed for query tuners, so it includes things like memory grants, degrees of parallelism, and execution plans.

Back to top

sp_BlitzAnalysis: Query sp_BlitzFirst output tables

Retrieves data from the output tables where you are storing your sp_BlitzFirst output.

Parameters include:

Example calls:

Get information for the last hour from all sp_BlitzFirst output tables

EXEC sp_BlitzAnalysis 
	@StartDate = NULL,
	@EndDate = NULL,
	@OutputDatabaseName = 'DBAtools',
	@OutputSchemaName = 'dbo',
	@OutputTableNameFileStats = N'BlitzFirst_FileStats',		
	@OutputTableNamePerfmonStats  = N'BlitzFirst_PerfmonStats',		
	@OutputTableNameWaitStats = N'BlitzFirst_WaitStats',		 
	@OutputTableNameBlitzCache = N'BlitzCache',		 
	@OutputTableNameBlitzWho = N'BlitzWho';

Exclude specific tables e.g lets exclude PerfmonStats by setting to NULL, no lookup will occur against the table and a skipped message will appear in the resultset

EXEC sp_BlitzAnalysis 
	@StartDate = NULL,
	@EndDate = NULL,
	@OutputDatabaseName = 'DBAtools',
	@OutputSchemaName = 'Blitz',
	@OutputTableNameFileStats = N'BlitzFirst_FileStats',		
	@OutputTableNamePerfmonStats  = NULL,		
	@OutputTableNameWaitStats = N'BlitzFirst_WaitStats',		 
	@OutputTableNameBlitzCache = N'BlitzCache',		 
	@OutputTableNameBlitzWho = N'BlitzWho';

Known issues: We are likely to be hitting some big tables here and some of these queries will require scans of the clustered indexes as there are no nonclustered indexes to cover the queries by default, keep this in mind if you are planning on running this in a production environment!

I have noticed that the Perfmon query can ask for a big memory grant so be mindful when including this table with large volumes of data:

SELECT 
      [ServerName]
    , [CheckDate]
    , [counter_name]
    , [object_name]
    , [instance_name]
    , [cntr_value]
FROM [dbo].[BlitzFirst_PerfmonStats_Actuals]
WHERE CheckDate BETWEEN @FromDate AND @ToDate
ORDER BY 
      [CheckDate] ASC
    , [counter_name] ASC;

Back to top

sp_BlitzBackups: How Much Data Could You Lose

Checks your backups and reports estimated RPO and RTO based on historical data in msdb, or a centralized location for [msdb].dbo.backupset.

Parameters include:

An example run of sp_BlitzBackups to push data looks like this:

EXEC sp_BlitzBackups @PushBackupHistoryToListener = 1, -- Turn it on!
                     @WriteBackupsToListenerName = 'AG_LISTENER_NAME', -- Name of AG Listener and Linked Server 
                     @WriteBackupsToDatabaseName = 'FAKE_MSDB_NAME',  -- Fake MSDB name you want to push to. Remember, can't be real MSDB.
                     @WriteBackupsLastHours = -24 -- Hours back in time you want to go

In an effort to not clog your servers up, we've taken some care in batching things as we move data. Inspired by Michael J. Swart's Take Care When Scripting Batches, we only move data in 10 minute intervals.

The reason behind that is, if you have 500 databases, and you're taking log backups every minute, you can have a lot of data to move. A 5000 row batch should move pretty quickly.

Back to top

sp_DatabaseRestore: Easier Multi-File Restores

If you use Ola Hallengren's backup scripts, DatabaseRestore.sql helps you rapidly restore a database to the most recent point in time.

Parameters include:

For information about how this works, see Tara Kizer's white paper on Log Shipping 2.0 with Google Compute Engine.

Back to top

Parameters Common to Many of the Stored Procedures

To check versions of any of the stored procedures, use their output parameters for Version and VersionDate like this:

DECLARE @VersionOutput VARCHAR(30), @VersionDateOutput DATETIME;
EXEC sp_Blitz 
    @Version = @VersionOutput OUTPUT, 
    @VersionDate = @VersionDateOutput OUTPUT,
    @VersionCheckMode = 1;
SELECT
    @VersionOutput AS Version, 
    @VersionDateOutput AS VersionDate;

Back to top

License

The SQL Server First Responder Kit uses the MIT License.

Back to top