

# Monitoring query execution plans and peak memory for Aurora PostgreSQL
<a name="AuroraPostgreSQL.Monitoring.Query.Plans"></a>

You can monitor query execution plans in your Aurora PostgreSQL DB instance to detect the execution plans contributing to current database load and to track performance statistics of execution plans over time using the `aurora_compute_plan_id` parameter. Whenever a query executes, the execution plan used by the query is assigned an identifier and the same identifier is used by subsequent executions of the same plan.

The `aurora_compute_plan_id` is turned `OFF` by default in DB parameter group from Aurora PostgreSQL versions 14.10, 15.5, and higher versions. To assign a plan identifier, set `aurora_compute_plan_id` to `ON` in the parameter group.

This plan identifier is used in several utilities that serve a different purpose.

You can monitor query peak memory usage in your DB instance to detect queries contributing to high database memory use from the following versions:
+ 16.3 and all higher versions
+ 15.7 and higher versions
+ 14.12 and higher versions

Whenever a query runs, the peak memory used by the query is tracked. Queries typically run many times; the average, minimum and maximum memory usage values across all runs can be viewed for each query.

**Topics**
+ [Accessing query execution plans and peak memory using Aurora functions](#AuroraPostgreSQL.Monitoring.Query.Plans.Functions)
+ [Parameter reference for Aurora PostgreSQL query execution plans](#AuroraPostgreSQL.Monitoring.Query.Plans.Parameters)

## Accessing query execution plans and peak memory using Aurora functions
<a name="AuroraPostgreSQL.Monitoring.Query.Plans.Functions"></a>

With `aurora_compute_plan_id`, you can access the execution plans using the following functions:
+ aurora\$1stat\$1activity
+ aurora\$1stat\$1plans

The query peak memory does not include memory that is allocated before query processing starts. Peak memory usage is tracked and reported separately for the planning and execution phases of each query.

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


You can access the query peak memory statistics using the following functions:
+ aurora\$1stat\$1statements
+ aurora\$1stat\$1plans

For more information on these functions, see [Aurora PostgreSQL functions reference](Appendix.AuroraPostgreSQL.Functions.md).

## Parameter reference for Aurora PostgreSQL query execution plans
<a name="AuroraPostgreSQL.Monitoring.Query.Plans.Parameters"></a>

You can monitor the query execution plans using the below parameters in a DB parameter group. 

**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)

**Note**  
The configuration for `aurora_stat_plans.with_*` parameters takes effect only for newly captured plans.

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

The `aurora_compute_plan_id` is a configuration parameter that controls whether a plan identifier is assigned during query execution.

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

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

The number of minutes to pass before a plan is recaptured. Default is 0 which will disable recapturing a plan. When the `aurora_stat_plans.calls_until_recapture` threshold is passed, the plan will be recaptured.


| Default | Allowed values | Description | 
| --- | --- | --- | 
| 0 | 0-1073741823 | Set the number of minutes to pass before a plan is recaptured. | 

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

The number of calls to a plan before it is recaptured. Default is 0 which will disable recapturing a plan after a number of calls. When the `aurora_stat_plans.minutes_until_recapture` threshold is passed, the plan will be recaptured.


| Default | Allowed values | Description | 
| --- | --- | --- | 
| 0 | 0-1073741823 | Set the number of calls before a plan is recaptured. | 

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

Captures an EXPLAIN plan with estimated costs. The allowed values are `on` and `off`. The default is `on`.

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

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

Controls the EXPLAIN plan with ANALYZE. This mode is only used the first time a plan is captured. The allowed values are `on` and `off`. The default is `off`.

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

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

Plan timing will be captured in the explain when ANALYZE is used. The default is `on`.

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

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

Plan buffer usage statistics will be captured in the explain when ANALYZE is used. The default is `off`.

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

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

Plan wal usage statistics will be captured in the explain when ANALYZE is used. The default is `off`.

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

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

Plan trigger execution statistics will be captured in the explain when `ANALYZE` is used. The default is `off`.

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