

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 CloudWatch Database Insights 監控 Amazon RDS 資料庫
<a name="USER_DatabaseInsights"></a>

使用 Database Insights 監控 Amazon RDS 資料庫執行個體機群的資料庫負載 (資料庫負載)。資料庫負載會測量資料庫中工作階段活動的層級。您可以使用 Database Insights 大規模分析 Amazon RDS 資料庫的效能，並進行疑難排解。

利用 Database Insights，您可以將資料庫機群的資料庫負載視覺化，並依等候、SQL 陳述式、主機或使用者篩選負載。

根據預設，RDS 會為您的 Amazon RDS 資料庫啟用 Database Insights 的標準模式。

如需在 Amazon CloudWatch 主控台中使用 Database Insights 的詳細資訊，請參閱《Amazon CloudWatch 使用者指南》**中的 [CloudWatch Database Insights](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Database-Insights.html)。

## 定價
<a name="USER_Database-Insights-pricing"></a>

如需有關定價的資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

**Topics**
+ [定價](#USER_Database-Insights-pricing)
+ [Database Insights 的 Amazon RDS 資料庫引擎、區域和執行個體類別支援](USER_DatabaseInsights.Engines.md)
+ [開啟適用於 Amazon RDS 的 Database Insights 的進階模式](USER_DatabaseInsights.TurningOnAdvanced.md)
+ [開啟 Amazon RDS 的 Database Insights 的標準模式](USER_DatabaseInsights.TurningOnStandard.md)
+ [使用 Amazon RDS 的 Database Insights 設定資料庫以監控慢速 SQL 查詢](USER_DatabaseInsights.SlowSQL.md)
+ [Amazon RDS Amazon 資料庫洞見的考量事項](USER_DatabaseInsights.Considerations.md)

# Database Insights 的 Amazon RDS 資料庫引擎、區域和執行個體類別支援
<a name="USER_DatabaseInsights.Engines"></a>

下表提供可支援 Database Insights 的 Amazon RDS 資料庫引擎。


|  Amazon RDS 資料庫引擎  | 支援的引擎版本和區域 | 執行個體類別限制 | 
| --- | --- | --- | 
|  Amazon RDS for MariaDB  |  如需 Database Insights 搭配 RDS for MariaDB 的版本和區域可用性的詳細資訊，請參閱 [Amazon RDS 中的 Performance Insights 的支援區域和資料庫引擎](Concepts.RDS_Fea_Regions_DB-eng.Feature.PerformanceInsights.md)。  |  下列執行個體類別不支援 Database Insights： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.Engines.html)  | 
|  RDS for MySQL  |  如需 Database Insights 搭配 RDS for MySQL 的版本和區域可用性的詳細資訊，請參閱 [Amazon RDS 中的 Performance Insights 的支援區域和資料庫引擎](Concepts.RDS_Fea_Regions_DB-eng.Feature.PerformanceInsights.md)。  |  下列執行個體類別不支援 Database Insights： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.Engines.html)  | 
|  Amazon RDS for Microsoft SQL Server  |  如需 Database Insights 搭配 RDS for SQL Server 的版本和區域可用性的詳細資訊，請參閱 [Amazon RDS 中的 Performance Insights 的支援區域和資料庫引擎](Concepts.RDS_Fea_Regions_DB-eng.Feature.PerformanceInsights.md)。  |  N/A  | 
|  Amazon RDS for PostgreSQL  |  如需 Database Insights 搭配 RDS for PostgreSQL 的版本和區域可用性的詳細資訊，請參閱 [Amazon RDS 中的 Performance Insights 的支援區域和資料庫引擎](Concepts.RDS_Fea_Regions_DB-eng.Feature.PerformanceInsights.md)。  |  N/A  | 
|  Amazon RDS for Oracle  |  如需 Database Insights 搭配 RDS for Oracle 的版本和區域可用性的詳細資訊，請參閱 [Amazon RDS 中的 Performance Insights 的支援區域和資料庫引擎](Concepts.RDS_Fea_Regions_DB-eng.Feature.PerformanceInsights.md)。  |  N/A  | 

