> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloudthinker.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Tony

> SQLおよびNoSQLプラットフォーム全体でデータベースクエリを最適化し、パフォーマンスをチューニングし、データを分析します。

Tony は CloudThinker のデータベース専門家であり、SQL および NoSQL プラットフォーム全体でクエリ最適化、パフォーマンスチューニング、バックアップ戦略、データ分析を専門としています。

***

## Tony が解決する問題

データベースのパフォーマンスは静かに劣化します。成長するテーブルのインデックス欠落は、P95 レイテンシがスパイクしてエンジニアが深夜 2 時に起こされるまで見えません。コネクションプールの枯渇は、誰かがデータベースを確認するまでアプリケーションのバグに見えます。スロークエリは 1 日に何百回も実行されながらデータベース CPU の 80% を消費しています — クエリ分析とインフラコストを結びつけるシステムがないため、誰も気づきません。

これらの問題を診断・修正するには通常以下が必要です：

* `pg_stat_statements` のクエリや MySQL スロークエリログの有効化
* 実行プラン（EXPLAIN ANALYZE 出力）の読み取りと解釈
* クエリパターンと現在のインデックスの照合
* PostgreSQL/MySQL の設定パラメーターとそのトレードオフの理解

これは高度な専門作業です。ほとんどのチームには専任の DBA がおらず、データベースのパフォーマンス問題は未解決のまま放置されるか、高コストのコンサルタントが必要になります。

***

## 他のツールが見逃すこと

| ツール                          | できること                     | 不足していること                                     |
| ---------------------------- | ------------------------- | -------------------------------------------- |
| **AWS Performance Insights** | データベースの負荷とクエリの待機を可視化      | AWS RDS のみ、解釈に SQL の専門知識が必要、推奨機能なし           |
| **pganalyze**                | PostgreSQL クエリ分析とインデックス推奨 | PostgreSQL のみ、会話型インターフェースなし、依然として DBA の解釈が必要 |
| **Percona Monitoring (PMM)** | オープンソースのデータベース監視          | 複雑なセットアップ、技術的なダッシュボード、AI 分析なし                |
| **Datadog APM**              | アプリケーション + データベーストレースの相関  | 監視のみ、修正推奨なし、大規模では高コスト                        |
| **New Relic / AppDynamics**  | データベースを含むフルスタックの可観測性      | 可視化ツールにすぎず、検出結果への対処に依然として専門家の解釈が必要           |

Tony は監視を超えた存在です。実行プランを読み取り、スキーマのコンテキストを理解し、作成すべき具体的なインデックス、書き直すべきクエリ、行うべき設定変更を平易な言葉で正確に伝えます。

***

## Tony の仕組み

1. **データベースへの接続** — 読み取りアクセス経由。`pg_stat_statements`、MySQL Performance Schema、RDS Performance Insights、Aurora、MongoDB プロファイラーに対応
2. **スロークエリの特定** — 実行時間、呼び出し頻度、リソース消費を分析し、最も影響度の高いターゲットを自動的に発見
3. **実行プランの読み取り** — EXPLAIN ANALYZE 出力を解釈し、テーブルスキャン、インデックスミス、結合の非効率を把握
4. **精度の高い推奨** — 具体的な `CREATE INDEX` ステートメント、クエリの書き換え、設定変更を前後の影響見積もりとともに生成
5. **トレードオフの理解** — 新しいインデックスの書き込みオーバーヘッド、設定変更のメモリへの影響、スキーマ変更のダウンタイム要件を考慮

***

## 機能

| ドメイン              | 機能                                      |
| ----------------- | --------------------------------------- |
| **クエリ最適化**        | SQL 分析、実行プラン、インデックス推奨、クエリの書き換え          |
| **パフォーマンスチューニング** | コネクションプーリング、設定最適化、ボトルネック特定              |
| **データ分析**         | 使用パターン、トレンド分析、キャパシティプランニング、メトリクス可視化     |
| **オペレーション**       | バックアップ/リカバリ、レプリケーション、メンテナンス、ディザスタリカバリ計画 |

***

## 対応プラットフォーム

| カテゴリ          | プラットフォーム                                   |
| ------------- | ------------------------------------------ |
| **リレーショナル**   | PostgreSQL、MySQL、MariaDB、SQL Server、Oracle |
| **クラウドマネージド** | AWS RDS、Aurora、Azure SQL、Cloud SQL         |
| **NoSQL**     | MongoDB、Redis、DynamoDB、DocumentDB          |
| **アナリティクス**   | Redshift、BigQuery、Snowflake                |

***

## プロンプトパターン

### クエリ分析

```text theme={null}
# スロークエリ調査
@tony analyze slow queries on production PostgreSQL

# 特定のパフォーマンスターゲット
@tony identify queries with execution time >2 seconds on orders database

# 実行プラン分析
@tony analyze execution plans for the 20 slowest queries

# クエリパターン
@tony find queries that could benefit from caching
```

### パフォーマンス最適化

