SQL Server First Responder Kit

repository·dev·Indexed 26 days ago

https://github.com/brentozarultd/sql-server-first-responder-kit

A collection of stored procedures for DBAs, sysadmins, and developers to diagnose performance issues, health problems, and configuration errors in Microsoft SQL Server environments. Includes tools such as sp_Blitz for health checks, sp_BlitzCache for resource-intensive query analysis, sp_BlitzFirst for real-time troubleshooting, sp_BlitzIndex for index tuning, and sp_BlitzLock for deadlock analysis. Supports SQL Server on Windows, Linux, Amazon RDS, and Azure SQL DB.

Tokens
27.7K
Snippets
26
Records
79
Agent score
87%

What's inside SQL Server First Responder Kit

  1. Supported Platforms for the First Responder Kit

    dev

    The kit supports the following environments:

    • SQL Server on Windows: All Microsoft-supported versions.
    • SQL Server on Linux: Fully supported, except for sp_DatabaseRestore which requires xp_cmdshell (not provided on Linux).
    • Amazon RDS SQL Server: Fully supported.
    • Azure SQL DB: Partial support. Some procedures work, but others are skipped due to limited access to DMVs or features like SQL Agent and Database Mail. Managed Instance and Amazon RDS are fully supported.

    Note for legacy versions: If using unsupported versions like SQL Server 2008, check the Deprecated folder for older script versions.

  2. Configure Windows page file and memory dumps

    dev

    To ensure proper diagnostic capabilities during a crash or extreme memory pressure, configure the Windows page file according to Microsoft guidelines:

    1. Create a 32GB page file.
    2. Ensure there is space for at least one 32GB memory dump.

    Warning: Do not remove the page file entirely. Windows requires it to write diagnostic information during system crashes.

  3. Install sp_BlitzPlanCompare

    dev

    sp_BlitzPlanCompare is an optional script located in the OptionalScripts folder and is not included in the standard Install-All-Scripts.sql or Install-Azure.sql installers.

    To install it:

    1. Open OptionalScripts/sp_BlitzPlanCompare.sql in SQL Server Management Studio (SSMS).
    2. Switch to the database where you want it installed (typically master to allow calling it from any database via EXEC master.dbo.sp_BlitzPlanCompare).
    3. Run the script.

    Note: For linked-server mode to work, you must install the procedure on both the local and remote servers.

  4. Use sp_BlitzPlanCompare to compare query plans

    dev

    sp_BlitzPlanCompare compares a query plan across two SQL Servers to identify environmental differences (stats, indexes, hardware, etc.) causing performance divergence. It operates in three modes:

    1. Emit (Mode 1): Snapshots the local plan and environment. It returns a CallStack cell containing a ready-to-run EXEC command. Copy this command and run it on the target server.
    2. Compare from XML (Mode 2): Takes an XML snapshot (produced by Mode 1) and compares it against the local plan.
    3. Linked Server (Mode 3): Calls the procedure on a remote server via RPC, shreds the snapshot, and performs the comparison locally. Requires RPC OUT enabled on the linked server and the procedure installed on both sides.

    Typical Copy/Paste Workflow (Most Common)

    1. On the slow server: Run sp_BlitzPlanCompare with a plan identifier (e.g., @QueryPlanHash).
    2. Get the result: Copy the EXEC ... @CompareToXML = N'...' string from the CallStack column.
    3. On the fast server: Paste and execute that string to see the prioritized diff.
    /* Step 1 — on the server where you noticed the slowness */
    EXEC dbo.sp_BlitzPlanCompare @QueryPlanHash = 0xABCD1234567890EF;
  5. Configure SQL Server alerting and Database Mail

    dev

    To enable alerting, you must first configure Database Mail via the wizard. Once configured:

    1. Create Operators in the SQL Server Agent.
    2. In SQL Server Agent properties, enable Database Mail and select the appropriate profile.
    3. Configure a failsafe operator.
    4. Restart the SQL Server Agent Service for changes to take effect.
    5. Use a script to create alerts for high severity and data corruption.
  6. Migrate application logins, Agent jobs, and custom alerts

    dev

    When deploying custom code and settings for an application, ensure the following components are migrated or reconfigured, typically by scripting them from an existing production server:

    • Application logins: Use Microsoft's guidance to transfer logins and passwords between instances to maintain security continuity.
    • SQL Agent jobs: Script these from the existing instance and execute them on the new server.
    • Custom alerts: Script these from the existing instance and execute them on the new server.
    • Orphaned Users: Identify and clean up users that are no longer mapped to a valid login after migration.
  7. Set a Database Constitution for AI context

    dev

    To provide the AI with organizational standards (e.g., naming conventions, query standards), you can set a database-level "constitution" using an extended property named CONSTITUTION.md. This text is automatically included in the AI prompts generated by sp_BlitzCache and sp_BlitzIndex.

    EXECUTE sp_addextendedproperty
        @name = N'CONSTITUTION.md',
        @value = N'## Object Naming Standards
    Views must always be prefixed with vw_.
    Tables should never be prefixed with tbl_.
    
    ## Query Standards
    Queries should prefer CTEs over temp tables.';
  8. Test Network Teaming via VLAN Changes

    dev

    To verify network teaming and resilience:

    1. Remote desktop into the server.
    2. Initiate a large file copy (e.g., a production backup) from one network share to another.
    3. While the copy is running, have a network team member change the VLAN for one of the switch ports. This simulates a network path failure without physically disabling the port.
    4. Success Criteria: The Remote Desktop connection must remain active and the file copy must continue (pauses are acceptable, but errors are not).
  9. Configure and test CLR components

    dev

    If your databases utilize Common Language Runtime (CLR) components, you must plan for their configuration and smoke testing post-migration.

    To enable CLR components in SQL Server, use the appropriate configuration commands. Note that depending on whether the assembly is signed by a certificate or requires UNSAFE or EXTERNAL_ACCESS permissions, you may need to perform additional steps such as:

    • Creating certificates.
    • Setting the database TRUSTWORTHY property.
    • Changing the owner of the database.

    Best Practice: Always test CLR assembly functionality on a restored copy of the database prior to performing the actual migration.

  10. Configure iSCSI Pathing and Multipathing

    dev

    For iSCSI storage, avoid relying on a single network connection:

    1. Redundancy: Use at least two dedicated network cards connected to two different switches.
    2. Multipathing Modes:
      • Active/Active: Provides combined throughput (e.g., 20 Gbps using two 10 Gbps NICs).
      • Active/Passive: Often seen on a per-array basis where different drive letters are mapped to different NICs.
    3. Testing:
      • Performance: Start simultaneous drive copies and monitor the Network tab in Task Manager. If a NIC is idle, the multipathing configuration needs tuning.
      • Failover: Start simultaneous file copies and down one storage network port. The file copy must not fail or throw Windows errors.
  11. Log sp_kill results to a persistent table

    dev
    To maintain a history of what was killed and why, you can pass @OutputDatabaseName, @OutputSchemaName, and @OutputTableName to sp_kill. The procedure will automatically create the table if it does not exist and append new rows to it. The log includes the executor, timestamp, parameters used, running sessions, killed sessions, and any errors.
  12. Use AI modes in sp_BlitzCache and sp_BlitzIndex

    dev

    The First Responder Kit supports two AI modes via the @AI parameter to assist with query tuning and index advice:

    • @AI = 2: Generates a pre-built AI prompt containing query text, execution plans, and performance metrics. This prompt is returned in an AI Prompt column, allowing you to manually copy and paste it into tools like ChatGPT, Gemini, or Claude. This mode works on all supported SQL Server and Azure SQL DB versions and requires no configuration.
    • @AI = 1: Performs the same actions as @AI = 2 but also makes a direct API call to an AI provider (OpenAI or Google Gemini) from within SQL Server, returning the advice directly in the result set. This mode requires SQL Server 2025 or Azure SQL DB and uses sp_invoke_external_rest_endpoint.