High memory usage in CloudSQL (PostgreSQL)

Hi, I uses GCP’s CloudSQL (PostgreSQL).
Memory usage is about 90% on a regular basis.
Memory usage can be more than 90% instantaneously.
Since we are using cache, I think that high usage is not a big problem,
CloudSQL is a managed service, so is Memory utilization of around 90% normal?
I am concerned about sudden memory shortages.

■Memory usage configuration
・cache: 52%
・Usage: 40%
・Free: 8%

Thank you.

Memory utilization of around 90% is not necessarily a problem for Cloud SQL, especially if you are using a significant amount of cache. However, it is important to monitor your memory usage closely to ensure that it does not exceed 100%, which can lead to out-of-memory (OOM) events.

OOM events can cause your database to become unavailable, so it is important to take steps to avoid them. Here are a few things you can do:

  • Monitor your memory usage regularly and set up alerts to notify you when it exceeds a certain threshold.
  • Identify and optimize any queries that are using a lot of memory.
  • Consider increasing the size of your Cloud SQL instance if it is consistently running at high memory utilization.

In your case, it is good to see that you are using a significant amount of cache (52%). This means that your database is likely to be able to handle a high volume of queries without running out of memory. However, it is still important to monitor your memory usage closely and take steps to avoid OOM events.

Here are some additional tips for managing memory usage in Cloud SQL for PostgreSQL:

  • Use the work_mem parameter to control the amount of memory that PostgreSQL uses for temporary workspaces. If you are seeing OOM events, you may need to reduce the value of this parameter.
  • Use the shared_buffersparameter to control the amount of memory that PostgreSQL uses for the shared buffer pool. The shared buffer pool is used to cache frequently accessed data pages. Increasing the size of the shared buffer pool can improve performance and reduce memory usage.
  • Use the max_connectionsparameter to control the maximum number of concurrent connections to your database. If you are seeing OOM events, you may need to reduce the value of this parameter.

If you are concerned about sudden memory shortages, you can use the pg_repack utility to defragment and compress the database files. This can free up some memory and reduce the risk of OOM events.

Overall, it is important to monitor your memory usage closely and take steps to avoid OOM events. However, memory utilization of around 90% is not necessarily a problem for Cloud SQL, especially if you are using a significant amount of cache.

2 Likes