## Amazon RDS 資料庫引擎、區域和執行個體類別支援 Database Insights 功能
<a name="database-insights-feature-support"></a>

下表提供可支援 Database Insights 功能的 Amazon RDS 資料庫引擎。


| 功能 | [定價方案](https://aws.amazon.com/rds/performance-insights/pricing/) |  [支援的區域](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html#Concepts.RegionsAndAvailabilityZones.Regions)  |  [支援的資料庫引擎](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html#Welcome.Concepts.DBInstance)  |  [支援的執行個體類別](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.DBInstanceClass.html#Concepts.DBInstanceClass.Types)  | 
| --- | --- | --- | --- | --- | 
| [績效詳情的 SQL 統計數字](sql-statistics.md) | 全部 | 全部 |  全部  | 全部 | 
| [使用 Amazon RDS 的 Performance Insights 儀表板來分析 Oracle 執行計畫](USER_PerfInsights.UsingDashboard.AccessPlans.md) | 全部 | 全部 |  RDS for Oracle  | 全部 | 
| [分析一段時間區間的資料庫效能](USER_PerfInsights.UsingDashboard.AnalyzePerformanceTimePeriod.md) | 僅限付費方案 |  全部  |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.Engines.html)  |  全部  | 
|  [檢視 Performance Insights 主動建議](USER_PerfInsights.InsightsRecommendationViewDetails.md) | 僅限付費方案 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.Engines.html)  |  全部  | 全部  | 

## Amazon RDS 區域支援 Database Insights
<a name="database-insights-region-support"></a>

Amazon RDS 在以下支援 Database Insights AWS 區域。
+ 美國東部 (維吉尼亞北部)
+ 美國東部 (俄亥俄)
+ 美國西部 (加利佛尼亞北部)
+ 美國西部 (奧勒岡)
+ 非洲 (開普敦)
+ 亞太地區 (香港)
+ 亞太區域 (海德拉巴)
+ 亞太地區 (雅加達)
+ 亞太地區 (馬來西亞)
+ 亞太地區 (墨爾本)
+ 亞太地區 (孟買)
+ 亞太區域 (大阪)
+ 亞太區域 (首爾)
+ 亞太區域 (新加坡)
+ 亞太地區 (雪梨)
+ 亞太區域 (東京)
+ 加拿大 (中部)
+ 加拿大西部 (卡加利)
+ 歐洲 (法蘭克福)
+ 歐洲 (愛爾蘭)
+ 歐洲 (倫敦)
+ 歐洲 (米蘭)
+ Europe (Paris)
+ 歐洲 (西班牙)
+ 歐洲 (斯德哥爾摩)
+ 歐洲 (蘇黎世)
+ 以色列 (特拉維夫)
+ Middle East (Bahrain)
+ 中東 (阿拉伯聯合大公國)
+ 南美洲 (聖保羅)
+ AWS GovCloud （美國東部）
+ AWS GovCloud （美國西部）

# 開啟適用於 Amazon RDS 的 Database Insights 的進階模式
<a name="USER_DatabaseInsights.TurningOnAdvanced"></a>

若要開啟 Amazon RDS 的 Database Insights 的進階模式，請使用下列程序。

## 在建立資料庫執行個體或多可用區域資料庫叢集時，開啟 Database Insights 的進階模式
<a name="USER_DatabaseInsights.TurnOnCreateDatabase"></a>

建立 Amazon RDS 的資料庫時，開啟 Database Insights 的進階模式。

------
#### [ Console ]

在此主控台中，您可以在建立資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的進階模式。

**使用主控台建立資料庫執行個體或多可用區域資料庫叢集時，開啟 Database Insights 的進階模式**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 選擇 **Databases** (資料庫)。

1. 選擇**建立資料庫**。

