本頁面說明如何啟動執行個體、停止執行個體,以及重新啟動執行中的執行個體。
啟用政策
啟動、停止或重新啟動執行個體時,您必須設定要使用的啟用政策。啟用政策會指出是否已啟用執行個體,以便接受連線要求。
啟用政策選項如下:
ALWAYS
:執行個體一律處於啟用及執行中狀態。NEVER
:未重新啟動執行個體。
ALWAYS
。如果您不使用執行個體,可以將其啟用政策設為 NEVER
,避免產生執行個體費用。
啟動執行個體
如要啟動已停止的執行個體,請按照下列步驟操作:
控制台
-
前往 Google Cloud 控制台的「Cloud SQL 執行個體」頁面。
- 如要開啟執行個體的「總覽」頁面,請按一下執行個體名稱。
- 按一下「啟動」。
- 在「Start database instance?」(要啟動資料庫執行個體嗎?) 對話方塊中,按一下「Start」。
執行個體的啟用政策設為「Always」(一律啟用),執行個體即會啟動。
gcloud
使用「ALWAYS」做為啟用政策:
gcloud sql instances patch INSTANCE_NAME \ --activation-policy=ALWAYS
REST v1
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- instance-id:執行個體 ID
- activation-policy:啟用政策為「一律啟用」或「永不啟用」
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id
JSON 要求主體:
{ "settings": { "activationPolicy": "activation-policy" } }
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id", "status": "PENDING", "user": "[email protected]", "insertTime": "2020-01-20T21:30:35.667Z", "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
- activation-policy:啟用政策為「一律啟用」或「永不啟用」
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id
JSON 要求主體:
{ "settings": { "activationPolicy": "activation-policy" } }
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id", "status": "PENDING", "user": "[email protected]", "insertTime": "2020-01-20T21:30:35.667Z", "operationType": "UPDATE", "name": "operation-id", "targetId": "instance-id", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id", "targetProject": "project-id" }
停止執行個體
您可以視需要手動停止執行個體。不過請注意,執行個體停止後即會持續處於停用狀態,除非您重新啟動,否則該執行個體不會回應任何應用程式連線。
在您停止執行個體之後,系統就不會繼續累計該執行個體的費用,執行個體資料不會受到影響,且儲存空間和 IP 位址的費用仍會持續計費。
停止執行個體:
控制台
-
前往 Google Cloud 控制台的「Cloud SQL 執行個體」頁面。
- 如要開啟執行個體的「總覽」頁面,請按一下執行個體名稱。
- 按一下「停止」。
- 在「Stop database instance?」(要停止資料庫執行個體嗎?) 對話方塊中,按一下「Stop」。
執行個體的啟用政策設為
Off
(永不),執行個體即會停止。
gcloud
gcloud sql instances patch INSTANCE_NAME \ --activation-policy=NEVER
REST v1
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- instance-id:執行個體 ID
- activation-policy:啟用政策為「永不」
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id
JSON 要求主體:
{ "settings": { "activationPolicy": "activation-policy" } }
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id", "status": "PENDING", "user": "[email protected]", "insertTime": "2020-01-20T21:30:35.667Z", "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
- activation-policy:啟用政策為「永不」
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id
JSON 要求主體:
{ "settings": { "activationPolicy": "activation-policy" } }
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id", "status": "PENDING", "user": "[email protected]", "insertTime": "2020-01-20T21:30:35.667Z", "operationType": "UPDATE", "name": "operation-id", "targetId": "instance-id", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id", "targetProject": "project-id" }
重新啟動執行個體
重新啟動執行個體會清空執行個體的連線並停止執行個體。接著,執行個體會重新啟動並準備好接受新的連線。
重新啟動執行個體不會變更執行個體的公開或私人 IP 位址。
重新啟動執行個體:
控制台
-
前往 Google Cloud 控制台的「Cloud SQL 執行個體」頁面。
- 如要開啟執行個體的「總覽」頁面,請按一下執行個體名稱。
- 按一下 [Restart]。
- 在「Restart database instance?」(要重新啟動資料庫執行個體嗎?) 對話方塊中,按一下「Restart」(重新啟動)。
gcloud
重新啟動執行個體:
gcloud sql instances restart INSTANCE_NAME
REST v1
使用任何要求資料之前,請先替換以下項目:
- project-id:專案 ID
- instance-id:執行個體 ID
- activation-policy:啟用政策為「一律啟用」或「永不啟用」
HTTP 方法和網址:
POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/restart
JSON 要求主體:
{ "settings": { "activationPolicy": "activation-policy" } }
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id", "status": "PENDING", "user": "[email protected]", "insertTime": "2020-01-20T21:30:35.667Z", "operationType": "RESTART", "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
- activation-policy:啟用政策為「一律啟用」或「永不啟用」
HTTP 方法和網址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/restart
JSON 要求主體:
{ "settings": { "activationPolicy": "activation-policy" } }
如要傳送要求,請展開以下其中一個選項:
您應該會收到如下的 JSON 回應:
{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id", "status": "PENDING", "user": "[email protected]", "insertTime": "2020-01-20T21:30:35.667Z", "operationType": "RESTART", "name": "operation-id", "targetId": "instance-id", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id", "targetProject": "project-id" }