What database incidents AI agents can handle, and what humans must decide
公開日 2026-08-13 · 更新日 2026-08-13 · 最終検証日 2026-08-13
結論
AI agents excel at detection and triage: continuous monitoring and correlation, and firing off a battery of standard diagnostic queries to gather facts, can be automated. Initial response is conditional, limited to actions whose impact is reversible and whose scope is tightly bounded. Permanent remediation and configuration changes require human judgment, for three reasons: the irreversibility of the action, the difficulty of estimating blast radius, and the fact that "stop the service or keep running slow" is a business decision, not a technical one.
この文書の適用条件
| 対象製品 | SQL Server / MySQL / Aurora MySQL (triage query targets) |
|---|---|
| 確認バージョン | SQL Server 2012+, MySQL 5.7 / 8.0, and Aurora MySQL 2 / 3 |
| 適用環境 | On-premises, EC2, Amazon RDS, Aurora, Azure |
| 必要権限 | SQL Server requires `VIEW SERVER STATE`. MySQL requires the `PROCESS` privilege. `KILL` additionally requires the equivalent of `ALTER ANY CONNECTION` |
| 実行影響 | Triage queries are read-only. The `KILL` example makes a change and requires human approval |
| 再起動 | Not required |
| 最終検証日 | 2026-08-13 |
そのまま実行できるコマンド
- 対象
- SQL Server 2012+ / Amazon RDS for SQL Server / Azure SQL Managed Instance
- 権限
- VIEW SERVER STATE
- 変更作業
- None (read-only)
- Production実行
- Safe to run
-- 対象: SQL Server 2012 以降 / Amazon RDS for SQL Server
-- 権限: VIEW SERVER STATE
-- 変更作業: なし(参照のみ)
-- Production 実行: 可能
SELECT
r.session_id,
r.blocking_session_id, -- 0 以外なら、この値のセッションに待たされている
r.status,
r.command,
r.wait_type,
r.wait_time AS wait_time_ms,
r.wait_resource,
DB_NAME(r.database_id) AS database_name,
s.login_name,
s.host_name,
s.program_name,
r.total_elapsed_time AS elapsed_ms,
SUBSTRING(t.text, 1, 500) AS sql_text
FROM sys.dm_exec_requests AS r
INNER JOIN sys.dm_exec_sessions AS s
ON r.session_id = s.session_id
OUTER APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE r.blocking_session_id <> 0
OR r.session_id IN (
SELECT blocking_session_id
FROM sys.dm_exec_requests
WHERE blocking_session_id <> 0
)
ORDER BY r.wait_time DESC;The head of a blocking chain is the session you reach by following `blocking_session_id` until you hit one that isn't itself waiting on anyone. Killing a session in the middle of the chain won't resolve it. Note that if the session doing the blocking isn't currently executing, it won't show up in `sys.dm_exec_requests` — check its state in `sys.dm_exec_sessions` as well.
- 対象
- MySQL 5.7 / 8.0, Aurora MySQL 2 / 3
- 権限
- PROCESS privilege (needed to see other users' sessions)
- 変更作業
- None (read-only)
- Production実行
- Safe to run
-- 対象: MySQL 5.7 / 8.0 系、Aurora MySQL 2 / 3
-- 権限: PROCESS 権限
-- 変更作業: なし(参照のみ)
-- Production 実行: 可能
SELECT
trx.trx_id,
trx.trx_state,
trx.trx_started,
TIMESTAMPDIFF(SECOND, trx.trx_started, NOW()) AS trx_age_sec,
trx.trx_mysql_thread_id AS thread_id,
trx.trx_rows_locked,
trx.trx_rows_modified, -- 大きいほどロールバックに時間がかかる
p.user,
p.host,
p.db,
p.command,
p.time AS thread_time_sec,
p.state,
LEFT(COALESCE(trx.trx_query, p.info), 500) AS current_sql
FROM information_schema.INNODB_TRX AS trx
LEFT JOIN information_schema.PROCESSLIST AS p
ON p.ID = trx.trx_mysql_thread_id
ORDER BY trx.trx_started ASC;
-- 補助: トランザクションを持たない接続も含めて全体を見る
SHOW FULL PROCESSLIST;If `trx_state` is `RUNNING` but `current_sql` is empty, the transaction is open but no query is currently flowing through it — suspect a missing commit on the application side, or a connection held open by a connection pool. `trx_rows_modified` is useful for estimating rollback duration.
- 対象
- SQL Server 2012+ / MySQL 5.7+ · Aurora MySQL
- 権限
- SQL Server: ALTER ANY CONNECTION (or `sysadmin` / `processadmin`). MySQL: equivalent of CONNECTION_ADMIN
- 変更作業
- Yes (forcibly terminates a running session and rolls back its transaction)
- Production実行
- Only with human approval
-- 対象: SQL Server 2012 以降 / MySQL 5.7 以降・Aurora MySQL
-- 権限: SQL Server は ALTER ANY CONNECTION、MySQL は CONNECTION_ADMIN 相当
-- 変更作業: あり(セッションの強制終了とトランザクションのロールバック)
-- Production 実行: 人間の承認を得た場合のみ
-- 実行前に、以下の6項目すべてを確認する。1つでも未確認なら実行しない。
-- 1. 対象がブロッキング連鎖の起点か(他に待たされていないセッションか)
-- 2. そのセッションが何をしているか(定常のアプリ処理・バッチ・DDL のいずれか)
-- 3. ロールバックの想定時間(更新行数が多いほど長く、その間ロックは解放されない)
-- 4. 呼び出し元が再試行するか。しない場合、業務データが欠落しないか
-- 5. 止める代わりに待つ選択肢が取れないか(業務側の許容時間の確認)
-- 6. 承認者は誰か。実行の記録をどこに残すか
-- SQL Server: セッションIDを指定(値はサンプル)
KILL 57;
-- ロールバックの進捗を確認する(KILL 後に実行する参照専用クエリ)
-- KILL 57 WITH STATUSONLY;
-- MySQL / Aurora MySQL: PROCESSLIST の ID を指定(値はサンプル)
-- KILL 12345;`KILL` triggers a rollback. For transactions with many modified rows, the rollback can take longer than the original operation did, and locks stay held the entire time. The fact that "killing it" doesn't guarantee a faster resolution is the main reason this cannot be put on the auto-execution path. On SQL Server, `KILL <spid> WITH STATUSONLY` shows rollback progress.
結果の読み方
| 列 | 意味 | 確認するポイント |
|---|---|---|
| Detection | Noticing that something abnormal is happening | AI's strength. Continuous monitoring, threshold breach detection, correlating multiple metrics, matching against past patterns |
| Triage | Gathering facts to narrow down the cause | AI's strength. Firing off standard read queries in bulk and cross-referencing the results to establish the facts |
| Initial response | Stopping or mitigating the impact | Conditional. Only actions that are reversible and scoped to an allowlisted target. Everything else needs human approval |
| Permanent remediation / config changes | Changing the system so it doesn't recur | Requires human judgment. Schema changes, parameter changes, and config changes all involve estimating blast radius |
| Postmortem | Recording what happened and deciding on countermeasures | AI drafts, human finalizes. Assembling the timeline and logs can be automated; determining root cause and deciding countermeasures is done by a person |
| blocking_session_id | The ID of the session this session is waiting on | Follow non-zero values to find the session that isn't waiting on anyone — the head of the chain |
| wait_type / state | What the session is waiting for | Whether it's a lock wait, I/O wait, or CPU wait determines where to look next |
| trx_rows_modified | Number of rows the transaction has modified | Larger values mean longer rollbacks — a key input for the `KILL` decision |
| trx_age_sec / elapsed_ms | Elapsed time of the transaction | Transactions open for a long time suggest a missing commit or a connection held by a pool |
| program_name / host | Connection origin | Whether activity is concentrated in one app or batch job — concentration points directly to the cause |
こういう状況で使います
- Application timeouts have spiked, and it isn't yet clear whether the database is the cause
- Updates to one specific table are stuck waiting
- An incident that happened overnight went unnoticed until it was discovered the next morning
- Monitoring is in place, but there are too many alerts to tell which one is real
- Every incident, the responder has to recall which queries to run from memory
- We want AI to handle initial response, but we haven't drawn the line on how far to let it go
考えられる原因(可能性の高い順)
01
Detection exists, but triage depends on what responders remember
If the queries to check aren't organized into a procedure, the facts gathered vary by responder. This is the part of the process that's easiest to automate.
02
Whether initial response is allowed was never decided in advance
Without a clear answer to "which actions are safe to run automatically," teams end up either pushing everything back to manual (to stay safe) or, conversely, automating actions that are genuinely dangerous.
03
Irreversible actions are treated the same as reversible ones
Killing a session, deleting data, and reinitializing replication are all called "responses," but they differ wildly in how easy they are to undo. Treating them the same leads to incidents.
04
No one has the authority to decide on a shutdown
Whether to stop the service to prioritize recovery, or keep running slow, is a business call. Without a designated decision-maker, technical staff end up shouldering that decision themselves, which delays response.
確認手順
- 1
Check the blocking chain
参照のみUse the read-only query above to list waiting and blocking sessions, and identify the head of the chain.
- 2
Check active sessions and their origin
参照のみLook for concentration in a particular application or host. If found, check that application's recent changes.
- 3
Tally wait events
参照のみDetermine whether lock waits, I/O waits, or CPU waits dominate — this determines where to look next.
- 4
Check transaction log usage
参照のみIf the log runs out of free space, all write activity halts. Check whether a long-running transaction is preventing log reuse.
- 5
Check replication lag
参照のみIf read traffic is routed to a replica, lag causes business impact. Check the size of the lag and whether it's increasing.
- 6
Check recent changes
参照のみCheck whether a deployment, new batch job, or parameter change happened just before the incident. A matching timeline is a strong clue.
対応方法
すぐに実施できる低リスクの対応
Fix a set of triage queries as a standard procedure
参照のみList out the queries to run during an incident so an agent can run them all automatically in one batch. Since they're read-only, automating them has no downside.
Auto-generate a summary of the facts
参照のみOrganize the collected results chronologically into something a responder can read. State facts and observations only — don't draw conclusions.
Document who has the authority to decide on a shutdown
低Write down, at the top of the response procedure, who makes the call when a decision involves stopping the service — so no one has to go looking for them during an incident.
事前検討が必要な変更
Define which initial-response actions may run automatically
中List out reversible, narrowly-scoped actions (read-only checks, cache reload, detaching a read replica, etc.) and require approval for everything else.
Automate the postmortem draft
低Automatically assemble the timeline, collected observations, and actions taken — leave root-cause determination and countermeasure decisions to a human.
Align monitoring targets with what "the service is working" actually means
中Add monitoring that checks whether the real request path is functioning, not just whether the process is alive.
専門家のレビューが必要な作業
Terminate the session at the head of the blocking chain
専門家レビュー必須This triggers a rollback, which can take longer than the original operation depending on how many rows were modified. Confirm all 6 items above and get approval before running it.
Fail over to a replica
専門家レビュー必須Failing over to a lagging replica can cause data loss. Check the lag amount and business requirements, and let a human make the call.
Apply a permanent fix via configuration or parameter changes
専門家レビュー必須Requires estimating blast radius and having a rollback procedure ready. Making changes during an active incident can itself become a new source of failure.
!注意事項
- Operations an AI agent must never run without human approval: deleting data, `KILL`, `SHRINK`, forced failover, reinitializing replication, reconfiguring CDC, full index rebuilds, large-scale statistics updates, parameter changes, schema changes, restarting the DB, firewall and permission changes, resetting binlogs, deleting backups.
- There are three reasons for this line. First, irreversibility — some actions can't be undone after the fact, or undoing them requires a separate recovery effort. Second, blast-radius estimation is hard — the impact can spread to connected systems beyond the target database. Third, "stop the service or keep running slow" is a business decision, not a technical one, and technical correctness alone can't settle it.
- `KILL` doesn't always improve the situation. It triggers a rollback, and if many rows were modified, that rollback can take longer than the original operation — and locks stay held the whole time.
- Making configuration changes during active incident response can itself become a new source of failure. Do permanent remediation after recovery, once you've investigated impact and prepared a rollback procedure.
- Even read-only queries may fail to return on an instance under extreme load. Limit the amount of data you pull and set a timeout.
- A cause AI proposes is a hypothesis. Leave the final postmortem determination and countermeasure decisions to a human.
バージョン・環境による違い
これで解決しない場合に確認すること
Check how long recent incidents took from detection to completed triage
If most of that time was spent "remembering what to check," triage automation will help.
Classify the actions taken during initial response as reversible or irreversible
If an irreversible action was run without approval, that's your next incident waiting to happen.
Confirm who has authority over the shutdown decision
Check whether it's also decided what happens during hours when that person is unavailable.
Check your alerts' accuracy
Count what fraction of recent alerts actually required a response. If it's low, real anomalies get buried.
Check whether postmortem records actually get referenced during the next incident
If they aren't being read, reconsider the format or where they're stored.
この文書の根拠と限界
一般的な技術説明
The triage queries are based on the published specifications of SQL Server's dynamic management views and MySQL's `information_schema`. The phase boundaries reflect a general operational design based on reversibility and blast radius. Only the "GIIP's scope" paragraph describes GIIP's own operating model — it is not a customer case study. Recovery time, incident counts, automation rates, and similar figures are not included because they cannot be verified.
よくある質問
How far can we let an AI agent go in incident response?
It can own detection and triage. Initial response is limited to actions that are reversible and explicitly scoped. Permanent remediation, configuration changes, and the decision to stop the service must be made by a human.
Why shouldn't `KILL` be run automatically?
Because it triggers a rollback that, depending on how many rows were modified, can take longer than the original operation — and locks stay held the whole time, which can make things worse. On top of that, if the caller doesn't retry the killed operation, business data can be lost.
What specifically should a human expert handle?
Deciding whether to run irreversible actions, whether to stop the service, judgment calls where impact spans multiple systems, designing permanent remediation, and finalizing the postmortem. None of these are settled by technical correctness alone — business impact and accountability are involved.
Can the triage queries be run in production?
The first and second queries in this article are read-only and safe to run. That said, on an instance under extreme load they may not return — limit the row count and set a timeout. The third query, `KILL`, makes a change and requires approval.
What do we need in place to automate initial response?
An allowlist of targets, pre-change snapshots, a rollback procedure, audit logging, and a kill switch. Don't put any action on the auto-execution path until all of these are in place.
Can we just take AI-proposed causes at face value?
Treat them as a hypothesis. Organizing the collected facts can be automated, but determining root cause is affected by factors that weren't observed. The right model is AI drafts the postmortem, and a human finalizes it.
この文書がカバーする質問
- What should human experts be responsible for in AI operations
- Is it safe to let an AI agent handle initial database incident response
- What queries should I run first during a database incident
リスク表示の意味
- 参照のみデータと設定を変更しません。
- 低影響は限定的ですが、権限と負荷の確認が必要です。
- 中性能・ロック・コストに影響する可能性があります。
- 高障害・データ損失・復旧作業が発生する可能性があります。
- 専門家レビュー必須本番適用前に別途レビューが必須です。
GIIPの対応範囲
The phase breakdown and the lines drawn above can be implemented in-house without any specific product. At GIIP, AI agents and human experts continuously monitor and operate multiple databases and roughly 30 web services across AWS and Azure; AI agents handle detection and triage, while the irreversible operations and shutdown decisions listed above are executed only after a human operator approves them. If it's hard to judge which actions count as reversible when drawing your own line, that can be worked out from your current setup and past incident records.
執筆・技術検証
GIIP プロダクション運用チーム
大規模Webサービス、SQL Server、Oracle、AWS、Azureの設計・移行・運用に約30年従事。x12largeクラスのAWS RDS for SQL Server環境12セット、約12万テーブルのOracle環境、約3TBのTiDBからAurora MySQLへの移行を経験。現在も複数のクラウドデータベースと約30のWebサービスを、AIエージェントと人間の専門家が継続的に監視・運用しています。
SQL to Check for Long-Running Open Transactions in SQL Server
A procedure using the sys.dm_tran_active_transactions family of DMVs to identify abandoned transactions, including start time, session, and the last SQL statement executed.
aurora-mysqlHow to Investigate a Slow Query in Aurora MySQL
A procedure for finding slow queries by starting with lower-risk checks, in the order: slow query log, PROCESSLIST, EXPLAIN, and digest aggregation. Also shows alternatives for environments where performance_schema is disabled.
monitoringWhat to Configure When Monitoring Servers and Databases 24/7
A checklist, organized by layer, of what to monitor, how to think about thresholds, the escalation structure, and why synthetic monitoring is necessary when designing 24/7 monitoring.
ai-operationsWhy AI automated execution needs approval and rollback, and how to design for it
Design elements for automated execution — snapshots, approval gates, dry-run separation, allowlists, idempotency, audit logs, staged rollout, and a kill switch — are summarized, along with where to draw the line on what can run without approval.
関連サービス
Work out where to draw the line for initial incident response
同じ確認を複数の環境で継続する必要がある場合は、運用体制ごと相談できます。
Work out where to draw the line for initial incident response