⭐ DBA Scripts – SQL Server Toolkit

A production‑ready DBA toolkit for SQL Server operations, diagnostics, automation, and operational review.

GitHub Repository: 🔗 https://github.com/peterwhyte-lgtm/dba-scripts


📘 Overview

This repository is built as a real production DBA toolkit, not a loose script dump. It provides a structured, enterprise‑ready library of:

  • SQL diagnostics and DMV investigations
  • PowerShell automation and orchestration
  • Hybrid helpers for repeatable workflows, CSV output, and repo runners

The repo is designed to support the DBA Scripts section of this site and give SQL Server DBAs a fast, copy/paste‑friendly toolkit for daily troubleshooting and operational checks.


📁 Repository Structure

SQL Layer (sql/)

Purpose‑built for SSMS and Azure Data Studio.

  • performance/ — waits, blocking, long‑running queries, missing indexes, I/O analysis
  • backups/ — backup coverage, restore prep, DR readiness
  • monitoring/ — health, memory, MAXDOP, jobs, AG, environment snapshots
  • security/ — permission and access reviews
  • migration/ — logins, jobs, linked servers, inventory
  • sql-templates/operations/ — production runbook templates (stats, CDC, TDE, upgrades)

PowerShell Layer (powershell/)

Automation, orchestration, and local execution.

  • inventory/ — storage, growth, instance inventory, disk analysis
  • backup-automation/ — backup/restore automation helpers
  • reporting/ — waits, blocking, index reporting
  • health-checks/ — database health and TempDB checks

Hybrid Layer (helpers/, tools/, examples/)

Lightweight helpers that glue the repo together.

  • helpers/triage/ — repo inventory, script discovery
  • helpers/local-sql/ — connectivity tests, SQL execution
  • helpers/maintenance/ — cleanup and repo hygiene
  • tools/ — repo maintenance utilities
  • examples/ — sample workflows and usage patterns

🚀 Start Here

If you want the fastest path into the repo:

1. Get the repo overview

.\helpers\triage\Show-RepoOverview.ps1

2. Pick the matching script

  • SQL task → use sql/
  • Automation task → use powershell/

3. Validate SQL connectivity

.\helpers\local-sql\Test-SqlConnectivity.ps1 -ServerInstance . -Database master

4. Use production templates

  • sql-templates/operations/ for runbooks and change‑order templates

🧪 Example Commands

.\run.ps1 Get-WaitStatistics
.\run.ps1 Get-LongRunningQueries
.\helpers\Run-Helper.ps1 -ScriptName Get-WaitStatistics
.\helpers\local-sql\Test-SqlConnectivity.ps1 -ServerInstance . -Database master

🎯 What This Repo Optimizes For

  • Fast copy/paste into SSMS or Azure Data Studio
  • Clear category grouping by real DBA tasks
  • Easy handoff to other production DBAs
  • A solid foundation for future blog posts and runbooks
  • A canonical layout that scales as the repo grows

🗺 Category Map at a Glance

SQL

  • Performance: waits, blocking, long‑running queries, missing indexes
  • Backups: coverage, restore prep, DR readiness
  • Monitoring: health, memory, MAXDOP, jobs, AG
  • Security: permissions and access reviews

PowerShell

  • Inventory: storage, growth, instance inventory
  • Backup Automation: backup/restore helpers
  • Reporting: waits, blocking, index reporting
  • Health Checks: DB health, TempDB

Templates

  • Operations: runbook‑style SQL templates for stats, CDC, TDE, upgrades

🛠 How to Use This Repo

  • Start in sql/ for SSMS‑ready analysis scripts
  • Use powershell/ for automation and local troubleshooting
  • Use sql-templates/operations/ for production runbooks
  • Use helpers/triage/ for repo discovery
  • Use helpers/local-sql/ for SQL connectivity and execution
  • Use tools/ for repo maintenance
  • Read docs/structure.md for the full repo map
  • Treat the scripts as production‑safe starting points and extend them for your environment

📥 Clone the Repository

git clone https://github.com/peterwhyte-lgtm/dba-scripts

🎨 Optional: GitHub‑Style Formatting (CSS)

Paste this into Appearance → Customizer → Additional CSS if you want the page to visually resemble GitHub:

.github-section {
    background: #f6f8fa;
    border: 1px solid #d0d7de;
    padding: 20px;
    border-radius: 6px;
    margin-bottom: 24px;
}

pre, code {
    background: #f6f8fa !important;
    border: 1px solid #d0d7de !important;
    padding: 8px !important;
    border-radius: 6px !important;
    font-family: Consolas, "Fira Code", monospace !important;
}