<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: dbadrivers</title>
    <description>The latest articles on DEV Community by dbadrivers (@dbadrivers).</description>
    <link>https://dev.to/dbadrivers</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4193046%2F26331797-9e60-4f02-9a78-632b57d13e73.png</url>
      <title>DEV Community: dbadrivers</title>
      <link>https://dev.to/dbadrivers</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dbadrivers"/>
    <language>en</language>
    <item>
      <title>AI DBA on Bare Metal: Slow Log In, Diagnosis + Fix SQL Out (Data Never Leaves Your Network)</title>
      <dc:creator>dbadrivers</dc:creator>
      <pubDate>Mon, 19 Oct 2026 02:00:58 +0000</pubDate>
      <link>https://dev.to/dbadrivers/ai-dba-on-bare-metal-slow-log-in-diagnosis-fix-sql-out-data-never-leaves-your-network-36jj</link>
      <guid>https://dev.to/dbadrivers/ai-dba-on-bare-metal-slow-log-in-diagnosis-fix-sql-out-data-never-leaves-your-network-36jj</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/hacktoberfest-week2-2026-10-12"&gt;Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;AI DBA on Bare Metal&lt;/strong&gt; — a dead-simple CLI tool for MySQL DBAs. You feed it a slow query log (or a DBCheck inspection package), and an open-weight model running on &lt;em&gt;your own hardware&lt;/em&gt; hands back three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Diagnosis&lt;/strong&gt; — the root cause in 1–3 sentences, no fluff&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Executable SQL&lt;/strong&gt; — the actual &lt;code&gt;ALTER TABLE&lt;/code&gt;, rewritten query, or parameter change that fixes it&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Risk note&lt;/strong&gt; — one line on what breaks if you run it blind&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Who would pay for this? Any team running MySQL in production where the slow log is too sensitive for a cloud API. Slow logs leak your table names, your query patterns, your business logic. A managed "AI database advisor" means shipping all of that to someone else's servers — and paying per token forever. This runs on a box you already own, as often as you like, for the cost of electricity.&lt;/p&gt;

&lt;p&gt;I'm a DBA. I built the thing I wished existed at 2 AM, when a slow query is melting production and I need a second pair of eyes that actually knows MySQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;Run it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;python aidba.py &lt;span class="nt"&gt;--slowlog&lt;/span&gt; sample-slow.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Parsed 3 slow queries, sending to model...
============================================================
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  SQL #1 — 12.35s
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Diagnosis:&lt;/strong&gt; Missing index on &lt;code&gt;orders.created_at&lt;/code&gt; forces a full scan; the &lt;code&gt;ORDER BY o.total&lt;/code&gt; then triggers a filesort over every row in the date range.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;idx_orders_created_total&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;created_at&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Risk:&lt;/strong&gt; Index build briefly locks the table on older MySQL versions; test on a replica first.&lt;/p&gt;




&lt;h2&gt;
  
  
  SQL #2 — 8.21s
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Diagnosis:&lt;/strong&gt; &lt;code&gt;IN (SELECT ...)&lt;/code&gt; executes the subquery once per row in &lt;code&gt;order_items&lt;/code&gt; — the classic correlated-subquery anti-pattern.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;order_items&lt;/span&gt; &lt;span class="n"&gt;oi&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;oi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;category&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'electronics'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Risk:&lt;/strong&gt; Verify that &lt;code&gt;order_items(product_id)&lt;/code&gt; and &lt;code&gt;products(category)&lt;/code&gt; indexes exist; add them if missing.&lt;/p&gt;




&lt;h2&gt;
  
  
  SQL #3 — 5.68s
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Diagnosis:&lt;/strong&gt; The query filters on both &lt;code&gt;action&lt;/code&gt; and &lt;code&gt;created_at&lt;/code&gt;, but at most one column is indexed — so it scans the table (or a single-column index) across the whole range.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;idx_user_logs_action_created&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;user_logs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Risk:&lt;/strong&gt; Composite index adds write overhead and storage; negligible for a read-heavy table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;============================================================
[AI DBA] Diagnosis complete. Data never left your network.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The whole flow: parse the slow log → pick the top-N slowest queries → build a DBA-structured prompt → POST to a local vLLM → print the diagnosis. Under 100 lines of Python, zero third-party dependencies.&lt;/p&gt;

