Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
縮減執行個體儲存空間容量
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁說明如何使用儲存空間縮減功能,管理 Cloud SQL 執行個體的儲存空間容量。
事前準備
查看這項功能的限制。
如果您使用 gcloud CLI,請務必使用最新版本的 Google Cloud SDK 和 gcloud CLI。
- 安裝最新版 gcloud CLI (gcloud CLI 563.0.0 以上版本)。
- 如要取得目前的 gcloud CLI 版本,請執行
gcloud --version。
- 如要更新 gcloud CLI 版本,請執行
gcloud components update。
取得下列 IAM 權限:
cloudsql.instances.getDiskShrinkConfig
cloudsql.instances.performDiskShrink
下列任一角色都具備這些權限。指派角色時,建議您採用最低權限原則:
- Cloud SQL 管理員 (
roles/cloudsql.admin)
- Cloud SQL 編輯者 (
roles/cloudsql.editor)
詳情請參閱下列資源:
準備執行個體
開始前,請先完成下列要求。
主要執行個體和唯讀備用資源的步驟相同。
如要更新唯讀副本,請務必先縮減主要執行個體的容量,再縮減副本的大小。
取得專案 ID:找出要管理的執行個體所屬專案,並取得該專案的 ID。
檢查執行個體的目前狀態,確認執行個體正在執行。如要檢查,請使用 describe 指令:
gcloud sql instances describe
傳回下列狀態:
RUNNABLE
如果沒有,請啟動執行個體。
建立目前執行個體的備份。這樣一來,如果設定期間發生問題,您稍後就能還原執行個體。
如果您執行的是 PostgreSQL 執行個體,請將 max_wal_size 旗標值設為小於 5128 MB。如果 max_wal_size 值過大,執行個體啟動速度可能會變慢,作業也可能失敗。
停用所有可啟用輸出連線 (或需要輸出資料傳輸) 的擴充功能或功能。
舉例來說,您可能會使用下列其中一個擴充功能或功能建立輸出連線,因此在執行儲存空間縮減作業前,請先停用這些連線:
dblink 項擴充功能
PL/proxy 項擴充功能
pglogical 項擴充功能
- 外部資料包裝函式 (例如
postgres_fdw、oracle_fdw 和 tds_fdw)
- PostgreSQL 10 以上版本中的邏輯複製
縮減執行個體的儲存空間容量
主要執行個體和唯讀複本的步驟相同。
檢查執行個體的目標最低儲存空間容量和預估作業時間。這項資訊有助於規劃儲存空間縮減作業。
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
更改下列內容:
- INSTANCE_NAME:執行個體的名稱。
- TARGET_STORAGE_SIZE:目標儲存空間容量 (以 GB 為單位)。例如 100 GB。
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"
}
疑難排解
如需疑難排解資訊,請參閱「更新儲存空間容量時發生問題」。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2026-05-12 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2026-05-12 (世界標準時間)。"],[],[]]