发送反馈
缩减实例存储空间容量
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页面介绍了如何使用存储空间缩减功能管理 Cloud SQL 实例的存储容量。
准备工作
查看功能限制 。
如果您使用的是 gcloud CLI ,请确保您使用的是最新版本的 Google Cloud SDK 和 gcloud CLI。
安装最新版本的 gcloud CLI 。
如需获取当前的 gcloud CLI 版本,请运行 gcloud --version。
如需更新 gcloud CLI 版本,请运行 gcloud components update。
获取以下 IAM 权限:
cloudsql.instances.getDiskShrinkConfig
cloudsql.instances.performDiskShrink
以下任一角色都具有这些权限。在分配角色时,我们建议您应用最小权限原则:
Cloud SQL 管理员 (roles/cloudsql.admin)
Cloud SQL Editor (roles/cloudsql.editor)
如需了解详情,请参阅以下资源:
准备实例
在开始之前,请完成以下要求。
这些步骤对于主实例和只读副本都是相同的。
如果更新的是只读副本,请务必先缩小主实例的容量,然后再缩小副本的大小。
获取 要管理的实例所属项目的项目 ID。
检查实例的当前状态 ,确保其正在运行。一种检查方法是使用 describe 命令:
gcloud sql instances describe
返回以下状态:
RUNNABLE
如果未运行,请启动实例 。
创建当前实例的备份 。这样,如果您在配置过程中遇到问题,便可以在日后恢复实例 。
停用所有可实现出站连接(或需要出站数据传输)的扩展程序或功能。
缩减实例的存储容量
以下步骤对于主实例和只读副本都是相同的。
检查实例的目标最小存储空间容量和估计的操作时间。此信息可帮助您规划存储空间缩减操作。
注意 : 此功能不适用于只读副本。读取副本的存储容量通常与其关联的主实例相同。
gcloud 运行 gcloud sql instances get-storage-shrink-config 命令:
gcloud sql instances get-storage-shrink-config INSTANCE_NAME
替换以下内容:
响应包含 minimalTargetSizeGb 的值。您可以使用此值来确定在运行存储空间缩减操作时要用于 --storage-size 参数的值。
响应还会返回一条包含估计操作时间的消息,类似于以下内容:
...
"The estimated operation time is 20 minutes".
REST v1 使用 GET 方法查看实例的目标最小存储容量。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :主实例所在项目的名称。
INSTANCE_ID :主实例的 ID。
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /getDiskShrinkConfig
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /getDiskShrinkConfig"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /getDiskShrinkConfig" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#instance",
"min_target_size_gb": "1234"
"message": "The size of your instance's storage impacts IOPS, and therefore shrinking your storage
may have a negative impact on IOPS. Before shrinking your storage, please refer to our
documentation on Cloud SQL limits to understand what impact shrinking your storage might have:
https://cloud.google.com/sql/docs/quotas#fixed-limits. Additionally, we recommend leaving an
appropriate buffer for operational purposes, like reindexing, etc. We recommend a buffer of at
least 100 GB or 20% more than current usage, whichever is larger. For more details, please refer
to: https://cloud.google.com/sql/docs/shared-responsibility. The estimated operation time is
20 minutes."
}
响应包含 min_target_size_gb 的值。您可以使用此值来确定在运行存储空间缩减操作时要用于 --storage-size 参数的值。
响应还会返回一条包含估计操作时间的消息,类似于以下内容:
...
"The estimated operation time is 20 minutes".
REST v1beta4 使用 GET 方法查看实例的目标最小存储容量。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :主实例所在项目的名称。
INSTANCE_ID :主实例的 ID。
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /getDiskShrinkConfig
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /getDiskShrinkConfig"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /getDiskShrinkConfig" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#instance",
"min_target_size_gb": "1234"
"message": "The size of your instance's storage impacts IOPS, and therefore shrinking your storage
may have a negative impact on IOPS. Before shrinking your storage, please refer to our
documentation on Cloud SQL limits to understand what impact shrinking your storage might have:
https://cloud.google.com/sql/docs/quotas#fixed-limits. Additionally, we recommend leaving an
appropriate buffer for operational purposes, like reindexing, etc. We recommend a buffer of at
least 100 GB or 20% more than current usage, whichever is larger. For more details, please refer
to: https://cloud.google.com/sql/docs/shared-responsibility. The estimated operation time is
20 minutes."
}
响应包含 min_target_size_gb 的值。您可以使用此值来确定在运行存储空间缩减操作时要用于 --storage-size 参数的值。
响应还会返回一条包含估计操作时间的消息,类似于以下内容:
...
"The estimated operation time is 20 minutes".
缩减实例的存储容量。
gcloud 运行以下命令以缩小实例上的存储空间:
gcloud sql instances perform-storage-shrink INSTANCE_NAME \
--storage-size= TARGET_STORAGE_SIZE --async
替换以下内容:
INSTANCE_NAME :实例的名称。
TARGET_STORAGE_SIZE :目标存储容量(以 GB 为单位)。例如,100 GB。
我们建议使用 --async 标志以异步方式等待操作完成。
REST v1
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :实例所在项目的 ID。
INSTANCE_ID :实例的 ID。
TARGET_STORAGE_SIZE :目标存储空间大小(以 GB 为单位)。
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /performDiskShrink
请求 JSON 正文:
{
"targetSizeGb": TARGET_STORAGE_SIZE
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json 的文件中,然后执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /performDiskShrink"
PowerShell (Windows)
将请求正文保存在名为 request.json 的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /performDiskShrink" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2019-09-25T22:19:33.735Z",
"operationType": "UPDATE",
"name": "operation-id",
"targetId": "INSTANCE_ID ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/operation-id",
"targetProject": "PROJECT_ID "
}
REST v1beta4
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :实例所在项目的 ID。
INSTANCE_ID :实例的 ID。
TARGET_STORAGE_SIZE :实例的目标存储空间大小。
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /performDiskShrink
请求 JSON 正文:
{
"targetSizeGb": TARGET_STORAGE_SIZE
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json 的文件中,然后执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /performDiskShrink"
PowerShell (Windows)
将请求正文保存在名为 request.json 的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /performDiskShrink" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2019-09-25T22:19:33.735Z",
"operationType": "UPDATE",
"name": "operation-id",
"targetId": "INSTANCE_ID ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/operation-id",
"targetProject": "PROJECT_ID "
}
如需检查存储空间缩减操作的状态,请参阅检查操作的状态 。
取消存储空间缩减操作
获取存储空间缩减操作 ID。
您可以运行以下 list 命令来检索操作 ID:
gcloud sql operations list
发送取消请求。
gcloud 运行以下命令可取消请求:
gcloud sql operations cancel OPERATION_ID
替换以下内容:
OPERATION_ID :要取消的存储空间缩减操作的 ID。
REST v1
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :实例所在项目的 ID。
OPERATION_ID :要取消的存储空间缩减操作的 ID。
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID /cancel
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID /cancel"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID /cancel" | Select-Object -Expand Content
您应该会收到一个成功的状态代码 (2xx) 和一个空响应。
REST v1beta4
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :实例所在项目的 ID。
OPERATION_ID :要取消的存储空间缩减操作的 ID。
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID /cancel
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID /cancel"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID /cancel" | Select-Object -Expand Content
您应该会收到一个成功的状态代码 (2xx) 和一个空响应。
查看取消请求或其他操作的状态
如需检查请求的状态,请运行以下命令:
gcloud
获取取消请求的操作 ID:
gcloud sql operations list
检查操作的状态:
gcloud sql operations describe OPERATION_ID
替换以下内容:
OPERATION_ID :要检查的操作的 ID。
REST v1
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :实例所在项目的名称。
OPERATION_ID :存储空间缩减操作的 ID。
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID "
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "RUNNING",
"user": "user@example.com",
"insertTime": "2023-12-18T22:43:09.849Z",
"startTime": "2023-12-18T22:43:10.373Z",
"operationType": "UPDATE",
"name": "OPERATION_ID",
"targetId": "example_instance",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID ",
"targetProject": "PROJECT_ID"
}
REST v1beta4
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :实例所在项目的名称。
OPERATION_ID :存储空间缩减操作的 ID。
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID "
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "RUNNING",
"user": "user@example.com",
"insertTime": "2023-12-18T22:43:09.849Z",
"startTime": "2023-12-18T22:43:10.373Z",
"operationType": "UPDATE",
"name": "OPERATION_ID",
"targetId": "example_instance",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID ",
"targetProject": "PROJECT_ID"
}
问题排查
如需了解问题排查,请参阅更新存储空间时出现的问题 。
后续步骤
发送反馈
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可 获得了许可,并且代码示例已根据 Apache 2.0 许可 获得了许可。有关详情,请参阅 Google 开发者网站政策 。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2026-03-31。
需要向我们提供更多信息?
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2026-03-31。"],[],[]]