&lt;p&gt;Video demo and full walkthrough coming — the model runs on my own dual-machine inference cluster, so the demo is a screen recording rather than a public URL. The entire point is that there &lt;em&gt;is&lt;/em&gt; no public URL.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fny6cnjjd7wj1x351kqmn.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fny6cnjjd7wj1x351kqmn.gif" alt="AI DBA demo" width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/aimdotsh/ai-dba" rel="noopener noreferrer"&gt;https://github.com/aimdotsh/ai-dba&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The repo is a single Python file on the standard library alone (&lt;code&gt;urllib&lt;/code&gt;, &lt;code&gt;re&lt;/code&gt;, &lt;code&gt;json&lt;/code&gt;, &lt;code&gt;argparse&lt;/code&gt; — no &lt;code&gt;openai&lt;/code&gt; package, no frameworks):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;aidba.py&lt;/code&gt; — slow log parser + prompt builder + OpenAI-compatible API client&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sample-slow.log&lt;/code&gt; — try it with &lt;code&gt;python aidba.py --slowlog sample-slow.log&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It speaks to any OpenAI-compatible endpoint. I run it against vLLM serving DeepSeek-V4 on two machines (4×200G RoCE interconnect, &amp;gt;120 tokens/s), but any local model works — Ollama, llama.cpp server, whatever you have on your iron.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I Built It
&lt;/h2&gt;

&lt;p&gt;The stack is deliberately boring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model&lt;/strong&gt;: DeepSeek-V4 (open-weight), served via &lt;strong&gt;vLLM&lt;/strong&gt; with its OpenAI-compatible &lt;code&gt;/v1/chat/completions&lt;/code&gt; endpoint&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client&lt;/strong&gt;: ~100 lines of Python, stdlib only. No SDK — it's just an HTTP POST with JSON&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompt engineering&lt;/strong&gt;: this is where the DBA knowledge lives. The system prompt enforces a strict output contract (diagnosis → executable SQL → risk note), temperature is 0.2 for determinism, and the parser pre-sorts the log by &lt;code&gt;Query_time&lt;/code&gt; so the model spends its context on the queries that actually hurt&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The key architectural decision: &lt;strong&gt;the model is infrastructure, not a service&lt;/strong&gt;. No API key, no usage dashboard, no per-token billing. Point &lt;code&gt;AIDBA_API_BASE&lt;/code&gt; at your own box and go. If your company already runs GPUs for anything, the marginal cost of one more DBA copilot is zero.&lt;/p&gt;

&lt;p&gt;Why not just use a cloud API? Because the input is a slow log. Let me say that again: the input is your production query patterns. For anyone in finance, healthcare, or anyone with a sane security policy, "paste your slow log into a chatbot" is a non-starter. Local inference isn't a nice-to-have here — it &lt;em&gt;is&lt;/em&gt; the product.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Does Open Innovation Matter?
&lt;/h2&gt;

&lt;p&gt;Three reasons, and every one of them disappears the moment this is built on a closed API:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data sovereignty is the feature.&lt;/strong&gt; The selling point isn't "AI diagnoses your database" — cloud vendors already do that. It's "AI diagnoses your database &lt;em&gt;without your data leaving the building&lt;/em&gt;." That sentence is only true with open-weight models you run yourself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The cost structure makes the business work.&lt;/strong&gt; A per-token DBA copilot gets most expensive exactly when you need it most — mid-incident, with a huge slow log. Self-hosted inference is a fixed cost. For a small team, that's the difference between "we can afford this" and "we'll just page the DBA."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Niche tuning beats general purpose.&lt;/strong&gt; A generic cloud model gives generic advice. Because the weights are open, I can — and plan to — fine-tune on real DBA incident reports: MySQL-specific failure modes, version-specific gotchas, the stuff no general-purpose API will ever specialize in. Openness is what lets a one-person side hustle out-depth a vendor's ML team.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This also feeds my existing project: &lt;a href="https://dbcheck.org" rel="noopener noreferrer"&gt;DBCheck&lt;/a&gt;, a free open-source database inspection platform. AI DBA consumes DBCheck's collection packages as input — the inspection finds &lt;em&gt;what's&lt;/em&gt; wrong, the model explains &lt;em&gt;why&lt;/em&gt; and &lt;em&gt;how to fix it&lt;/em&gt;. Open weights make that pipeline possible without either side paying a toll to a third party.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>devchallenge</category>
      <category>hf26challenge</category>
      <category>mysql</category>
    </item>
  </channel>
</rss>
