Hi all, this week I tried to hand my Oracle morning check to an AI agent. The deal was simple: at 07:00, before my first coffee, the agent runs the checks I normally run by hand, a local model reads the results like a DBA would, and the report lands in my mailbox. No cloud, no API key, not one row leaving the laptop.
It worked. The mail really did arrive at 07:10 this morning with nobody at the keyboard. But the AI also told me SYSTEM was full (it was at 0 %) and on the first run it completely ignored that the database had no backup. So this post is the honest version: how I built it, what I expected, what actually came back, and what I'd do better.
1. The test environment, command by command
Everything runs on one Windows laptop (15 GB RAM, no GPU). If you already have an Oracle database you can skip the first line.
| Piece | What I used | How to get it |
|---|---|---|
| Database | Oracle AI Database 26ai Free (23.26.3) in Docker | gvenzl/oracle-free image, port on 127.0.0.1 only |
| Python | 3.12 + oracledb (thin mode, no Oracle Client), requests, keyring | winget install Python.Python.3.12 |
| Local AI | Ollama + gemma3:4b (about 3 GB) | winget install Ollama.Ollama |
| Mailpit (a fake SMTP server with a web inbox) | Docker | |
| Schedule | Windows Task Scheduler, daily 07:00 | built in |
The database and the mail server:
docker run -d --name oracle-free --restart unless-stopped -p 127.0.0.1:1521:1521 ^
-e ORACLE_PASSWORD=<your password> gvenzl/oracle-free:23.26.3
docker run -d --name mailpit --restart unless-stopped ^
-p 127.0.0.1:8025:8025 -p 127.0.0.1:1025:1025 axllent/mailpit
Port 1025 takes the mail, http://localhost:8025 shows the inbox. On a real server you point the agent at your company relay instead.
The model, once:
ollama pull gemma3:4b
The project folder and the Python environment:
morning-agent\
agent\checks.py the ten checks: id, title, one SELECT each
agent\agent.py collect -> rate -> ai_review -> report -> send_mail
config.json database, model, mail settings
requirements.txt oracledb, requests, keyring
run-agent.ps1 what Task Scheduler calls
py -3.12 -m venv .venv
.\.venv\Scripts\pip install -r requirements.txt
A read-only account for the agent. First surprise of the day: the alert log check failed with ORA-00942, because V$DIAG_ALERT_EXT isn't covered by SELECT_CATALOG_ROLE. One extra grant fixed it:
create user dba_morning identified by "<a strong password>";
grant create session, select_catalog_role to dba_morning;
grant select on sys.v_$diag_alert_ext to dba_morning;
The password goes into Windows Credential Manager, never into a file:
.\.venv\Scripts\python -c "import keyring, getpass; keyring.set_password('oracle-morning-agent', 'DBA_MORNING', getpass.getpass())"
And the 07:00 schedule (hidden window, 3 retries 5 minutes apart, 1 hour max):
$a = New-ScheduledTaskAction -Execute powershell.exe -Argument '-WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File "C:\lab\morning-agent\run-agent.ps1"' -WorkingDirectory "C:\lab\morning-agent"
$t = New-ScheduledTaskTrigger -Daily -At 07:00
$s = New-ScheduledTaskSettingsSet -StartWhenAvailable -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 5) -ExecutionTimeLimit (New-TimeSpan -Hours 1)
Register-ScheduledTask "Oracle Morning Check Agent" -Action $a -Trigger $t -Settings $s
One design decision I made early and still like: the model never picks the colour. Fixed rules in Python decide OK / WARN / CRIT (95 % full is critical because a rule says so). The AI only explains, links findings and suggests what to do first. The model call is one POST to Ollama's /api/chat with format: json, temperature 0.2 and an 8K context.
2. What we tested
A morning check on a healthy lab is boring, so I built a small city parking app called PARKSYS and broke it on purpose overnight:
- a 64 MB tablespace (PARK_DATA) filled to 98.9 %
- a release that drops a column the PARK_BILLING package still reads, so the package body goes INVALID
- two night jobs: PAYMENT_IMPORT fails with ORA-01654, NIGHTLY_SETTLEMENT with ORA-04063
- a purge of 100,799 rows that leaves the statistics stale
- a POS gateway session that updates a parking meter and never commits
- no RMAN backup, and the database in NOARCHIVELOG mode
The broken night is three scripts from the repo:
sql sys@localhost:1521/FREE as sysdba
SQL> @lab/01-parksys-setup.sql -- PARKSYS schema, tablespace, package, two scheduler jobs
SQL> @lab/02-overnight-incidents.sql -- dropped column, failed jobs, full tablespace, big purge
python lab/hold_lock.py -- POS gateway session that never commits (leave it running)
The ten checks: instance, tablespaces, alert log, failed scheduler jobs, invalid objects, overnight DDL, RMAN backups, blocked sessions, stale statistics, sessions. I ran the agent three times, changing one thing each time.
3. What I expected vs. what came back
| Problem in the lab | What a DBA should say | Run 1 (plain prompt) | Run 2 (DBA notes in prompt) | Run 3 (self-check loop) |
|---|---|---|---|---|
| PARK_DATA 98.9 % | Add space before the import runs again | Found it, but also called XPT_TS (34 %) "concerning" | Found | Found, but added "SYSTEM is also full" (it's 0 %) |
| NIGHTLY_SETTLEMENT ORA-04063 | Invalid package, caused by the dropped column | Blamed on space (wrong) | Linked to PARK_BILLING (right) | Right |
| PAYMENT_IMPORT ORA-01654 | Tablespace full | Right | Right, but said stale stats caused it (wrong) | Right, but "restart the jobs" before adding space |
| No backup + NOARCHIVELOG | The most dangerous line: no point-in-time recovery | Not mentioned at all | Skipped again | Covered after the re-ask |
| Blocked session | Name both sessions | "10 seconds" (only the wait when it looked) | Skipped | Both sessions named, 15 min idle POS gateway |
| Overnight DDL | The PAYMENTS table changed | (check not there yet) | Skipped | Only mentioned the package, not the table |
| Findings vs. problems | 8 of 8 | partial | 5 of 8 | 8 of 8 |
| Model time | 321 s | 399 s | 374 s + 216 s follow-up |
The SQL part takes about six seconds every time. The model takes five to ten minutes on a laptop CPU, which is fine for a job that runs at 07:00. The real scheduled run this morning started at 07:00:01, the self-check re-asked about four skipped checks, and the mail went out at 07:10:47.
4. Where it went wrong, and how it could be better
A 4B model doesn't follow every rule. In run 2 the prompt said in capital letters "write one finding for every check that isn't OK", and it still dropped three red checks. Writing more rules didn't fix it. Checking the answer in code did: every non-OK check must have a finding, if one is missing the agent asks again only about those checks, and if it still says nothing the report says "The AI gave no comment" on that card. A red check is never hidden.
Brief it like a junior DBA. The jump from run 1 to run 2 came from a few plain DBA sentences in the prompt: read each job error on its own, ORA-04063 means invalid code so look at what changed overnight, no backup plus NOARCHIVELOG means no point-in-time recovery. Plus one new check for objects with DDL in the last 24 hours.
It still invents things. SYSTEM at 0 % became "full". It missed that the PAYMENTS table was the thing that actually changed, so its "recompile" advice wouldn't fix a column that's gone. That's why every report ends with the raw SQL rows and a line saying the AI can be wrong. I read it like a mail from a new colleague: very useful for the first five minutes, and every number gets checked against the raw table before I touch anything.
What I'd do differently: a bigger local model if the machine has a GPU, and a second prompt that only checks the first answer against the raw rows. For a real server: the company relay with TLS (smtp_starttls: true), a list of databases in the config, and keeping old reports so today can be compared with yesterday.
Security, the short version: its own read-only account (catalog role + one grant), the password in Credential Manager, the model running locally, and the agent never fixes anything. It reports. I decide.
5. What I'd take from this, and what would be worth testing later
My conclusion after three runs: the agent is worth keeping, but only with fixed rules for the colours, a self-check in code and the raw rows in every report. A few things would be worth testing at some point, because they'd tell us more than another run on the same laptop:
- A larger local model with a GPU. It would show whether the three mistakes come from the model size or from the prompt.
- Data Guard lag and FRA usage as extra checks (one entry each in
checks.py). - Several databases in one morning mail, with a "what changed since yesterday" section.
If you build your own, tell me which check you added first. Mine would be the backup one, after this week.
Comments
Post a Comment