Skip to content

How to log and analyze query execution plans in Amazon Aurora PostgreSQL for performance tuning using the Performance Insights Advanced feature.

3 minute read
Content level: Intermediate
3

This guide explains how to enable and view query execution plans using Performance Insights Advanced feature in Amazon Aurora PostgreSQL, helping you monitor and tune query performance effectively.

Prerequisites:-

• You must use Advanced mode of Database Insights.

• Your DB instance must run Aurora PostgreSQL version 14.10, 15.5, or later.

• The aurora_compute_plan_id parameter must be set to 1 in your cluster parameter group (this is a dynamic parameter, no reboot required)

Implementation Steps

Step 1: Enable Advanced Mode of Database Insights (Modifying a DB cluster to enable the Advanced mode of Database Insights doesn't cause downtime.)

  1. Sign in to the AWS Management Console and open the Amazon RDS console
  2. Choose Databases and select your DB cluster
  3. Click Modify
  4. In the Database Insights section, select Advanced mode
  5. Configure: o Retention: Set to 15 months (required for Advanced mode) o AWS KMS key: Specify your KMS key for encryption
  6. Choose Continue
  7. For scheduling, select Apply immediately
  8. Click Modify cluster

Step 2: To gain deeper insights into query performance, configure these advanced execution plan parameters in your cluster parameter group:-

• aurora_stat_plans.with_analyze: Set to on (captures actual execution plans). As By default, CloudWatch displays the estimated execution plan.

• aurora_stat_plans.with_costs: Set to on (captures estimated costs, on by default)

• aurora_stat_plans.with_timing: Set to on (captures timing information, on by default)

• aurora_stat_plans.with_buffers: Set to on (captures buffer usage statistics, off by default)

**Step 3: **Analyze Execution Plans

  1. Open the CloudWatch console
  2. Choose Insights > Database Insights
  3. Select Database Instance view
  4. Choose your DB instance
  5. Select the Top SQL tab
  6. Look for the Plans Count column showing the number of plans collected for each query
  7. Choose a digest query to expand it into its component statements.
  8. Scroll down to view SQL text, then select the Plans tab to see execution plans
  9. To compare plans from the same digest query, choose two Plans from the Plans for digest query list. You can view either one or two plans for a query at a time.

Additional Information

• All the parameters mentioned above are dynamic (no restart required)

• 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.

• By analyzing these execution plans, you can identify inefficient queries and optimize your database performance accordingly.

[+]https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Database-Insights.html

[+] https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Monitoring.Query.Plans.html#aurora.with_analyze

[+] https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Database-Insights-Execution-Plans.html

[+] https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights.UsingDashboard.AnalyzeDBLoad.AdditionalMetrics.html

AWS
EXPERT

published a year ago1.3K views