A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/sql/docs/mysql/optimize-high-memory-usage below:

Optimize high memory usage in instances | Cloud SQL for MySQL

Optimize high memory usage in instances

Stay organized with collections Save and categorize content based on your preferences.

It's a common problem to have instances consuming lots of memory or running into out-of-memory (OOM) issues. A database instance running with high memory utilization often causes performance issues, stalls, or even database downtime.

Some MySQL memory blocks are used globally. This means that all query workloads share memory locations, are occupied all the time, and are released only when the MySQL process stops. Some memory blocks are session based, which means that as soon as the session closes, memory used by that session is also released back to the system.

Whenever there is high memory usage by a Cloud SQL for MySQL instance, Cloud SQL recommends that you identify the query or process that's using a lot of memory and release it. MySQL memory consumption is divided into three major parts:

Threads and process memory consumption

Each user session consumes memory depending on the queries running, buffers, or cache used by that session and is controlled by the session parameters of MySQL. The major parameters include:

If there are N number of queries running at a particular time, then each query consumes memory according to these parameters during the session.

Buffer memory consumption

This part of memory is common for all the queries and is controlled by parameters such as Innodb_buffer_pool_size, Innodb_log_buffer_size, and key_buffer_size.

Cache memory consumption

Cache memory includes a query cache, which is used to save the queries and their results for faster data retrieval of the same subsequent queries. It also includes the binlog cache to hold the changes made to the binary log while the transaction is running, and is controlled by binlog_cache_size.

Other memory consumption

Memory is also used by join and sort operations. If your queries use join or sort operations, those queries use memory on the basis of join_buffer_size and sort_buffer_size.

Apart from this, if you enable the performance schema, it consumes memory. To check the memory usage by the performance schema, use the following query:

SELECT *
FROM
  performance_schema.memory_summary_global_by_event_name
WHERE EVENT_NAME LIKE 'memory/performance_schema/%';

There are many instruments available in MySQL that you can set up to monitor the memory usage through the performance schema. To learn more, see the MySQL documentation.

The MyISAM-related parameter for bulk data insertion is bulk_insert_buffer_size.

To learn about how MySQL uses memory, see the MySQL documentation.

Recommendations

The following sections offer some recommendations for optimal memory usage.

Use Metrics Explorer to identify the memory usage

You can review the memory usage of an instance with the database/memory/components.usage metric in Metrics Explorer.

If you have less than 5% memory in database/memory/components.cache and database/memory/components.free combined, the risk of an OOM event is high. To monitor the memory usage and to prevent OOM events, we recommend that you set up an alerting policy with a metric threshold condition of 95% or more in database/memory/components.usage.

The following table shows the relationship between your instance memory and the recommended alerting threshold:

Instance memory Recommended alerting threshold Up to 100 GB 95% 100 GB to 200 GB 96% 200 GB to 300 GB 97% More than 300 GB 98% Calculate memory consumption

Calculate the maximum memory usage by your MySQL database to select the appropriate instance type for your MySQL database. Use the following formula:

Maximum MySQL memory usage = innodb_buffer_pool_size + innodb_additional_mem_pool_size + innodb_log_buffer_size + tmp_table_size + key_buffer_size + ((read_buffer_size + read_rnd_buffer_size + sort_buffer_size + join_buffer_size) x max_connections)

Here are the parameters used in the formula:

Note: There are many other small components consuming memory which depends on the queries so there should be room for those components as well. Troubleshoot high memory consumption Apply changes

After you analyze the memory usage by different components, set the appropriate flag in your MySQL database. To change the flag in Cloud SQL for MySQL instance, you can use Google Cloud console or gcloud CLI. To change the flag value using the Google Cloud console, edit the Flags section, select the flag, and enter the new value.

Lastly, if the memory usage is still high and you feel running queries and flag values are optimized, then consider increasing the instance size to avoid OOM.

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-14 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-14 UTC."],[],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4