1. 在 **Database Insights** 區段中，選取**進階模式**。然後選擇下列選項：
   + **Retention (保留)** – 保留 Performance Insights 資料的時間。Database Insights 進階模式的保留期間必須為 15 個月。
   + **AWS KMS key** – 指定您的 KMS 金鑰。績效詳情使用您的 KMS 金鑰來加密所有可能的敏感資料。將會對傳輸中與靜態資料進行加密。如需詳細資訊，請參閱[加密 Amazon RDS 資源](Overview.Encryption.md)。

1. 選擇**建立資料庫**。

------
#### [ AWS CLI ]

若要在建立資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的進階模式，請呼叫 [create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html) 或 [create-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-cluster.html) AWS CLI 命令，並提供下列值：
+ `--database-insights-mode advanced` 以開啟 Database Insights 的進階模式。
+ `--engine` – 資料庫執行個體的資料庫引擎。
+ `--db-instance-identifier` – 資料庫執行個體的識別符，或 `--db-cluster-identifier` – 多可用區域資料庫叢集的識別碼。
+ `--enable-performance-insights` 以開啟適用於 Database Insights 的 Performance Insights。
+ `--performance-insights-retention-period` – 資料庫執行個體或多可用區域資料庫叢集的資料保留期間。若要開啟 Database Insights，保留期間必須至少為 465 天。

下列範例會在建立資料庫執行個體時啟用 Database Insights 的進階模式。

針對 Linux、macOS 或 Unix：

```
aws rds create-db-instance \
    --database-insights-mode advanced \ 
    --engine postgresql \
    --db-instance-identifier sample-db-identifier \
    --enable-performance-insights \
    --performance-insights-retention-period 465
```

針對 Windows：

```
aws rds create-db-instance ^
    --database-insights-mode advanced ^ 
    --engine postgresql ^
    --db-instance-identifier sample-db-identifier ^
    --enable-performance-insights ^
    --performance-insights-retention-period 465
```

------
#### [ RDS API ]

若要在建立資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的進階模式，請為 [CreateDBInstance](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html) 或 [CreateDBCluster](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html) Amazon RDS API 操作指定下列參數。
+ `DatabaseInsightsMode` 至 `advanced`
+ `EnablePerformanceInsights` 至 `True`
+ `PerformanceInsightsRetentionPeriod` 到至少 465 天

------

## 在修改資料庫執行個體或多可用區域資料庫叢集時，開啟 Database Insights 的進階模式
<a name="USER_DatabaseInsights.TurnOnModifyDatabase"></a>

修改 Amazon RDS 的資料庫時，開啟 Database Insights。修改資料庫執行個體以啟用 Database Insights 的進階模式不會導致停機時間。

**注意**  
若要啟用 Database Insights，多可用區域資料庫叢集中的每個資料庫執行個體都必須具有相同的 Performance Insights 和增強型監控設定。

------
#### [ Console ]

在此主控台中，您可以在修改資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的進階模式。

**使用主控台修改資料庫執行個體或多可用區域資料庫叢集時，開啟 Database Insights 的進階模式**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 選擇 **Databases** (資料庫)。

1. 選擇一個資料庫執行個體或多可用區域資料庫叢集，然後選擇 **Modify** (修改)。

1. 在 **Database Insights** 區段中，選取**進階模式**。然後選擇下列選項：
   + **Retention (保留)** – 保留 Performance Insights 資料的時間。Database Insights 進階模式的保留期間必須為 15 個月。
   + **AWS KMS key** – 指定您的 KMS 金鑰。績效詳情使用您的 KMS 金鑰來加密所有可能的敏感資料。將會對傳輸中與靜態資料進行加密。如需更多詳細資訊，請參閱 [加密 Amazon RDS 資源](Overview.Encryption.md)。

1. 選擇 **Continue** (繼續)。

