SQL Server DBA Scripts & Tools
dba-tools is the toolkit I use as a working SQL Server DBA, free and open on GitHub. Copy/paste scripts for the day-to-day, a one-command health check, and an AI assessment that reviews the whole server with you.
Quick Access
Repo Areas
📋 Copy/Paste First
170+ production-safe SQL scripts. Open one, paste it into SSMS, run it. No install, no parameters, no magic variables.
🩺 Health Check
39 diagnostic scripts run in a single command, saved as CSVs, then a rules review flags CRITICAL / WARNING / INFO findings.
🤖 AI Assessment
The flagship. An AI reads the whole collection, correlates findings into root causes, and writes a prioritized report.
Quick Start
Clone the repo and run the setup script. It checks prerequisites, installs the SqlServer module if missing, and verifies the connection. Pass or fail, it tells you exactly what to do next.
git clone https://github.com/peterwhyte-lgtm/dba-tools
cd dba-tools
.\Initialize-Environment.ps1
To target a remote or named instance instead:
.\Initialize-Environment.ps1 -ServerInstance PROD01\SQL2025
Once setup passes, the server is saved for the session and every script picks it up automatically. Everything is read-only by default, and every script header states the permissions it needs and what it touches.
🤖 The Health Check, Reviewed by AI
The flagship workflow. A collection runs 39 diagnostic scripts against an instance (backups, waits, blocking, memory, disk, security surface area) and saves every result as a CSV. A rules review turns those into deterministic findings. Then the AI assessment reads the whole collection and does what fixed thresholds can’t: it correlates findings across the outputs into root causes and writes a prioritized report with evidence and a fix for each issue.
It’s a second reviewer that has read every output, doesn’t get tired, and surfaces the blindspots you’d miss at 2am. Nothing is sent to any AI until you run the assessment step yourself.
Three commands take a server from no idea to a written assessment:
# 1. Collect
.\powershell\reporting\Invoke-HealthCheckCollection.ps1 -ServerInstance PROD01\SQL2025
# 2. Rules review
.\powershell\reporting\Review-HealthCheckOutput.ps1
# 3. AI assessment
.\powershell\reporting\Invoke-AiAssessment.ps1
What’s Inside
⚡ Performance & Troubleshooting
Blocking, long-running queries, wait stats, missing indexes, deadlocks.
📊 Monitoring & Health
CPU, memory, disk pressure, TempDB, SQL Agent jobs, configuration checks.
💾 Backups & Recovery
Backup coverage, history, restore validation, gap detection.
🔐 Security & Configuration
Logins, permissions, sysadmin review, orphaned users.
🟢 High Availability
Always On health, replica state, sync latency.
🚚 Migration Support
Compatibility checks, deprecated features, DDL generators for logins, jobs and users.
Three Ways to Run It
1. SQL in SSMS
Copy any script from the repo straight into SSMS, run it, and get results immediately. This is the core toolkit path and needs nothing else installed.
2. PowerShell
Run the same scripts by name from terminal, for example .\run.ps1 Get-WaitStatistics, and export output to CSV for analysis and reporting.
3. The Web UI
A local dashboard where collections are viewed and verified: health scorecard, security drill-down, disk capacity, AI reports, and live incident triage.
Script Articles
The scripts worth explaining get their own articles: what the script returns, when to use it, and the full script ready to copy. Good starting points, grouped by the job in hand:
⚡ Performance
- Blocking and Locking (hub)
- Index Maintenance (hub)
- Query and Performance Tuning (hub)
- Top Wait Statistics in SQL Server
- Identify Long-Running Queries
- Identify Missing Indexes
- Get Blocking Sessions
- Get Deadlock Summary
- Get Index Fragmentation
🔐 Security
💾 Backups & Recovery
💽 Storage & Capacity
- Storage and Capacity (hub)
- Check Disk Space on SQL Server
- Get Database Sizes and Free Space
- Get Database Free Space Summary
- Get Filegroup Space
- Get Database Growth Risk and Forecast
- Get Log Reuse Waits
- Get Autogrowth History
- Get Temp DB Hotspots
🟢 High Availability
- High Availability (hub)
- Check AG Replica Role and Synchronization State
- Check Always On Availability Group Latency
- Get AG Failover Readiness and Readable Secondary Usage
- Get Mirroring Endpoint Health and Status
- Get Last Node Blip
- Get Replication Status
- Get Replication Agent Status
⚙️ Configuration & Jobs
Production DBA Daily Scripts
Day-to-day production shortlist. These are the scripts to grab first when triaging activity, checking capacity, validating resilience, and getting through change windows safely.
Operations and Triage
Storage and Capacity
Resilience and Security
Grab the Toolkit
Free and open source. Every script came from a real situation: an incident, a migration window, or a routine check that needed to be fast and safe.
Blog Categories
- Backups & Recovery (7)
- DBA Scripts (97)
- High Availability (HA) (7)
- Installation & Configuration (14)
- Maintenance (4)
- Monitoring (14)
- Performance Tuning (11)
- Security (Encryption & Permissions) (6)
- T-SQL Fundamentals (11)
- Troubleshooting (10)
- Wait Types (201)
Latest Posts
- DBA Scripts: Generate Maintenance Jobs
- DBA Scripts: Get Job Schedules and Duration Trends
- How to Shrink SQL Server Database Files in Chunks
- DBA Scripts: Get Lock Escalation, Contention Analysis, and Blocking Chains with Plan
- DBA Scripts: Get Trace Flags and Resource Governor Configuration
- DBA Scripts: Get CPU Topology and OS Configuration Checks
Blog Tags
Access (3) Always On Availability Groups (4) Auditing (7) Backups (4) Blocking Locking (6) Database Backups & Recovery (8) Database Backups and Recovery (5) Database Maintenance (7) DBA Tools (28) Disk Space (5) Error Log (2) Extended Events (7) Features (6) High Availability (6) Indexes (5) Instance (3) Inventory (6) Jobs (3) Migration (6) Monitoring (24) Performance (19) Performance Troubleshooting (9) PowerShell (4) Queries (3) Query Behaviour (5) Security (7) SQL Agent (3) SQL Scripts (21) SQL Server Administration (10) SQL Server Configuration (7) SQL Server Errors (5) SQL Server High Availability (4) SQL Server Internals (3) SQL Server Management Studio (SSMS) (6) SQL Server Monitoring (7) SQL Server Networking (9) SQL Server Security (9) SQL Server Versions (2) Storage and Capacity (9) T-SQL (9) Temp DB (3) Tracing (7) Transaction Logs (5) Troubleshooting (14) Windows Server (4)