

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

# 監控 Aurora PostgreSQL 的查詢執行計劃和尖峰記憶體
<a name="AuroraPostgreSQL.Monitoring.Query.Plans"></a>

您可以在 Aurora PostgreSQL 資料庫執行個體中監控查詢執行計劃，以偵測造成目前資料庫負載的執行計劃，並使用 `aurora_compute_plan_id` 參數追蹤執行計劃隨時間的效能統計資料。每當查詢執行時，查詢使用的執行計劃都會獲指派識別符，而相同計劃的後續執行也會使用相同的識別符。

根據預設，`aurora_compute_plan_id` 會在 Aurora PostgreSQL 14.10、15.5 版和更新版本的資料庫參數群組中設定為 `OFF`。若要指派計劃識別符，請在參數群組中將 `aurora_compute_plan_id` 設定為 `ON`。

此計劃識別符用於數個提供不同用途的公用程式。

您可以監控資料庫執行個體中的查詢尖峰記憶體用量，以偵測從下列版本導致高資料庫記憶體用量的查詢：
+ 16.3 版和所有更新版本
+ 15.7 和更新版本
+ 14.12 和更新版本

每當查詢執行時，系統都會追蹤查詢所使用的尖峰記憶體。查詢通常會執行多次；每個查詢都可以檢視所有執行的平均、最小和最大記憶體用量值。

**Topics**
+ [使用 Aurora 函數存取查詢執行計劃和尖峰記憶體](#AuroraPostgreSQL.Monitoring.Query.Plans.Functions)
+ [Aurora PostgreSQL 查詢執行計劃的參數參考](#AuroraPostgreSQL.Monitoring.Query.Plans.Parameters)

## 使用 Aurora 函數存取查詢執行計劃和尖峰記憶體
<a name="AuroraPostgreSQL.Monitoring.Query.Plans.Functions"></a>

透過 `aurora_compute_plan_id`，您可以使用下列函數存取執行計劃：
+ aurora\$1stat\$1activity
+ aurora\$1stat\$1plans

查詢尖峰記憶體不包含查詢處理開始之前配置的記憶體。針對每個查詢的規劃和執行階段，系統會分別追蹤和報告尖峰記憶體用量。

![\[\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/images/aurora-apg-peakmemory.png)


您可以使用下列函數來存取查詢尖峰記憶體統計資料。
+ aurora\$1stat\$1statements
+ aurora\$1stat\$1plans

如需這些函數的詳細資訊，請參閱 [Aurora PostgreSQL 函數參考](Appendix.AuroraPostgreSQL.Functions.md)。

## Aurora PostgreSQL 查詢執行計劃的參數參考
<a name="AuroraPostgreSQL.Monitoring.Query.Plans.Parameters"></a>

您可以使用資料庫參數群組中的下列參數來監控查詢執行計劃。

**Topics**
+ [aurora\$1compute\$1plan\$1id](#aurora.compute_plan_id)
+ [aurora\$1stat\$1plans.minutes\$1until\$1recapture](#aurora.minutes_until_recapture)
+ [aurora\$1stat\$1plans.calls\$1until\$1recapture](#aurora.calls_until_recapture)
+ [aurora\$1stat\$1plans.with\$1costs](#aurora.with_costs)
+ [aurora\$1stat\$1plans.with\$1analyze](#aurora.with_analyze)
+ [aurora\$1stat\$1plans.with\$1timing](#aurora.with_timing)
+ [aurora\$1stat\$1plans.with\$1buffers](#aurora.with_buffers)
+ [aurora\$1stat\$1plans.with\$1wal](#aurora.with_wal)
+ [aurora\$1stat\$1plans.with\$1triggers](#aurora.with_triggers)

**注意**  
`aurora_stat_plans.with_*` 參數的組態只會對新擷取的計劃生效。

### aurora\$1compute\$1plan\$1id
<a name="aurora.compute_plan_id"></a>

`aurora_compute_plan_id` 是組態參數，可控制是否在查詢執行期間指派計劃識別符。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Monitoring.Query.Plans.html)

### aurora\$1stat\$1plans.minutes\$1until\$1recapture
<a name="aurora.minutes_until_recapture"></a>

計劃重新擷取之前要經過的分鐘數。預設為 0，這會停用重新擷取計劃。超過 `aurora_stat_plans.calls_until_recapture` 閾值時，將會重新擷取計劃。


| 預設 | 允許的值 | Description | 
| --- | --- | --- | 
| 0 | 0-1073741823 | 設定計劃重新擷取之前要經過的分鐘數。 | 

### aurora\$1stat\$1plans.calls\$1until\$1recapture
<a name="aurora.calls_until_recapture"></a>

重新擷取計劃之前對計劃的呼叫次數。預設值為 0，這會停用在多次呼叫後重新擷取計劃。超過 `aurora_stat_plans.minutes_until_recapture` 閾值時，將會重新擷取計劃。


| 預設 | 允許的值 | Description | 
| --- | --- | --- | 
| 0 | 0-1073741823 | 設定重新擷取計劃之前的呼叫次數。 | 

### aurora\$1stat\$1plans.with\$1costs
<a name="aurora.with_costs"></a>

使用預估成本擷取 EXPLAIN 計劃。允許的值為 `on` 和 `off`。預設值為 `on`。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Monitoring.Query.Plans.html)

### aurora\$1stat\$1plans.with\$1analyze
<a name="aurora.with_analyze"></a>

使用 ANALYZE 控制 EXPLAIN 計劃。此模式只會在第一次擷取計劃時使用。允許的值為 `on` 和 `off`。預設值為 `off`。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Monitoring.Query.Plans.html)

### aurora\$1stat\$1plans.with\$1timing
<a name="aurora.with_timing"></a>

使用 ANALYZE 時，計劃時間將在解釋中擷取。預設值為 `on`。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Monitoring.Query.Plans.html)

### aurora\$1stat\$1plans.with\$1buffers
<a name="aurora.with_buffers"></a>

使用 ANALYZE 時，計劃緩衝區用量統計資料將在解釋中擷取。預設值為 `off`。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Monitoring.Query.Plans.html)

### aurora\$1stat\$1plans.with\$1wal
<a name="aurora.with_wal"></a>

使用 ANALYZE 時，計劃 WAL 用量統計資料將在解釋中擷取。預設值為 `off`。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Monitoring.Query.Plans.html)

### aurora\$1stat\$1plans.with\$1triggers
<a name="aurora.with_triggers"></a>

使用 `ANALYZE` 時，計劃觸發程序執行統計資料將在解釋中擷取。預設值為 `off`。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Monitoring.Query.Plans.html)