r/SQLServer • u/balurathinam79 • Apr 24 '26
Discussion Is fully automated SQL Server diagnosis actually viable? Built something to test it — what am I missing?
I’ve been working on a small tool to see if database diagnostics can run fully unattended.
The idea is simple:
A scheduled job reads DMVs / system views → runs a set of detectors → sends the evidence to an LLM → gets back a structured root cause + recommended SQL.
No agents, no writes to the monitored DB — just VIEW SERVER STATE / pg_monitor.
Right now I’ve got ~10–12 detectors covering the common failure paths:
- blocking / deadlocks
- job slowdowns vs baseline
- memory grant pressure / CPU saturation
- tempdb pressure (spills, version store, allocation contention)
- I/O stalls
- CDC / log scan issues
- long-running sessions with risk scoring
- query-level issues (missing indexes, plan instability)
- similar patterns on PostgreSQL (bloat, vacuum lag)
Each run is just a point-in-time snapshot — no long tracing or heavy collection.
Example from a real run (PostgreSQL — blocking + deadlock at the same time):
[!!] Found 2 issue(s)
==================================================== ISSUE 1 OF 2
[DB] Type: contention_lock_blocking
Job: REALTIME_CONTENTION
Desc: 1 session(s) blocked. Max wait 105s.
[!] Pattern: ETL/report contention (blocking present in DMV snapshot).
-> Consult runbook: Blocking and Lock Contention
[AI] Asking AI to analyze...
[OK] AI analysis saved to repository incidents
[>>] AI Analysis:
Root Cause: Session 1115 is blocking session 1813 with a transaction-level
lock (transactionid) for over 104 seconds
Confidence: 95%
Evidence:
* Real-time blocking: session 1813 blocked by session 1115
* Wait event Lock:transactionid -- row/transaction-level contention
* Block duration 104801.22ms (over 1.7 minutes) -- excessive
* Only 1 active session in Test_db with significant waits
* First occurrence of this blocking pattern in 30 days
Recommended Actions:
1. SELECT pid, state, query, xact_start FROM pg_stat_activity WHERE pid=1115
2. SELECT pid, xact_start FROM pg_stat_activity
WHERE pid=1115 AND xact_start IS NOT NULL
3. Terminate if idle-in-transaction: SELECT pg_terminate_backend(1115)
4. Cancel if running: SELECT pg_cancel_backend(1115)
5. Monitor: SELECT pid, wait_event_type FROM pg_stat_activity WHERE pid=1813
6. Confirm locks cleared:
SELECT locktype, pid, mode FROM pg_locks WHERE NOT granted
==================================================== ISSUE 2 OF 2
[DB] Type: deadlock
Job: DEADLOCK_EVENT
Desc: 1 mutual lock wait(s) detected. Max wait 105s.
[AI] Asking AI to analyze...
[OK] AI analysis saved to repository incidents
[>>] AI Analysis:
Root Cause: Deadlock between two sessions on table test_blocking --
session 1813 executing UPDATE while session 1115 holds
conflicting lock, indicating inconsistent lock acquisition order
Confidence: 90%
Evidence:
* Lock chain: blocked_pid=1813 blocking_pid=1115 table=test_blocking
* Blocked session waiting 105s on: UPDATE test_blocking SET val='s2'
* Blocking session holding lock 146s, last query: SELECT pg_backend_pid()
* First deadlock incident for DEADLOCK_EVENT in 30 days
* Test_db shows 1 session with significant lock-related waits
Recommended Actions:
1. SELECT locktype, relation::regclass, mode, granted, pid
FROM pg_locks WHERE NOT granted
2. SELECT pid, state, query FROM pg_stat_activity
WHERE pid IN (1813, 1115)
3. Terminate blocker: SELECT pg_terminate_backend(1115)
4. Fix application: ensure consistent lock acquisition order
5. Use FOR UPDATE NOWAIT or SKIP LOCKED to avoid indefinite waits
6. Track recurrence:
SELECT deadlocks FROM pg_stat_database WHERE datname='Test_db'
7. Enable logging: SET log_lock_waits=on; SET deadlock_timeout='1s'
This was a test scenario where both blocking and a deadlock condition existed — both detectors fired independently.
In simple cases like this, the output has been directionally correct. But I’m sure there are situations where this breaks.
What I’m trying to validate from people running real systems:
- What kind of issues would this completely miss?
- Which of these signals are too noisy to trust automatically?
- Where would you not trust the root cause even if the evidence looks fine?
Not trying to replace monitoring tools — more trying to see if the investigation step can be automated at all.
2
u/Simple_Brilliant_491 Apr 25 '26
I agree with your point that the monitoring tools only point you to the issue and using AI based tools can help investigate and provide a resolution to the issue more efficiently.
In my experience there are three keys to success:
If you are looking for something like this for SQL Server environments (including Managed Instance and Azure SQL), you can use AI SQL Tuner Studio. It has the following features:
Health Check - Checks wait, sp_configure settings, backup and checkdb history, security configuration, etc. See Fast SQL Server Health Check | AI SQL Tuner
Index Tuning - Queries plan cache, query store, missing indexes, index usage stats, and column cardinality to recommend index adds & drops, as well as code changes. See Index Tuning Goal | AI SQL Tuner
Code Review - Looks at up to 100 objects (stored procs, views, triggers and/or UDFs) and recommends code or index changes. See Code Review Tuning Goal: Find 5 Critical SQL Issues Instantly
Query Tuner - Deep dive into a single statement. Brings in the index stats and column cardinality for the tables involved to recommend code or index changes. See SQL Query Tuner - AI-Powered Query Optimization | AI SQL Tuner
Deadlock Analysis - Reviews deadlock XML and the objects involved for recent deadlocks and provides recommendations. See Fix SQL Server Deadlocks: 5 Proven Root Cause Analysis Steps | AI SQL Tuner
You can use provided endpoints of GPT-5.4, Claude Sonnet 4.6, or Opus 4.7 for analysis, or bring your own AI endpoint.
You can see sample reports at SQL Deadlock Root Cause Analysis & Fix Guide | AI SQL Tuner. For example, here is an excerpt from a deadlock analysis; since it pulls in the code involved it can give specific guidance as opposed to the analysis that you showed that only provides additional queries for the DBA to execute.
1
u/balurathinam79 Apr 28 '26
Thanks for the responses which i had got - it was very helpful. Would like to share a bit more context here to make it clear this isn’t something built to sell or promote. With AI being everywhere now, there’s a lot going on and many ways we can use these skills. And also, the intent isn't to replace a skilled DBA. It's to help developers who aren't DBAs stop losing an hour or so just figuring out where to look.
There are already great commercial tools with dashboards full of red and yellow indicators, dozens of metrics, wait stats, blocking chains. The problem I kept running into as a developer is that those tools give you a lot of signal but not much direction. You end up going down the wrong path — chasing CPU when the real issue is a stuck CDC scan holding the log open, or tuning a query when the job is just waiting on a lock.
This idea came from that experience. Not from a DBA mindset — I'm looking at it from the other side. The goal is something that says "here's what's wrong, here's why, here's what to check" in a way a developer can act on without needing five years of DBA experience to interpret it.
This post is really about collecting experiences from others who've been in that same spot — not to sell anything, just to understand what actually costs people time and whether the direction makes sense.
What kinds of issues have taken you the longest to diagnose — and what information would have actually helped you get there faster?
1
u/itsnotaboutthecell Microsoft Employee Apr 24 '26
Where’s the tool? Is there a GutHub link so people can review it? Is this intended as open source or a paid offering?
1
u/tribat Apr 25 '26
I’d love to see the repo.
2
u/7amitsingh7 Apr 28 '26
Fully automated SQL Server diagnosis can be useful, but mostly as a first pass tool rather than a true replacement for a skilled DBA. Automation is great at quickly identifying common issues like blocking, wait stats, missing indexes. Things like backup problems require human intelligence as here automation my fail because it usually falls short in context and judgment knowing which issues actually matter, which recommendations are safe, or whether a reported problem is the real cause versus just a symptom (you can learn more about automatic backup). In practice, automated tools are best used to speed up detection and triage, while human expertise is still essential for deeper performance tuning, architecture decisions, and avoiding fixes that could create bigger problems.
1
u/DurianVivid93 Apr 25 '26
Remindme! 24 hours