```text theme={null}
# インデックス推奨
@tony analyze missing indexes that would improve performance by >10%

# 接続最適化
@tony review connection pooling configuration for high-load scenarios

# 設定チューニング
@tony optimize MySQL 8.0 configuration for high-throughput OLTP with 10k connections

# リソース分析
@tony identify queries consuming >5% of total database CPU
```

### データベースヘルス

```text theme={null}
# ヘルスチェック
@tony check database health and performance metrics

# レプリケーション状況
@tony assess replication lag and recommend optimization

# ストレージ分析
@tony analyze database growth patterns and recommend archiving strategy

# 接続分析
@tony analyze connection usage patterns and identify connection leaks
```

### バックアップとリカバリ

```text theme={null}
# バックアップ検証
@tony verify backup status and recovery procedures for production databases

# DR 計画
@tony create disaster recovery plan with RTO/RPO analysis

# リカバリテスト
@tony recommend backup testing strategy for production databases
```

***

## ツールの使い方

| ツール          | Tony のユースケース                             |
| ------------ | ---------------------------------------- |
| `#dashboard` | クエリレイテンシ（P50/P95/P99）、接続数、I/O、レプリケーションラグ |
| `#report`    | パフォーマンス分析、最適化推奨、キャパシティプランニング             |
| `#recommend` | インデックス変更、設定更新、クエリの書き換え                   |
| `#alert`     | スロークエリ、コネクションプール枯渇、レプリケーションラグ            |
| `#chart`     | クエリのトレンド、リソース使用率、成長パターン                  |

### ツールを使った例

```text theme={null}
@tony #dashboard database performance metrics for production cluster
@tony #report query performance analysis with optimization plan
@tony #recommend index optimizations prioritized by impact
@tony #alert when P95 query latency exceeds 500ms
```

***

## 効果的なプロンプト

**ヒント：メトリクスを含める**

```text theme={null}
# 良い例
@tony analyze queries with
execution time >2 seconds
running >100 times daily

# 避けるべき例
@tony make database faster
```

**ヒント：プラットフォームを指定する**

```text theme={null}
# 良い例
@tony optimize MySQL 8.0
for read-heavy workloads
with 10k concurrent connections

# 避けるべき例
@tony check the database
```

***

## 接続要件

Tony はパフォーマンスメトリクスへのアクセスを持つデータベース接続を必要とします：

| プラットフォーム       | 必要なアクセス                                  |
| -------------- | ---------------------------------------- |
| **PostgreSQL** | `pg_stat_statements`、クエリログ、パフォーマンススキーマ   |
| **MySQL**      | Performance Schema、スロークエリログ、ステータス変数      |
| **RDS/Aurora** | Enhanced Monitoring、Performance Insights |
| **MongoDB**    | プロファイラー、`serverStatus`、オペレーションログ         |

***

## 代表的なワークフロー

### パフォーマンス危機対応

```text theme={null}
# Step 1: 特定
@tony identify top 10 slowest queries in last hour

# Step 2: 分析
@tony analyze execution plans for problematic queries

# Step 3: 最適化
@tony #recommend index changes and query rewrites

# Step 4: 監視
@tony #dashboard real-time query performance
```

### プロアクティブな最適化

```text theme={null}
# Step 1: ベースライン
@tony #dashboard current performance metrics

# Step 2: 分析
@tony identify optimization opportunities across all databases

# Step 3: 優先順位付け
@tony #recommend optimizations ranked by impact and effort

# Step 4: 自動化
@tony #schedule weekly performance review
```

### キャパシティプランニング

```text theme={null}
# Step 1: 成長分析
@tony analyze database growth patterns over last 6 months

# Step 2: 予測
@tony predict storage and compute needs for next year

# Step 3: 計画
@tony #recommend scaling strategy with cost analysis
```

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="PostgreSQL 接続" icon="https://mintcdn.com/cloudthinker/aLd-ttc-SCW-aFky/images/icons/postgresql.svg?fit=max&auto=format&n=aLd-ttc-SCW-aFky&q=85&s=8bb2ac033d0a2ccbef51154a76e1e819" href="/ja/guide/connections/postgresql" width="24" height="24" data-path="images/icons/postgresql.svg">
    Tony を PostgreSQL データベースに接続する
  </Card>

  <Card title="MySQL 接続" icon="https://mintcdn.com/cloudthinker/aLd-ttc-SCW-aFky/images/icons/mysql.svg?fit=max&auto=format&n=aLd-ttc-SCW-aFky&q=85&s=29b74ea2b3ffacd21682ca898f6a2e43" href="/ja/guide/connections/mysql" width="24" height="24" data-path="images/icons/mysql.svg">
    Tony を MySQL データベースに接続する
  </Card>

  <Card title="Deep Response Engine" icon="triangle-exclamation" href="/ja/guide/incident/overview">
    Tony がデータベース関連インシデントを自動調査する方法
  </Card>

  <Card title="Anna" icon="users" href="/ja/guide/agents/anna">
    インフラ + データベースのコスト最適化に向けて Tony と [Alex](/ja/guide/agents/alex) を連携させる
  </Card>
</CardGroup>
