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.)
- Sign in to the AWS Management Console and open the Amazon RDS console
- Choose Databases and select your DB cluster
- Click Modify
- In the Database Insights section, select Advanced mode
- Configure:
o Retention: Set to 15 months (required for Advanced mode)
o AWS KMS key: Specify your KMS key for encryption
- Choose Continue
- For scheduling, select Apply immediately
- 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
- Open the CloudWatch console
- Choose Insights > Database Insights
- Select Database Instance view
- Choose your DB instance
- Select the Top SQL tab
- Look for the Plans Count column showing the number of plans collected for each query
- Choose a digest query to expand it into its component statements.
- Scroll down to view SQL text, then select the Plans tab to see execution plans
- 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