

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

# 使用 CloudWatch Database Insights 分析執行計畫
<a name="Database-Insights-Execution-Plans"></a>

可以使用下列方法分析 Amazon Aurora PostgreSQL、RDS for Microsoft SQL Server 和 RDS for Oracle 資料庫的執行計畫。
+ **配量依據**下拉式清單 – 選擇**資料庫負載**圖表中的**計畫**維度，可檢視不同計畫如何隨時間推移影響資料庫負載。
+ **最高 SQL** 索引標籤 – 選擇**資料庫負載分析**，然後選擇**最高 SQL** 索引標籤，以檢視每個摘要查詢的計畫數目。

  若要分析摘要查詢的執行計畫，請選擇查詢，然後選擇**計畫**索引標籤。如需詳細資訊，請參閱下列程序。

## 先決條件
<a name="Database-Insights-Execution-Plans-prereqs"></a>

若要分析執行計畫，必須使用 Database Insights 的進階模式。如需如何開啟進階模式的資訊，請參閱 [Turning on the Advanced mode of Database Insights for Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_DatabaseInsights.TurningOnAdvanced.html) 和 [Turning on the Advanced mode of Database Insights for Amazon Relational Database Service](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.TurningOnAdvanced.html)。

如果使用的是 Aurora PostgreSQL，還需滿足下列先決條件：
+ 您的資料庫執行個體必須使用 Aurora PostgreSQL 版本 14.10、15.5 或更高版本。如需有關升級 Aurora PostgreSQL 資料庫叢集的資訊，請參閱《Amazon Aurora 使用者指南》**中的 [Upgrading Amazon Aurora PostgreSQL DB clusters](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_UpgradeDBInstance.PostgreSQL.html)。
+ 必須透過下列其中一個選項將參數 `aurora_compute_plan_id` 設定為 `on`，以設定資料庫叢集來分析執行計畫。
  + 《Amazon Aurora 使用者指南》中的 [Creating a DB cluster parameter group in Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_WorkingWithParamGroups.CreatingCluster.html) **
  + 《Amazon Aurora 使用者指南》中的 [Modifying parameters in a DB cluster parameter group in Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_WorkingWithParamGroups.ModifyingCluster.html) **

## 分析執行計畫
<a name="Database-Insights-Execution-Plans-analyze"></a>

若要分析執行計畫，請依循下列程序。

**分析執行計畫**

1. 簽署 AWS 管理主控台 並開啟位於 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 的 CloudWatch 主控台。

1. 選擇 **Insights**。

1. 選擇 **Database Insights**。

1. 選擇**資料庫執行個體**檢視。

1. 選擇資料庫執行個體。

1. 選擇 **Top SQL** (最高 SQL) 索引標籤。**欄位計數**欄位顯示針對每個摘要查詢收集的計畫數目。

1. (選用) 如果**計畫計數**資料欄未顯示，請選擇**最高 SQL** 資料表上的**設定**圖示，以自訂欄位的可見性和順序。  
![\[計畫詳細資訊資料表的設定\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/DBInsights2.png)

1. 選擇摘要查詢，展開到其元件陳述式中。  
![\[將查詢展開至其元件陳述式\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_did-dbload-expand.png)

1. 向下捲動並檢視 SQL 文字。然後，選擇**計畫**索引標籤。

   依預設，CloudWatch 會顯示預估的執行計畫。對於 Aurora PostgreSQL，若要檢視實際執行計畫，請啟用資料庫執行個體的 `aurora_stat_plans.with_analyze` 參數。如需有關參數 `aurora_stat_plans.with_analyze` 的詳細資訊，請參閱《Amazon Aurora 使用者指南》**中的監控 [Aurora PostgreSQL 的查詢執行計畫與尖峰記憶體用量](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Monitoring.Query.Plans.html#aurora.with_analyze)。

1. 若要比較同個摘要查詢的計畫，請從**摘要查詢的計畫**清單中選擇兩個**計畫**。

   一次可以查看查詢的一個或兩個計畫。下列螢幕擷取畫面範例中，兩個計畫皆適用於 Aurora PostgreSQL。  
![\[比較計畫\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_did-plans.png)

1. 也可以透過在 DBLoad 圖表的**配量依據**下拉式清單中選擇**計畫**，檢視各項計畫如何隨時間推移影響資料庫負載。  
![\[Database load chart showing active sessions over time with plans contribution highlighted.\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/DBInsights_OverTime.png)