1. 在 **Scheduling of Modifications (修改排程)** 中，選擇 **Apply immediately (立即套用)**。如果您選擇**在下一個排定的維護時段套用**，則資料庫會忽略此設定，並立即開啟 Database Insights 的進階模式。

1. 選擇**修改執行個體**。

------
#### [ AWS CLI ]

若要在修改資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的進階模式，請呼叫 [modify-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/modify-db-instance.html) 或 [modify-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/modify-db-cluster.html) AWS CLI 命令，並提供下列值：
+ `--database-insights-mode advanced` 以開啟 Database Insights 的進階模式。
+ `--db-instance-identifier` – 資料庫執行個體的識別符，或 `--db-cluster-identifier` – 多可用區域資料庫叢集的識別碼。
+ `--enable-performance-insights` 以開啟適用於 Database Insights 的 Performance Insights。
+ `--performance-insights-retention-period`：資料庫執行個體的資料保留期間。若要開啟 Database Insights 的進階模式，保留期必須至少為 465 天。

下列範例會在修改資料庫執行個體時啟用 Database Insights 的進階模式。

針對 Linux、macOS 或 Unix：

```
aws rds modify-db-instance \
    --database-insights-mode advanced \
    --db-instance-identifier sample-db-identifier \
    --enable-performance-insights \
    --performance-insights-retention-period 465
```

針對 Windows：

```
aws rds modify-db-instance ^
    --database-insights-mode advanced ^
    --db-instance-identifier sample-db-identifier ^
    --enable-performance-insights ^
    --performance-insights-retention-period 465
```

------
#### [ RDS API ]

若要在修改資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的進階模式，請為 [ModifyDBInstance](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_ModifyDBInstance.html) 或 [ModifyDBCluster](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_ModifyDBCluster.html) Amazon RDS API 操作指定下列參數。
+ `DatabaseInsightsMode` 至 `advanced`
+ `EnablePerformanceInsights` 至 `True`
+ `PerformanceInsightsRetentionPeriod` 到至少 465 天

------

# 開啟 Amazon RDS 的 Database Insights 的標準模式
<a name="USER_DatabaseInsights.TurningOnStandard"></a>

若要開啟 Amazon RDS 的 Database Insights 的標準模式，請使用下列程序。

## 在建立資料庫執行個體或多可用區域資料庫叢集時，開啟 Database Insights 的標準模式
<a name="USER_DatabaseInsights.TurnOnCreateDatabaseStandard"></a>

建立 Amazon RDS 的資料庫時，開啟 Database Insights 的標準模式。

------
#### [ Console ]

在此主控台中，您可以在建立資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的標準模式。

**使用主控台建立資料庫執行個體或多可用區域資料庫叢集時，開啟 Database Insights 的標準模式**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 選擇 **Databases** (資料庫)。

1. 選擇**建立資料庫**。

1. 在 **Database Insights** 區段中，選取**標準模式**。然後，從下列選項中選擇以開啟或關閉 Performance Insights：
   + 若要關閉 Performance Insights，請取消選取**啟用 Performance Insights**。
   + 若要開啟 Performance Insights，請選取**啟用 Performance Insights**。若要設定 Performance Insights，請指定下列選項：
     + **Retention (保留)** – 保留 Performance Insights 資料的時間。保留期間必須至少為 7 天。
     + **AWS KMS key** – 指定您的 KMS 金鑰。績效詳情使用您的 KMS 金鑰來加密所有可能的敏感資料。將會對傳輸中與靜態資料進行加密。如需詳細資訊，請參閱[加密 Amazon RDS 資源](Overview.Encryption.md)。

1. 選擇**建立資料庫**。

------
#### [ AWS CLI ]

