How to Enable and Use the Slow Query Log on Aurora MySQL Serverless

Enabling the slow query log in Amazon Aurora MySQL Serverless is one of the easiest ways to diagnose performance bottlenecks. With just a few parameter changes, you can capture queries that run longer than expected and send them to either a MySQL table for quick analysis or to CloudWatch Logs for dashboards and alerts. In this guide, we’ll walk through enabling the feature, viewing results, and using CloudWatch Logs Insights to surface your top slow queries.

Table of Contents

When you’re troubleshooting performance on Amazon Aurora MySQL Serverless, one of the most useful tools available is the slow query log. By capturing queries that take longer than expected, you can pinpoint inefficiencies and optimize your workload.

Aurora Serverless supports slow query logging much like standard RDS MySQL, but with some Aurora-specific twists. This post walks you through enabling the feature, choosing between TABLE and FILE output, and analyzing your logs in CloudWatch.


Step 1: Understand How Aurora Logs Work

Aurora MySQL Serverless (v1 and v2) uses a DB cluster parameter group to manage configuration. You’ll need to modify (or create) a cluster parameter group to enable slow query logging.

You can log queries to:

  • TABLE → stored in mysql.slow_log, queryable with SQL.
  • FILE → written to RDS logs and optionally exported to CloudWatch Logs for dashboards and alerts.

Step 2: Configure Parameters

The key parameters are:

Parameter Value Purpose
slow_query_log 1 Enables slow query logging
long_query_time 1 Threshold in seconds
log_output TABLE or FILE Output destination
log_queries_not_using_indexes 0 or 1 Optional: log unindexed queries

Example: Enable Slow Query Log (to TABLE)

Example: Enable Slow Query Log (to FILE + CloudWatch)


Step 3: Apply Parameter Group to Cluster

Aurora Serverless v2 supports dynamic parameter changes, so most settings apply immediately. On v1, some may require a stop/start cycle.


Step 4: View Your Logs

Option A: TABLE Output

Run queries directly against the system table:

Rotate/clear logs when needed:

Option B: FILE Output + CloudWatch

Logs appear under RDS → Logs & Events or in CloudWatch if you enable export:

In CloudWatch, look under:


Step 5: Analyze Slow Queries in CloudWatch Logs Insights

With logs in CloudWatch, you can use Logs Insights to quickly spot problematic queries.

Go to CloudWatch → Logs Insights, select your slow query log group (e.g., /aws/rds/cluster/<cluster>/slowquery), paste a query, and run it.

Top 10 slow queries by total execution time

Top 10 by average query time

Hot list of queries over 2 seconds


Step 6: Pin to a CloudWatch Dashboard

You can keep an eye on slow query trends right from a CloudWatch Dashboard. Here’s a sample widget JSON that shows the count of slow queries over time.

How to use:

  1. Open CloudWatch → Dashboards.
  2. Create or edit a dashboard.
  3. Choose “Add widget” → “Logs” → “Source query” → Switch to JSON.
  4. Paste the JSON, update YOUR-CLUSTER-ID and region.
  5. Save the dashboard.

Now you’ll see a real-time chart of slow query counts, binned by 5 minutes.


Best Practices

  • Start with long_query_time=1 and adjust based on workload.
  • Use log_queries_not_using_indexes=1 sparingly—it can generate a lot of noise.
  • Prefer TABLE output for one-off troubleshooting and FILE + CloudWatch for ongoing monitoring.
  • Rotate logs regularly to keep storage manageable:

Quick Setup Script (All-in-One)

Here’s a simple script that enables logging to FILE and exports to CloudWatch:


Conclusion

With the slow query log enabled, you’ll have clear visibility into which queries are dragging down performance in Aurora MySQL Serverless. Whether you choose TABLE for ad-hoc analysis, FILE + CloudWatch for continuous monitoring, or pin results to a CloudWatch Dashboard, this feature is an essential part of your optimization toolkit.


Reliable Penguin helps teams optimize AWS environments and manage Aurora clusters every day. If you’d like expert support tuning your database or improving performance, contact us and let’s talk.

Have a project or a problem?

Talk with a senior engineer for practical recommendations—no obligation.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.