How to reduce Google Cloud SQL instance size?

2019-07-24 23:21发布

I have a Google Cloud SQL MySQL 2nd Gen 5.7 instance with 70GB of unused storage. I want to reduce the unused storage of my instance as this is one of the major hosting costs.

The only way that I'm seeing as a possibility is dumping all the database to a new Google Cloud SQL instance created with the right storage capacity. However this approach has several pitfalls:

  • It would require a lot of time to dump and load the database (this would require severe downtime in the websites that are using the db)
  • I would have to change all the websites that use that database because the database's IP would change

What alternatives do I have?

2条回答
唯我独甜
2楼-- · 2019-07-24 23:55

Have you tried changing the Machine Type (Tier) in Cloud SQL? You can use gcloud command line to do it. However, be aware that

You can change an instance's tier at any time, with just a few seconds of downtime. Blockquote

ref: gcloud doc

First, you should pick which tier you want based on the region and your needs (CPU & memory)

This command shows the list of available tiers in different region.

gcloud sql tiers list

Then run with your selected tier (e.g. db-f1-micro)

gcloud sql instances patch --project=<YOUR_PROJECT_ID> <SQL_DB_INSTANCE_NAME> --tier <TIER>

I hope it helps.

查看更多
家丑人穷心不美
3楼-- · 2019-07-24 23:56

As it is indicated in the official documentation, it is not possible to reduce the storage capacity of a Cloud SQL instance. You can give more capacity to an instance if needed, but the change is permanent and cannot be rolled back.

The best option for you right now would be to create a SQL dump file and export your current data into it. Then, in a new Cloud SQL instance with the desired capacity, import the SQL dump file so that all your data is stored in the new instance. To reduce time and costs for this process, please follow these best practices, including the use of the appropriate flags, compressing your data and other tips available for faster and less expensive imports and exports.

However, the possibility of reducing the capacity of a Cloud SQL instance has been requested as a new feature and is currently being worked on. Head to the link and click on the star icon on the top left corner to get email notifications on any progress made on this request.

查看更多
登录 后发表回答