若要在建立資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的標準模式，請呼叫 [create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html) 或 [create-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-cluster.html) AWS CLI 命令，並提供下列值：
+ `--database-insights-mode standard` 以開啟 Database Insights 的標準模式。
+ `--engine` – 資料庫執行個體的資料庫引擎。
+ `--db-instance-identifier` – 資料庫執行個體的識別符，或 `--db-cluster-identifier` – 多可用區域資料庫叢集的識別碼。
+ `--enable-performance-insights` 或 `--no-enable-performance-insights` 以開啟或關閉 Performance Insights。如果您指定 `--enable-performance-insights`，還必須指定 `--performance-insights-retention-period` – 資料庫執行個體資料的保留期間。保留期間必須至少為 7 天。

下列範例會在建立資料庫執行個體時啟用 Database Insights 和 Performance Insights 的標準模式。

針對 Linux、macOS 或 Unix：

```
aws rds create-db-instance \
    --database-insights-mode standard \ 
    --engine postgresql \
    --db-instance-identifier sample-db-identifier \
    --enable-performance-insights \
    --performance-insights-retention-period 7
```

針對 Windows：

```
aws rds create-db-instance ^
    --database-insights-mode standard ^ 
    --engine postgresql ^
    --db-instance-identifier sample-db-identifier ^
    --enable-performance-insights ^
    --performance-insights-retention-period 7
```

下列範例會在建立資料庫執行個體時，啟用 Database Insights 的標準模式及停用 Performance Insights。

針對 Linux、macOS 或 Unix：

```
aws rds create-db-instance \
    --database-insights-mode standard \ 
    --engine postgresql \
    --db-instance-identifier sample-db-identifier \
    --no-enable-performance-insights
```

針對 Windows：

```
aws rds create-db-instance ^
    --database-insights-mode standard ^ 
    --engine postgresql ^
    --db-instance-identifier sample-db-identifier ^
    --no-enable-performance-insights
```

------
#### [ RDS API ]

若要在建立資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的標準模式，請為您的 [CreateDBInstance](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html) 或 [CreateDBCluster](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html) Amazon RDS API 操作指定下列參數。
+ `DatabaseInsightsMode` 至 `standard`
+ `EnablePerformanceInsights` 設為 `True` 或 `False`。如果您將 `EnablePerformanceInsights` 設定為 `True`，您必須將 `PerformanceInsightsRetentionPeriod` 設定為至少 7 天。

------

## 在修改資料庫執行個體或多可用區域資料庫叢集時，開啟 Database Insights 的標準模式
<a name="USER_DatabaseInsights.TurnOnModifyDatabaseStandard"></a>

修改 Amazon RDS 的資料庫時，開啟 Database Insights 的標準模式。修改資料庫執行個體以啟用 Database Insights 的標準模式不會導致停機時間。

**注意**  
若要啟用 Database Insights，多可用區域資料庫叢集中的每個資料庫執行個體都必須具有相同的 Performance Insights 和增強型監控設定。

------
#### [ Console ]

在此主控台中，您可以在修改資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的標準模式。

**使用主控台修改資料庫執行個體或多可用區域資料庫叢集時，開啟 Database Insights 的標準模式**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 選擇 **Databases** (資料庫)。

1. 選擇一個資料庫執行個體或多可用區域資料庫叢集，然後選擇 **Modify** (修改)。

1. 在 **Database Insights** 區段中，選取**標準模式**。然後，從以下選項中選擇：
   + 若要關閉 Performance Insights，請取消選取**啟用 Performance Insights**。
   + 若要開啟 Performance Insights，請選取**啟用 Performance Insights**。若要設定 Performance Insights，請指定下列選項：
     + **Retention (保留)** – 保留 Performance Insights 資料的時間。保留期間必須至少為 7 天。
     + **AWS KMS key** – 指定您的 KMS 金鑰。績效詳情使用您的 KMS 金鑰來加密所有可能的敏感資料。將會對傳輸中與靜態資料進行加密。如需更多詳細資訊，請參閱 [加密 Amazon RDS 資源](Overview.Encryption.md)。

1. 選擇 **Continue** (繼續)。

