A comprehensive SQL Server Management Studio solution β a curated library of T-SQL scripts, PowerShell automations, Python orchestrators, and C# tools built by an experienced DBA to cover the full spectrum of SQL Server administration: from daily health checks to ambitious HA/DR projects.
If this project helped you reduce time to develop, you can give me a cup of coffee :)
| PayPal | UPI | |
|---|---|---|
![]() |
- VSS Backup & Restore on KVM β Flagship Project
- Custom Log Shipping
- Transactional Replication β Full Automation
- Transactional Replication β SQL Auth / Snapshot
- Baselining & Performance Collection
- BlitzQueries β Health Check & Diagnostics
- Blocking Alert System
- XEvent Metrics Infrastructure
- Performance Tuning SQL Notebooks
- SQLDBATools Inventory & Monitoring
- StackOverflow Lab & Workload Simulation
- Always On / HADR
- Service Broker β Single Service Pattern
- Deadlock Detection via SQL Trace
- Extended Events
- Security β TDE & Certificate Auth
- Self-Service Module β Signed Stored Procedures
- Columnstore Index Deep Dive
- Space & Capacity Management
- Backup & Restore β Migration Toolkit
- Instance Migration
- Maintenance β Index & Statistics
- Resource Governor
- SQLWATCH Integration
- Audit & Logon Trigger
- SQL Agent Jobs & Notifications
- SQL Trace β ClearTrace Integration
- Advanced Query Techniques
- Architecture Choices That Affect Performance
- TempDB Issues
- PowerShell Command Library
- SQL Lab β Infrastructure Setup
Flagship project β A production-grade, Microsoft-standard VSS backup/restore system for SQL Server running on Windows VMs hosted on a Linux KVM hypervisor.
π Backup-Restore-VSS/ Β· π Full Tutorial
No native BACKUP DATABASE, no .bak files, no KVM disk snapshot. Two C# programs talk directly to the SQL Server VSS Writer via the IVssBackupComponents API:
VssBackup.exe(runs on the source VM) β freezes SQL Server for milliseconds, takes a Windows software shadow copy, copies the frozen MDF/LDF files to a Samba share on the hypervisor, releases the shadow.VssRestore.exe(runs on the target VM) β reads the writer metadata from the share, rewrites the recorded machine name, signals the local SQL Writer to accept the files, and leaves the database inRESTORINGstate for continuous log shipping (warm standby).
A Python orchestrator on the hypervisor drives both tools over WinRM and a FastAPI web GUI lets operators run the whole cycle from a browser.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Bootstrap 5 SPA (vss_api/static/) β
β Dark sidebar Β· Backup Β· Restore Β· Snapshots Β· Jobs tabs β
β WebSocket live log streaming Β· PITR datetime picker β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β REST + WebSocket + /metrics
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββ
β FastAPI REST API (vss_api/) β
β server.py config.py jobs.py metrics.py β
β runners/backup.py runners/restore.py β
βββββββββββ¬ββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββ
β WinRM (PS β .exe) β mssql-python (TCP 1433)
βββββββββββΌββββββββββββββββββ βββββββββββββΌβββββββββββββββββββ
β VssBackup.exe Β· VssRestoreβ β sys.databases Β· DROP DATABASEβ
β Agent job (.trn chain) β β RESTORE LOG Β· ALTER NAME β
βββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββ
| Feature | Details |
|---|---|
| Pure-VSS path | No qcow2 juggling, no KVM quiesce; uses the same writer protocol as commercial backup products |
| LSN-chain verified | T-logs taken after the VSS backup apply cleanly on the restored DB β verify_tlog_chain.py proves it end-to-end |
| Compression | --compress flag gzips MDF/LDF on the fly; 60 GB β 18 GB (3.4Γ) on a real 5-database set |
| Parallelism | --parallel N copies up to N databases concurrently; backup 2.6Γ faster on the benchmark set |
| Copy-only mode | --copy-only (VSS_BT_COPY) leaves the SQL differential base LSN untouched β safe alongside a live backup schedule |
| Side-by-side restore | Rename + move a DB onto the same instance without touching the live original |
| PITR | Restore to any point in time via RESTORE DATABASE β¦ WITH RECOVERY, STOPAT = '<ts>' |
| Web GUI | Full job history, snapshot browser (with per-file detail and delete), real-time WebSocket log stream, running-job badge |
| mssql-python | All SQL metadata calls go through Microsoft's pure-Python driver β ~2 ms vs ~15 s for Invoke-Sqlcmd cold-load |
| Scenario | DBs | Backup | Restore | T-Log | Wire size |
|---|---|---|---|---|---|
| Base (serial) | CDCDemo, Db2 | 69 s | 8 s | β | 1.0 GB |
| Compress | CDCDemo, Db2 | 5 s | 12 s | β | 33 MB |
| Compress + Parallel + T-log | CDCDemo, Db2 | 6 s | 5 s | β | 33 MB |
| Full set base | 5 DBs / 60 GB | 3965 s | 860 s | β | 58.4 GB |
| Full set compress + parallel | 5 DBs / 60 GB | 1502 s | 785 s | β | 17.7 GB |
Backup-Restore-VSS/
βββ vss-backup-kvm.md β Full tutorial (this section)
βββ VssRequester/ β C# solution (core)
β βββ VssBackup/Program.cs β Backup requester
β βββ VssRestore/Program.cs β Restore requester
β βββ e2e_run.py / e2e_run_multi.py
β βββ verify_tlog_chain.py
β βββ preflight.py
βββ vss_api/ β FastAPI web server
β βββ server.py / config.py / jobs.py
β βββ runners/backup.py / restore.py
β βββ static/index.html + app.js
βββ winrm_helper.py β WinRM/SMB helpers
βββ create_tlog_job.py β Install Agent T-log job
βββ Apply-TLogs.ps1 β Warm-standby log apply loop
βββ start-vss-gui.sh β One-command GUI launcher
π LogShipping/ Β· π README
A hand-rolled log shipping solution that outperforms the built-in MSLS wizard when SQL services run under a domain account.
Core procedure: usp_DBAApplyTLogs β applies transaction log backups to one or many secondary databases, tracks the last applied file, sends mail alerts on failure, and integrates with Service Broker for event-driven log-walk triggering.
Why use this instead of native log shipping?
- Multiple secondaries with different latency windows
- Works as DR, limited reporting, migration, or SQL upgrade path
- No extra load on the primary
- Combines with AlwaysOn, Clustering, or Mirroring
- Alert suppression logic (
usp_GetLogWalkJobHistoryAlert_Suppressβ 10 versions tracked) prevents alert storms during planned maintenance
Key files
| File | Purpose |
|---|---|
usp_DBAApplyTLogs.sql |
Main log-apply procedure |
ServiceBroker-LogWalk.sql |
Event-driven log walk via Service Broker |
ScriptOut-Backup-Restore.sql |
Generates BACKUP/RESTORE chains |
[usp_GetLogWalkJobHistoryAlert].sql |
Alert on log walk job failures |
v1.0 β¦ v10.0 - [usp_GetLogWalkJobHistoryAlert_Suppress].sql |
Versioned alert-suppression logic |
__RefreshLogShipping__.ps1 |
Automates full log-shipping refresh |
π Replication-Transactional/
End-to-end management of SQL Server transactional replication β from initial setup through production monitoring, latency alerting, and schema-contention mitigation.
1 - Get Replication Jobs.sql
2 - Configuring the Distributor.sql
3 - Setting up Publication (Immediate Sync or Backup/Restore)
4 - Setting up Subscription (Backup/Restore or ReplicationSupportOnly)
5 - Testing a transactional replication topology.sql
6 - Remove Replication.sql
7 - Add Article without Full Snapshot.sql
| Object | Purpose |
|---|---|
dbo.repl_token_header / repl_token_history |
Partitioned tracer-token collection tables |
vw_Repl_Latency / vw_Repl_Latency_Details |
Views exposing publisherβdistributorβsubscriber latency |
usp_Get_Repl_Latency_Notification |
Sends HTML-formatted email when latency exceeds threshold; cross-checks MSdistribution_history errors |
usp_repl_pending_commands |
Counts undistributed commands per subscription |
DBA - Replication Token Rate.sql |
Tracks token throughput over time |
SCH-Repl-Canary-Tables.sql |
Canary table approach for latency without tracer tokens |
Job [DBA - Replication - Stoped Jobs].sql |
Alert when any replication agent job stops unexpectedly |
usp_replication_agent_checkup |
Comprehensive agent health check |
usp_RemoveReplSchemaAccessContention |
Reduces REPL_SCHEMA_ACCESS wait by pausing log reader during schema changes |
ps-add-distribution-database-2-ag.ps1 |
Adds distribution DB to an Availability Group |
ps-create-replication-setup-scriptout.ps1 |
Scripts out the full replication topology |
π Replication-Transactional-SQLAuthentication-Snapshot-Based/
A fully scripted, snapshot-initialized transactional replication setup that uses SQL Server Authentication β suitable for environments without Windows domain integration.
Automation pipeline (all steps are idempotent):
0 β Create sample tables on publisher
1 β Sync logins between publisher and subscriber (PS)
2 β Sync SQL Agent jobs (PS)
3 β Export and apply indexes (PS)
4 β Logon trigger on subscriber
5 β Replication latency check
9 β Full setup via 9__replication_setup.ps1:
9a Add distributor
9b Create publication
9c Add articles
9d Start snapshot agent
9e Check snapshot history
9f Create subscription
9g Get publication details
9h Check distribution history
9i Check identity columns
The master PowerShell script 9__replication_setup.ps1 accepts βDataCenter, βTable[], βSqlCredential, and optional flags to include or skip distributor/publication scripts β making it fully rerunnable.
π Baselining/
A scheduled data collection framework for ongoing performance trending and reactive investigation.
| Job / Script | Collects |
|---|---|
SCH-Job-[(dba) Collect Metrics - WhoIsActive].sql |
Every-minute sp_WhoIsActive snapshots into dbo.WhoIsActive with blocking tree, locks, plans, transaction info |
(dba) Collect Metrics - Wait Stats.sql |
Incremental wait-stat deltas into a partitioned table |
SCH-ResourcePool-CPU-Collection-Partitioned.sql |
Resource Governor pool CPU usage |
SCH-Virtual File Stats (SQLDBATools) |
Per-database file I/O latency and throughput |
FileStats - AsOf / During / Delta |
Point-in-time and interval-based I/O analysis |
BlitzFirst-PerfMon - AsOf / During |
sp_BlitzFirst results stored for trend analysis |
| Script | Purpose |
|---|---|
What Was Running.sql / What was Running - AsOf.sql |
Find active sessions at a past moment from WhoIsActive history |
What Was Running - BlockingTree*.sql |
Reconstruct blocking chains at a moment or over an interval |
WaitStats - Delta/During/Cumulative |
Wait stat trending with Paul Randal's filtering |
Top-10-Longest-Running-Variations.sql |
Rank queries by duration from WhoIsActive snapshots |
BenchMarking-Storage-Network.sql |
Disk and network throughput baselines |
Grafana-Database-Statistics-Dashboard.sql |
Grafana-ready time-series queries |
High-Memory-Usage-Alert-Response.sql |
Automated response playbook for memory pressure |
Generate-Workload-StackOverflow.sql |
Controlled load generation using the StackOverflow dataset |
π BlitzQueries/ Β· π README
A curated collection of First Responder Kit wrappers and custom health-check scripts.
WhatIsRunning.sql β A single query that shows currently running sessions at both batch and individual statement level, with CPU/memory usage, volume utilisation, data/log file space, lead blockers, and backup/restore/rollback progress. SQL Agent job sessions are shown with the human-readable job name.
who_is_active_v11_30(Modified).sql β Adam Mechanic's classic, extended to surface the SQL Agent job name for job-owned sessions.
| Script | Focus |
|---|---|
Blitz.sql / BlitzCache.sql / BlitzIndex.sql |
sp_Blitz family wrappers |
BlitzLock.sql |
Deadlock history from Extended Events |
BlitzQueryStore.sql |
Query Store health and regression analysis |
Buffer-Pool-Analysis.sql |
Buffer pool breakdown by database/object |
Plan-Cache-Analysis.sql |
Plan cache bloat, single-use plans, parameter sniffing |
Fragmentation-Analysis.sql |
Index fragmentation across all databases |
Detect n Reduce High VLFs.sql |
Identify and shrink excessive VLF counts |
Find-Indirect-Connections.sql |
Identify cross-server linked server usage |
RingBuffer-PerfMon-CPU-Memory.sql |
CPU and memory from the ring buffer (no PerfMon needed) |
SRV-Avg-CPU-Over-Time.sql |
CPU trend from sys.dm_os_ring_buffers |
Very-Large-Databases-Optimization.sql |
Checklist for VLDB health |
SCH-usp_PlanCacheAutoPilot.sql |
Automated plan cache analysis and flushing |
Configure_PSSDiag.sql / MS-SQL_LogScout.sql |
Microsoft diagnostics capture setup |
π Blocking Alert/
A complete blocked-process alerting solution wired to SQL Server Agent.
Setup sequence:
1. Add DBAGroup operator
2. Set 'blocked process threshold' (20 s)
3. Create dbo.WhoIsActive_ResultSets capture table
4. Create Job [DBA - Log_With_sp_WhoIsActive]
5. Create Alert [Blocked Process Threshold > 5 minutes]
6. Fetch and format blocking information
Real-time analysis scripts:
| Script | Use |
|---|---|
BT-Live.sql |
Live blocking tree in pure T-SQL |
BT-Live-WhoIsActive.sql |
Live blocking tree via sp_WhoIsActive |
BT-Capturing-ThresholdBased.sql |
Capture blocking chains when threshold is hit |
Find-Blocking-Tree-LockTime.sql |
Analyse historical blocking with lock duration |
Blocking-Alert-Azure.sql |
Azure SQL Database variant |
An Extended Events-based workload metrics platform that captures per-query CPU, reads, writes, and duration into a normalized dbo.xevent_metrics table, then aggregates them for trend analysis.
| Script | Purpose |
|---|---|
QRY-xevent_metrics-infra.sql |
Parameterised query: group workload by SQL text, login, program, or host over a time window |
QRY-xevent_metrics-Infra-Normalized.sql |
Normalized view with dbo.normalized_sql_text() for plan-count deduplication |
QRY-RC-Workload-Delta-By-CPU.sql |
Delta CPU usage by resource pool / query group |
QRY-RC-Workload-Delta-By-Reads.sql |
Delta reads analysis |
QRY-top-login-program.sql |
Top consumers by login and application |
QRY-Top-Consumers-DELTA.ipynb |
Jupyter notebook for trending top consumers |
π Performance-Tuning-SQL-Notebooks/
A suite of Azure Data Studio / Jupyter SQL notebooks for structured, repeatable performance analysis. Each notebook queries the [DBA] metrics database and is parameterised by weekday or month-day for trend comparison.
| Notebook | Analyses |
|---|---|
sp_Blitz-WeekDay-MonthDay.ipynb |
Server health findings over time |
sp_BlitzFirst-WeekDay-MonthDay.ipynb |
Wait stats and perfmon snapshot deltas |
sp_BlitzFirst-SinceStartup-WeekDay-MonthDay.ipynb |
Cumulative waits since SQL Server start |
sp_BlitzCache-By-CPU/Reads/Writes/Executions/Memory/Spills/UnusedGrants/Writes |
Plan cache top queries, each sorted by a different resource dimension |
sp_BlitzIndex-Mode-0/1/2/3/4 |
Index analysis across all five BlitzIndex modes |
sp_BlitzLock-WeekDay-MonthDay.ipynb |
Deadlock trends |
sp_HumanEvents-Compilations-WeekDay-MonthDay.ipynb |
Compilation and recompilation spikes |
IO-Latency-WeekDay-MonthDay.ipynb |
File-level I/O latency trends |
WaitStats-WeekDay-MonthDay.ipynb |
Wait stat distribution over time |
__Observations__.ipynb |
Free-form observation notebook for tuning sessions |
Supporting scripts:
| Script | Purpose |
|---|---|
Import-Blitz-Results-To-SQLServer.ps1 |
Bulk-imports Blitz output files into a SQL table |
Run-SQLNotebooks-Using-PowerShell.ps1 |
Batch-executes notebooks via PowerShell |
A centralised [DBA] database that aggregates performance metrics from multiple SQL Server instances. Designed to feed Grafana dashboards and alerting pipelines.
| DMV / Source | What is stored |
|---|---|
sys.dm_os_memory_clerks |
Memory clerk sizes (MB) per type |
sys.dm_os_sys_memory |
Physical / page-file / free memory state |
sys.dm_os_process_memory |
SQL process address space |
sys.dm_os_performance_counters |
SQL and OS PerfMon counters |
sys.dm_io_virtual_file_stats |
Per-file I/O: reads, writes, stall ms |
sys.dm_os_wait_stats |
Cumulative wait statistics |
| XEvent ring buffer | Query-level CPU, reads, duration |
Grafana-Database-Statistics-Dashboard.sqlβ Dashboard queries for CPU, memory, I/O, wait statsGrafana-Dashboard-SQLDBATools-1597626189988.jsonβ Importable Grafana dashboard definitionGrafana-WaitStats.sqlβ Time-series wait stat queries formatted for Grafana
| Script | Purpose |
|---|---|
SQLDBATools_DDLs.sql / SCH-*.sql |
Complete DDL for all metric tables |
Job-DataCollection.sql |
Agent job to run usp_collect_performance_metrics every minute |
Job [SQLDBATools - DataCollection - EventLogs].sql |
Windows Event Log collection |
PS-perfmon-collector-logman.sql |
PerfMon data collector set via logman |
PS-perfmon-collector-push-to-sqlserver.sql |
Push PerfMon BLG files to SQL Server |
1-5. Create VHDs / VMs / Post-OS scripts |
Hyper-V lab provisioning from scratch |
UnAttended-Sql-Installation.sql |
Silent SQL Server installation script |
π StackOverflow/
Scripts and tools for using the public Stack Overflow database as a realistic large-scale SQL Server lab dataset.
| Script | Purpose |
|---|---|
Invoke-RandomQ.ps1 |
Randomly selects and executes queries against StackOverflow to generate realistic CPU/IO load |
Invoke-IndexLab6.ps1 |
Index tuning lab β creates/drops indexes while measuring query impact |
Invoke-ServerLab2/4/5.ps1 |
Graduated server-level performance labs |
Generate Workloads.sql |
Grafana-integrated workload queries |
| Script | Topic |
|---|---|
QA - StackOverflow Rank and Percentile.sql |
Reputation percentile ranking |
QA - How many upvotes do I have for each tag.sql |
Tag-based vote breakdown |
QA - Users with highest accept rate of their answers.sql |
Answer acceptance analysis |
QA - How Unsung am I.sql |
Unaccepted answer ratio |
QA - Most controversial posts on the site.sql |
Controversy scoring |
QA - Top 500 answerers on the site.sql |
Leaderboard query |
SCH - RPT-usp_*.sql (20+ procedures) |
Stored reporting procedures for dashboards |
π HADR/
Certificate-based Always On AG and Database Mirroring setup scripts β no domain Kerberos dependency.
| Script | Purpose |
|---|---|
AG Setup - Certificate Based.sql |
Creates master key, certificates, mirroring endpoints, logins, AG, and listener across multiple nodes |
AG_without_WSFC.sql |
AG configuration outside a Windows Server Failover Cluster |
Mirroring Setup - Certificate Based.sql |
Database mirroring with certificate authentication |
troubleshooting-issues.sql |
Common HADR error codes and remediation queries |
Complements SQLAgent-Notifications/SCH-Setup-AG-Alerts.sql which configures standard AG health alerts and operator notifications.
π ServiceBroker-SingleService/
Implements the single-service Service Broker pattern to asynchronously queue and process sp_WhoIsActive messages β decoupling the capturing step from the processing step.
| Script | Role |
|---|---|
a) Single-Service-Config.sql |
Queue, service, contract, message type setup |
b) [usp_SendWhoIsActiveMessage].sql |
Sends a WhoIsActive XML snapshot to the queue |
c) [usp_ProcessWhoIsActiveMessage].sql |
Dequeues and processes messages |
Test-Multi-Job-Execution-Scenario.sql |
Validates concurrency under multiple simultaneous senders |
π Deadlock_Detection_SQLTrace/
An automated deadlock capture pipeline using SQL Trace (legacy path, compatible with SQL 2008 R2+).
1. Create SQLTrace_Deadlock trace definition
2. Create usp_StopTrace stored procedure
3. Create Agent jobs: SQLTrace_Start (on SQL startup) + SQLTrace_Stop (on schedule)
Supporting scripts create a test deadlock scenario (Job [Update Employee Salary] and [Deadlock Session].sql) and provide trace metadata queries.
π Extended Events/
| Script | Purpose |
|---|---|
01) XEvent Definition.sql |
Session definitions for capturing query performance, deadlocks, and waits |
02) XEvent Extraction.sql |
Parsing and querying XEvent ring buffer and file targets |
π Security/
| Script | Purpose |
|---|---|
TDE.sql |
Step-by-step Transparent Data Encryption: master key β certificate β DEK β encryption |
Encrypt-SQLDatabases.ps1 |
PowerShell wrapper to enable TDE on multiple databases in a single pass |
SCH-[tde_implementation_details].sql |
Audit table tracking TDE state, certificate thumbprint, and encryption progress per database |
π Self-Service-Module-Signed-Tools/
Implements certificate-based code signing so DBA tools (e.g., sp_Blitz) can be granted elevated permissions without adding the caller to sysadmin.
| Script | Purpose |
|---|---|
Certificate Based Authentication - [CodeSigningLogin].sql |
Creates CodeSigningCertificate, backs it up, creates CodeSigningLogin from the cert, grants sysadmin to the cert-login (not the user) |
All-Procedures.sql |
Signs all DBA procedures with the certificate |
Dummy-Login-Creation.sql |
Creates a low-privilege login to test the signed-proc pattern |
Certificate Cleanup.sql |
Revocation and removal scripts |
π Columnstore/
A 7-module hands-on lab series using the StackOverflow database. Each .sql file is a standalone demo:
0) Introduction and overview β rowstore vs columnstore on dbo.Votes
1) How data is stored β segments, row groups, dictionaries
2) Deletes, updates, inserts β delta stores and tombstones
3) How data is read β segment elimination, batch mode
4) Rebuilding β ALTER INDEX REBUILD vs REORGANIZE
5) Nonclustered columnstore advantages β partial coverage
6) Clustered columnstore candidate β design criteria
7a/b) Partitioning as a partner β partition switching with columnstore
π Space Issues/ Β· SpaceCapacity-Automation/
| Script | Purpose |
|---|---|
Get-DbSize.sql / QRY-Get-All-Db-Files-Details.sql |
Database and file sizes across all databases |
Get-VolumeInfo.sql |
Drive free space via sys.dm_os_volume_stats |
Get-Table-Sizes.sql / PS-Get-Table-Sizes.sql |
Top tables by data and index size |
Purge-Records-In-Chunks.sql |
Safe batch delete to reclaim space without log bloat |
compress-Tables-Indexes.sql |
ROW/PAGE compression recommendations and application |
SCH-Move-Database-Files.sql |
Online database file relocation procedure |
Shrink Log Files.sql / Invoke-DbaDbShrink.sql |
Controlled log file shrink |
QRY-Log-Files-Space-On-Drive.sql |
Log file space consumption per drive |
| Script | Purpose |
|---|---|
Automation - Restrict File growth.sql |
Agent job that caps autogrowth events |
Tsql-VLF-Counts.sql / Tsql-Remove-VLFs*.sql |
VLF diagnosis and reduction (single DB and all DBs) |
π Backup-Restore/
Numbered scripts that walk through a full database migration:
1) Generate backup script (all databases)
2) Script out database permissions (for DB refresh)
3) Generate restore script (from backup history or disk files)
4) Script out DB_Owner from source
5) Set compatibility level to match model database
6) Run CHECKDB + UpdateStats on migrated DBs
7) Copy latest full backup to new location (two variants)
8) Fix orphan logins for all databases
Supporting scripts:
| Script | Purpose |
|---|---|
RevLogin-Script.sql |
Re-creates logins with original SID and hashed password |
Database Mirroring - Certificate Based.sql |
Mirroring setup as part of migration |
Get-LatestBackups.sql |
Query latest backup per database |
Query - Backup History.sql / Restore History.sql |
Backup/restore audit trail |
ScriptOut - RESTORE With REPLACE.sql |
Bulk restore override scripts |
__RefreshLogShipping__.ps1 |
Automates secondary refresh from new full backup |
π InstanceMigration/
A checklist-driven migration toolkit:
| Script | Purpose |
|---|---|
Check-Space-Requirement.sql |
Estimates target disk space needed |
Estimate-Backup-Size-Full.sql |
Pre-migration backup size estimate |
LoginsUsers.sql |
Scripts all logins and user mappings |
Get-UserObjects-in-SystemDb.sql |
Finds user objects in master/msdb that must move |
Copy-Files-Folders-Permissions.sql |
Robocopy + icacls for file migration |
Copy-SSIS-Packages.sql |
SSIS package migration |
Migrate-SSRS-Reports.sql |
SSRS report and data source migration |
Move-TempDb.sql |
Relocates TempDB files |
Migration-Issues.sql |
Common post-migration issues and fixes |
PowerShell.ps1 |
Bulk migration automation |
π Maintenance/
| Script | Purpose |
|---|---|
Ola-Maintenance-Solution-Github.sql |
Ola Hallengren's maintenance solution setup |
[IndexOptimize_Modified]-SCH.sql |
Modified IndexOptimize with additional thresholds |
[IndexOptimize_Modified]-Usage.sql |
Usage examples for the modified procedure |
Index-Defrag-UpdateStats-Analysis.sql |
Pre/post fragmentation and statistics analysis |
QRY-Delta-UpdateStats-IndexOptimize.sql |
Delta comparison of stats update efficiency |
QRY-Statistics-State-Update-Status.sql |
Statistics last-updated age across all databases |
QRY-Flush-Regressing-QueryPlans.sql |
Flush specific plans from the plan cache |
SCH-Purge-msdb.dbo.sysjobhistory.sql |
Agent job history pruning |
Maintainence - Delete files older than 72 hours.sql |
File-system cleanup for backup file retention |
π Resource Governor/
| Script | Purpose |
|---|---|
Arc-RS-Settings.sql |
Resource Governor pool and workload group configuration |
Find-Queries-Consuming-CPU.sql |
Identify top CPU consumers by resource pool |
PS-Copy-RG-Classifier-Function.sql (Baselining) |
Copy classifier function between instances |
_URLs-Resource-Governor.sql |
Reference links for Resource Governor design |
π SQLWATCH/
Scripts and Grafana dashboard definitions for the SQLWATCH monitoring framework.
| File | Purpose |
|---|---|
SQLWATCH-IMPORT-CENTRAL-REPO.sql |
Import SQLWATCH data into a central repository |
SQLWATCH-Make-Changes-in-Configuration.sql |
Configuration tuning (collection intervals, checks) |
[dbg].[usp_sqlwatch_internal_process_checks].sql |
Debug wrapper for check processing |
Grafana-Queries.sql |
Custom Grafana panel queries |
SQL Instance Overview.json |
Importable instance overview dashboard |
Repository Dashboard.json |
Central repository Grafana dashboard |
Wait Events.json / Long Queries.json |
Specialised Grafana panels |
| Script | Purpose |
|---|---|
SCH-Connection-Limit-Infra.sql |
Infrastructure for per-login connection throttling |
Connection Limit.sql |
Logon trigger that enforces max-connections-per-login |
Audit-Logins-Failed-Successful.sql |
SQL Server Audit spec for login events |
SCH-Audit-for-TRUNCATE.sql |
DDL trigger to audit TRUNCATE TABLE |
database-access-audit.sql |
Database-level access audit using SQL Audit |
create-database-audit.sql |
Server-level audit object creation |
POC-Ledger-Audit.sql |
SQL Server 2022 Ledger table proof-of-concept |
PS-Generate-Concurrent-Connections.sql |
PowerShell load generator for connection-limit testing |
QRY-Check-Limit-Connections-Live.sql |
Live connection count per login |
ps-Find-Table-Dependencies.sql |
Find all dependent objects before structural changes |
π SQL Jobs/ Β· SQLAgent-Notifications/
| Script | Purpose |
|---|---|
v0.0/0.1 - Mail-Notification-Long-Running-Jobs.sql |
Alert when an Agent job exceeds a runtime threshold |
v0.1 - dbo.usp_StopLongRunningJob.sql |
Automatically stops a runaway job and notifies |
v0.0 - dbo.usp_GetDisabledJobNotification.sql |
Alert when expected jobs are disabled |
usp_GetStepFailureData.sql |
Detailed step failure history with error messages |
JobHistory_Duration.sql |
Job duration trend across days/weeks |
Jobs_Schedule.sql |
Visualise job schedules and last run results |
SCH-Setup-AG-Alerts.sql |
Always On health alerts (role change, data movement suspended) |
DBA - Ping Mirroring Partners.sql |
Scheduled ping of mirroring endpoints |
PingServers.ps1 |
Multi-server availability check |
π SQLTrace/
| Script | Purpose |
|---|---|
01) Trace Definition (SQL 2008 R2).sql |
Server-side trace capturing RPC/Batch completed events |
02) Trace Related Queries.sql |
Query active traces and their file targets |
03) DBA - SQLTrace_Stop.sql |
Gracefully stops the trace and closes the file |
04) ClearTrace-Top-15-Batches-By-*.sql |
ClearTrace-imported data: top 15 batches by CPU / Duration / IO |
04) ClearTrace-Top-15-Statements-By-*.sql |
Statement-level top consumers |
π Advanced Query Techniques/
Demo scripts from conference presentations on advanced T-SQL:
| Script | Topic |
|---|---|
Carry-Over-Sort-vs-Batch-Mode-Window-Functions.sql |
Sort spill avoidance with batch-mode window aggregates |
Itzik-Ben-Gan.sql |
Techniques from Itzik Ben-Gan's T-SQL training |
Wild-LIKE-CHARINDEX.sql |
Wildcard search performance β LIKE vs CHARINDEX vs Full-Text |
π Architecture-Choices-That-Affect-Performance/
Presentation materials and demo queries for the meetup talk "Database Architecture Designs That Impact Performance":
| File | Topic |
|---|---|
Finding Data Type Mismatches.sql |
Detect implicit conversion hotspots |
Implicit Conversion Examples.sql |
Reproduce and measure conversion overhead |
Foreign key and constraints.sql |
FK trust status and optimizer impact |
Red Flags for Database Design.sql |
Design anti-patterns: HEAPs, wide rows, NULLs, GUIDs |
Meetup - Database Architecture Designs That Impact Performance.pptx |
Slide deck |
π TempDb-Issues/
| Script | Purpose |
|---|---|
Find-Longest-Running-Query-TempLog.sql |
Find the query consuming the most TempDB log space |
Find-Db-Files-Space-Usage.sql |
Real-time TempDB file utilization |
Version-Store-Usage.sql |
Version store size and cleanup rate |
Raw-Queries-TempDb-Space-Issues.sql |
Ad-hoc TempDB diagnostic queries |
v0.0 - [usp_getDatabaseFileSpaceUsageNotification].sql |
Alert when TempDB hits a space threshold |
π PowerShell Commands/
A reference library of production-tested PowerShell patterns for SQL Server administration:
| Script | Technique |
|---|---|
MultiThreading-Powershell-Jobs.sql |
Background jobs (Start-Job) |
MultiThreading-Powershell-PoshRSJob.sql |
PoshRSJob module for faster parallelism |
MultiThreading-Powershell-RunSpaces.sql |
Raw runspace pools for maximum throughput |
RSJob-with-Progress-Bar.sql |
Progress reporting for long-running RS jobs |
PowerShell-Efficient-Fetch-From-Multiple-Servers.sql |
Concurrent multi-server data collection |
ScriptOut-Database-Objects-EachInOwnFile.sql |
Script all objects, one file per object |
ScriptOut-Database-Objects-AllCombinedFile.sql |
Single-file full database script-out |
Copy-DbaDbTableData.sql |
dbatools Copy-DbaDbTableData with filtering |
Save-Credentials.sql |
Secure credential storage with Export-Clixml |
Retry-Command.sql |
Generic retry wrapper with exponential back-off |
QueryResults-2-Excel.sql / Get-SqlResult2Excel.sql |
Export query results to Excel |
compare-replication-state-change.ps1 |
Diff replication agent state before/after a change |
ps-upgrade-sql2019-powershell.ps1 |
Automates SQL Server 2019 upgrade via PowerShell |
π SQL-Lab/
Scripts for building a multi-node SQL Server lab from scratch on KVM/Hyper-V:
| Script | Purpose |
|---|---|
Join-CentOS-2-Windows-Domain.sql |
Join a Linux VM to an Active Directory domain |
hosts-file-*.sql |
/etc/hosts entries for DC, VMs, and hypervisor |
Setup-Email-Server.sql |
Configure Database Mail with Gmail SMTP |
Setup-VPN-Windows-Server.sql |
RRAS VPN configuration for lab isolation |
FireWall-Rules.sql |
Windows Firewall rules for SQL, AG endpoints, and WinRM |
Simulating a Multi Subnet cluster.pdf |
Lab guide for multi-subnet FCI/AG |
If this project helped you reduce development time, you can give me a cup of coffee :)
| PayPal | UPI | |
|---|---|---|
![]() |





