Better Database Performance with Google Cloud SQL Insights

Google Cloud launched an advanced database performance tool (Cloud SQL Insights), allowing you to closely monitor the database performance and identify potential performance issues.

Many Google Cloud SQL users have waited for it for a long time, as both AWS and Azure already offer similar products for a while. AWS RDS Performance Insights is available since 2018, and Microsoft did a significant update in 2020 to their Azure Query Performance Insights. Now all major cloud providers offer a database performance monitoring tool.

Why should you get familiar with this new product? Because companies can't afford surprises with their database performance. Companies trust their databases to be reliable, scalable, and always well-performing.

How to enable Cloud SQL Insights:

  • When you create a new PostgreSQL instance or edit an existing one - you can find the new option under the configuration options:

    By default it is disabled and you need to enable it. When you enable it, you have a few more features:

    • Store Client IP Addresses - This can help you understand where queries are coming from.
    • Store Application Tags - If you are using Tags in your SQL queries or in your ORM, you can later filter by these options.
    • Customize Query length - This option is there to overcome a default configuration in some databases, where the default query length is too short. However, increasing the length will require more memory.

After you enable it, you will see the new Query Insights option on the left sidebar:

 

What’s new in Google Cloud SQL Insights:

  • Timeline - Cloud SQL Insights allows you to quickly locate potential issues, by allowing you to review the database resource usage on an easy to use timeline. Once you locate a potential issue at a specific time, you can zoom into that location to review the relevant resource usage and slow queries being executed at that time.
  • Visualizing slow query logs  - This far, the only way users had to review slow SQL query logs for Google Cloud SQL instances was to review the textual logs on StackDriver. In most cases, users were either exploring those logs in the textual format, or building custom dashboards and metric alerts on top of those logs.
    The new Query Insights dashboard allows better visualization into the top slow queries, while also visualizing resource usage for the database and queries.
  • Prioritizing which slow queries to optimize - Google SQL Insights offers the ability to view the top SQL queries taking up most of the resources on your database. You can sort the list based on several options such as total load time, average execution time and executions count, to quickly prioritize which queries you need to optimize to improve your database performance.

    If you’re looking for an automatic optimization tool to complement this solution, try
    EverSQL Query Optimizer, which will provide you additional insights and automatically rewrite the queries for you (yes, automatically).
  • Tagging - Most monitoring tools will just show you which queries are running slow, leaving you with the work of correlating those queries to their location in your code base.
    Cloud SQL Insights can tag your queries automatically, using comments from your SQL queries. Those comments can be added by you manually inside your code, or if you're using an ORM, they can be added automatically when implementing Google's SQLCommenter.
    Once you got tagging implemented, you can view the origin of each query and track it to the relevant microservice / code base.
  • Visual Execution Plans - Explain plans are usually used by the more experienced developers or DBAs, who wish to better understand the optimizer's execution path and plan. Cloud SQL Insights will present a visualization of the execution plan as you can see below.However, while some of us would love to dig into these plans, some developers may find these diagrams a bit too technical and may still need dba assistance.
  • PostgreSQL support - PostgreSQL has shown high growth and adoption in the last few years among both startups and large businesses. It’s ranking #4 in the DBEngines top databases list, so it’s no wonder that Cloud SQL Insights decided to launch the product with PostgreSQL in their first version.

    If you are looking to explore other solutions for database performance analysis, or in case you’re using MySQL (which is currently not supported by Google Cloud SQL Insights), you can try
    EverSQL to both obtain performance insights for your database and optimize your SQL queries automatically.
  • Optimizing SQL queries - Google Cloud SQL Insights does a great job in allowing you to identify the root cause of the performance issues, but what if you need to resolve them quickly? Many GCP users are looking for an automated way to optimize their SQL queries, while also learning from the process to be able to write optimized queries in the future. EverSQL will allow you to both automatically optimize the queries, while also explaining exactly how to index and rewrite SQL queries for optimal performance.

  • Advanced Performance Insights - Google Cloud SQL Insights shows you the slowest queries which is very helpful. If you need additional advanced insights such as viewing query trends and enabling performance bottleneck prediction, you can integrate your database with EverSQL:

Optimize Slow Queries directly from Google Cloud SQL Insights 

EverSQL released an updated version to the EverSQL for Database Monitoring Applications plug-in, allowing developers to optimize their SQL queries directly from their favorite database monitoring tool.

If you're already a Google Cloud customer, you're probably looking to have everything you need in one place, which is why we made sure the integration with Cloud SQL Insights is easy and seamless.

To integrate the products, all you have to do is install EverSQL's Chrome extension, which will automatically add a Optimize by EverSQL button for each query in SQL Insights top SQL queries table. These new buttons will allow you to optimize your queries automatically using EverSQL. The recommendations from EverSQL will include an automatically re-written and optimized SQL query, and a recommendation for optimal indexes you should create to improve the query's performance.

The integration is non-intrusive, standalone, and doesn’t require any access or permissions into your google cloud account. If you prefer to optimize your SQL queries directly without the integration, you can do that as well by using EverSQL.

Summary

Google Cloud SQL Insights is a great addition for Google Cloud SQL users, allowing you to quickly locate performance issues in PostgreSQL instances. If you haven't tried it yet, you should start here and discover how to improve your database performance.