1. 在 **Scheduling of Modifications (修改排程)** 中，選擇 **Apply immediately (立即套用)**。如果您選擇**在下一個排定的維護時段套用**，則資料庫會忽略此設定，並立即開啟 Database Insights 的標準模式。

1. 選擇**修改執行個體**。

------
#### [ AWS CLI ]

若要在修改資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的標準模式，請呼叫 [modify-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/modify-db-instance.html) 或 [modify-db-cluster](https://docs.aws.amazon.com/cli/latest/reference/rds/modify-db-cluster.html) AWS CLI 命令，並提供下列值：
+ `--database-insights-mode standard` 以開啟 Database Insights 的標準模式。
+ `--db-instance-identifier` – 資料庫執行個體的識別符，或 `--db-cluster-identifier` – 多可用區域資料庫叢集的識別碼。
+ `--enable-performance-insights` 或 `--no-enable-performance-insights` 以開啟或關閉 Performance Insights。如果您指定 `--enable-performance-insights`，還必須指定 `--performance-insights-retention-period` – 資料庫執行個體或多可用區域資料庫叢集的資料保留期間。保留期間必須至少為 7 天。

下列範例會在修改資料庫執行個體時啟用 Database Insights 的標準模式及啟用 Performance Insights。

針對 Linux、macOS 或 Unix：

```
aws rds modify-db-instance \
    --database-insights-mode standard \
    --db-instance-identifier sample-db-identifier \
    --enable-performance-insights \
    --performance-insights-retention-period 7
```

針對 Windows：

```
aws rds modify-db-instance ^
    --database-insights-mode standard ^
    --db-instance-identifier sample-db-identifier ^
    --enable-performance-insights ^
    --performance-insights-retention-period 7
```

下列範例會在修改資料庫執行個體時啟用 Database Insights 的標準模式及停用 Performance Insights。

針對 Linux、macOS 或 Unix：

```
aws rds modify-db-instance \
    --database-insights-mode standard \
    --db-instance-identifier sample-db-identifier \
    --no-enable-performance-insights
```

針對 Windows：

```
aws rds modify-db-instance ^
    --database-insights-mode standard ^
    --db-instance-identifier sample-db-identifier ^
    --no-enable-performance-insights
```

------
#### [ RDS API ]

若要在修改資料庫執行個體或多可用區域資料庫叢集時開啟 Database Insights 的標準模式，請為 [ModifyDBInstance](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_ModifyDBInstance.html) 或 [ModifyDBCluster](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_ModifyDBCluster.html) Amazon RDS API 操作指定下列參數。
+ `DatabaseInsightsMode` 至 `standard`
+ `EnablePerformanceInsights` 設為 `True` 或 `False`。如果您將 `EnablePerformanceInsights` 設定為 `True`，您必須將 `PerformanceInsightsRetentionPeriod` 設定為至少 7 天。

------

# 使用 Amazon RDS 的 Database Insights 設定資料庫以監控慢速 SQL 查詢
<a name="USER_DatabaseInsights.SlowSQL"></a>

若要監控資料庫的慢速 SQL 查詢，您可以使用 Database Insights 儀表板中的**慢速 SQL 查詢**區段。在設定資料庫以監控慢速 SQL 查詢之前，**慢速 SQL 查詢**區段為空白。

如需在 Database Insights 儀表板中監控慢速 SQL 查詢的詳細資訊，請參閱《Amazon CloudWatch 使用者指南》**中的[檢視 CloudWatch Database Insights 的資料庫執行個體儀表板](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Database-Insights-Database-Instance-Dashboard.html)。

若要設定資料庫以使用 Database Insights 監控慢速 SQL 查詢，請完成下列步驟：

1. 啟用日誌匯出至 CloudWatch Logs。

1. 建立或修改資料庫執行個體的資料庫參數群組。

如需設定日誌匯出的詳細資訊，請參閱《Amazon RDS 使用者指南》**中的[將資料庫日誌發佈至 Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.html#USER_LogAccess.Procedural.UploadtoCloudWatch)。

若要建立或修改資料庫參數群組，請參閱下列主題。
+ [在 Amazon RDS 中建立資料庫參數群組](USER_WorkingWithParamGroups.Creating.md)
+ [修改 Amazon RDS 中的資料庫參數群組中的參數](USER_WorkingWithParamGroups.Modifying.md)

------
#### [ RDS for MariaDB ]

若要設定 RDS for MariaDB 資料庫執行個體來監控慢速 SQL 查詢，您可以使用下列參數組合做為範例：
+ `log_slow_query`：設定為 `1`
+ `log_slow_query_time`：設定為 `1.0`
+ `log_output`：設定為 `FILE`

這是一個可能的組態。如需 MariaDB 慢速查詢日誌參數和其他組態選項的完整指南，請參閱[慢速查詢日誌的 MariaDB 文件](https://mariadb.com/kb/en/slow-query-log-overview/)。

------
#### [ RDS for MySQL ]

若要設定 RDS for MySQL 資料庫執行個體來監控慢速 SQL 查詢，您可以使用下列參數組合做為範例：
+ `slow_query_log`：設定為 `1`
+ `long_query_time`：設定為 `1.0`
+ `log_output`：設定為 `FILE`

這是一個可能的組態。如需 MySQL 慢速查詢日誌參數和其他組態選項的完整指南，請參閱[慢速查詢日誌的 MySQL 文件](https://dev.mysql.com/doc/refman/8.0/en/slow-query-log.html)。

------
#### [ RDS for PostgreSQL ]

若要設定 RDS for PostgreSQL 資料庫執行個體來監控慢速 SQL 查詢，您可以使用下列參數組合做為範例。請注意，設定這些參數可能會降低資料庫執行個體的效能。
+ `log_min_duration_statement`：設定為 `1000`
+ `log_statement`：設定為 `none`
+ `log_destination`：設定為 `stderr`

這是一個可能的組態。如需 PostgreSQL 記錄參數和其他組態選項的完整指南，請參閱[記錄組態的 PostgreSQL 文件](https://www.postgresql.org/docs/current/runtime-config-logging.html)。

------

**注意**  
對於 RDS for MySQL，您可以使用 1‐毫秒精細程度設定參數 `long_query_time`。例如，您可以將此參數設為 `0.000001`。根據資料庫執行個體上的查詢數量，參數 `long_query_time` 的值會降低效能。從值 `1.0` 開始，然後根據您的工作負載進行調整。當您將此參數設定為 `0` 時，Database Insights 會記錄所有查詢。

如需 RDS for MariaDB、RDS for MySQL 和 RDS for PostgreSQL 日誌的詳細資訊，請參閱以下內容。
+ [MariaDB 資料庫日誌檔案](USER_LogAccess.Concepts.MariaDB.md)
+ [ MySQL資料庫日誌檔案](USER_LogAccess.Concepts.MySQL.md)
+ [ RDS for PostgreSQL 資料庫日誌檔案](USER_LogAccess.Concepts.PostgreSQL.md)

# Amazon RDS Amazon 資料庫洞見的考量事項
<a name="USER_DatabaseInsights.Considerations"></a>

以下是 Amazon RDS Database Insights 的考量事項。
+ 您無法管理多可用區域資料庫叢集中資料庫執行個體的 Database Insights。
+ 若要啟用 Database Insights 的進階模式，您必須啟用 Performance Insights，並將 Performance Insights 保留期間設定為至少 465 天 (15 個月)。除了 Database Insights 的成本之外，將 Performance Insights 保留期間設定為 15 個月無需額外費用。如需 Database Insights 定價的資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。
+ 若要啟用 Database Insights，多可用區域資料庫叢集中的每個資料庫執行個體都必須具有相同的 Performance Insights 和增強型監控設定。
+ 修改資料庫執行個體以啟用 Database Insights 的任一模式不會導致停機時間。