DEV Community

slawekluzny
slawekluzny

Posted on Originally published at sentinel-ai.info

How Sentinel's Database Autopilot Decides What to Fix (And When to Leave Things Alone)

How Sentinel's Database Autopilot Decides What to Fix (And When to Leave Things Alone)

Letting software change your production database is a big ask. So this post is deliberately concrete: what Sentinel's Index Autopilot for MySQL actually looks at, the exact conditions under which it changes anything, and the long list of things it will never touch on its own.

Step 1: Reading the slow query log

Everything starts from MySQL's own slow query log. When the log is enabled and you open Sentinel's Optimizations page, Sentinel parses it, reading each entry's query time, rows sent and rows examined.

Similar queries are grouped together: string and number literals are replaced with a placeholder and whitespace is normalised, so WHERE id = 17 and WHERE id = 42 count as the same query. Anything that touches MySQL's own system schemas — information_schema, performance_schema, mysql, sys — is skipped entirely.

Step 2: Asking MySQL why a query is slow

For each slow query, Sentinel runs MySQL's EXPLAIN and reads the plan. It's looking for a small set of well-understood problems:

  • A missing index — the query scans when it could look up.
  • A filesort (Using filesort) — rows sorted after the fact, often fixable with the right index.
  • A temporary table (Using temporary).
  • A large full table scan — a full scan (type=ALL) over more than 100,000 rows.
  • A composite index opportunity — several columns filtered together that one multi-column index would serve.
  • Redundant conditions — the same condition on the same column repeated in one query.

Where an index would help, Sentinel stores a concrete CREATE INDEX suggestion. Where it wouldn't — a temporary table, say — it records the diagnosis and leaves the fix to you.

Step 3: When the autopilot acts

Suggestions on their own change nothing. Index Autopilot is a per-connection toggle, and it's off until you turn it on. When it is on, a background job runs every 30 minutes and applies a suggestion only when all of these are true:

  • Index Autopilot is enabled on that database connection;
  • the global Service Mode switch is off (Service Mode pauses automation while you do maintenance);
  • the suggestion is new;
  • it's one of three index types: a missing index, a filesort fix, or a multi-column index.

Then table size decides when:

  • Under 10,000,000 rows: the index is created straight away.
  • 10,000,000 rows or more: it's scheduled for the night window, 03:00–05:00, and Sentinel raises a WARNING alert so you know it's coming.

Every applied or scheduled index goes into the Activity Log, together with per-cycle counts of suggestions seen, applied and failed.

What it will never do on its own

This list matters more than the previous one. The autopilot will not:

  • drop an index;
  • change MySQL server settings, such as innodb_buffer_pool_size;
  • run OPTIMIZE TABLE — that's only ever proposed, when fragmentation exceeds 20%, and run manually.

Adding an index is the one action it takes, because it's the one that is additive and easy to undo.

DB Doctor: the read-only check-up

Alongside the autopilot, DB Doctor gives a health check without changing anything. It reads metadata only — SHOW GLOBAL STATUS, information_schema and EXPLAIN — with a 5-second connection timeout, and flags:

  • an InnoDB buffer pool hit rate below 95%;
  • more than 10% of temporary tables spilling to disk (with advice to review tmp_table_size, max_heap_table_size and large GROUP BY / ORDER BY queries);
  • transactions running longer than 60 seconds;
  • table fragmentation above 20%.

Database security, too

Performance isn't the only thing in the logs. Sentinel can install a Fail2Ban jail for MySQL that bans IP addresses after repeated failed logins, and it separately reads the MySQL error log for Access denied lines, raising an incident when one IP racks up ten or more failures.

The design in one sentence

Read what MySQL already reports, ask MySQL itself why a query is slow, automate only the one change that's additive and reversible — and only when you've switched it on.

Basic tier: free for one server — sign up at sentinel-ai.info/pricing for the one-line install command.

Top comments (0)