建立及管理讀取集區
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
MySQL
| PostgreSQL
| SQL Server
本頁說明如何為大量讀取工作負載建立及管理讀取集區。
事前準備
- 讀取集區包含主要執行個體的副本。如果您尚未建立 Cloud SQL Enterprise Plus 版本主要執行個體,請先建立。雖然讀取集區支援公開 IP 連線,但為了配合本指南的目的,請建立具有私人 IP (PSA) 連線的主要執行個體。如要進一步瞭解主要執行個體和複製作業,請參閱「關於 Cloud SQL 中的複製作業」。
- 建立主要執行個體後,請為根使用者選擇密碼,然後執行下列指令,在主要執行個體上設定密碼。請儲存這個密碼,以便日後連線至讀取集區時使用。
gcloud --project=PROJECT \
sql users set-password root --host=% \
--instance=PRIMARY_INSTANCE_NAME --prompt-for-password
請將以下項目改為對應的值:
- PROJECT:您要將主要執行個體和讀取集區放置在其中的專案名稱。
- PRIMARY_INSTANCE_NAME:主要執行個體的名稱。
建立讀取集區
gcloud
如要瞭解如何安裝及開始使用 gcloud CLI,請參閱「安裝 gcloud CLI」。如要瞭解如何啟動 Cloud Shell,請參閱「使用 Cloud Shell」一文。
使用下列 gcloud beta sql instances create
指令,建立包含多個讀取集區節點的讀取集區:
gcloud beta sql instances create READ_POOL_NAME \
--tier=TIER --edition=ENTERPRISE_PLUS \
--instance-type=READ_POOL_INSTANCE --node-count=NODE_COUNT \
--master-instance-name=PRIMARY_INSTANCE_NAME
請將以下項目改為對應的值:
- READ_POOL_NAME:您要用於讀取集區的名稱。
- TIER:您要為讀取集區中每個讀取集區節點使用的機器類型,例如
db-perf-optimized-N-4
。
- NODE_COUNT:您想要在讀取集區中建立的讀取集區節點數量。請選擇介於
1
到 20
之間的任何數字。
- PRIMARY_INSTANCE_NAME:與讀取集區相關聯的主執行個體名稱,例如
my-primary-instance
。
REST v1
使用執行個體資源的
insert
方法,建立包含多個讀取集區節點的讀取集區。databaseVersion
屬性必須與主要屬性相同。
使用任何要求資料之前,請先替換以下項目:
- PROJECT:您要將主要執行個體和讀取集區放置在其中的專案名稱。
- REGION:讀取集區的區域,例如
us-east1
。區域必須與主要執行個體相同。
- TIER:您要為讀取集區中每個讀取集區節點使用的機器類型,例如
db-perf-optimized-N-4
。
- PRIMARY_INSTANCE_NAME:主要執行個體的名稱。
- READ_POOL_NAME:您要用於讀取集區的名稱,例如
my-read-pool
。
- DATABASE_VERSION:您要使用的資料庫版本。例如
POSTGRES_16
。
- NODE_COUNT:您希望讀取集區中的讀取集區節點數量。請選擇介於
1
到 20
之間的任何數字。
- FULL_NETWORK_NAME:您希望讀取集區所在的完整網路路徑,例如
projects/vpc-host-project/global/networks/my-network-name
。
HTTP 方法和網址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT/instances
JSON 要求主體:
{
"name": "READ_POOL_NAME",
"masterInstanceName": "PRIMARY_INSTANCE_NAME",
"project": "PROJECT",
"databaseVersion": "DATABASE_VERSION",
"region": "REGION",
"instanceType": "READ_POOL_INSTANCE",
"nodeCount": NODE_COUNT,
"settings": {
"tier": "TIER",
"edition": "ENTERPRISE_PLUS",
"ipConfiguration": {
"ipv4Enabled": false,
"privateNetwork": "FULL_NETWORK_NAME"
}
}
}
如要傳送要求,請展開以下其中一個選項:
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/instances"
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/instances" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "CREATE_READ_POOL",
"name": "OPERATION_ID",
"targetId": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
REST v1beta4
使用執行個體資源的
insert
方法,建立包含多個讀取集區節點的讀取集區。databaseVersion
屬性必須與主要屬性相同。
使用任何要求資料之前,請先替換以下項目:
- PROJECT:您要將主要執行個體和讀取集區放置在其中的專案名稱。
- REGION:讀取集區的區域,例如
us-east1
。區域必須與主要執行個體相同。
- TIER:您要為讀取集區中每個讀取集區節點使用的機器類型,例如
db-perf-optimized-N-4
。
- PRIMARY_INSTANCE_NAME:主要執行個體的名稱。
- READ_POOL_NAME:您要用於讀取集區的名稱,例如
my-read-pool
。
- DATABASE_VERSION:您要使用的資料庫版本。例如
POSTGRES_16
。
- NODE_COUNT:您希望讀取集區中的讀取集區節點數量。請選擇介於
1
到 20
之間的任何數字。
- FULL_NETWORK_NAME:您希望讀取集區所在的完整網路路徑,例如
projects/vpc-host-project/global/networks/my-network-name
。
HTTP 方法和網址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances
JSON 要求主體:
{
"name": "READ_POOL_NAME",
"masterInstanceName": "PRIMARY_INSTANCE_NAME",
"project": "PROJECT",
"databaseVersion": "DATABASE_VERSION",
"region": "REGION",
"instanceType": "READ_POOL_INSTANCE",
"nodeCount": NODE_COUNT,
"settings": {
"tier": "TIER",
"edition": "ENTERPRISE_PLUS",
"ipConfiguration": {
"ipv4Enabled": false,
"privateNetwork": "FULL_NETWORK_NAME"
}
}
}
如要傳送要求,請展開以下其中一個選項:
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/instances"
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/instances" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "CREATE_READ_POOL",
"name": "OPERATION_ID",
"targetId": "INSTANCE_ID",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
將唯讀備用資源轉換為讀取集區
您可以指定集區中的節點數量,將現有的 Cloud SQL Enterprise Plus 版本唯讀備用資源轉換為讀取集區。在這個轉換程序期間,備援 IP 會成為讀取集區 IP (讀取端點),因此現有用戶端不必重新設定即可連線至集區。
新建立的讀取集區節點將與原始唯讀備用資源具有相同的機器類型和設定。如要變更這個機器類型或設定,必須執行另一項作業。這項操作僅支援可用區唯讀備用資源。如要將高可用性 (HA) 唯讀備用資源轉換為唯讀集區,您必須先將其轉換為區域唯讀備用資源。
詳情請參閱「編輯讀取集區設定」。
gcloud
如要瞭解如何安裝及開始使用 gcloud CLI,請參閱「安裝 gcloud CLI」。如要瞭解如何啟動 Cloud Shell,請參閱「使用 Cloud Shell」一文。
使用下列 gcloud beta sql instances patch
指令轉換唯讀副本,以便與唯讀集區搭配使用:
gcloud beta sql instances patch READ_REPLICA_NAME \
--instance-type=READ_POOL_INSTANCE --node-count=NODE_COUNT
請將以下項目改為對應的值:
- READ_REPLICA_NAME:您要轉換的唯讀副本名稱。
- NODE_COUNT:您想要在讀取集區中建立的讀取集區節點數量。請選擇介於
1
到 20
之間的任何數字。
REST v1
使用執行個體資源的
patch
方法,將唯讀備用資源轉換為唯讀集區。
使用任何要求資料之前,請先替換以下項目:
- READ_REPLICA_NAME:您要轉換的讀取用副本名稱,例如
my-read-replica
。
- NODE_COUNT:您希望讀取集區中的讀取集區節點數量。請選擇介於
1
到 20
之間的任何數字。
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_REPLICA_NAME
JSON 要求主體:
{
"instanceType": "READ_POOL_INSTANCE",
"nodeCount": NODE_COUNT
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \
-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/instances/READ_REPLICA_NAME"
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_REPLICA_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_REPLICA_NAME",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "OPERATION_ID",
"targetId": "READ_REPLICA_NAME",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
REST v1beta4
使用執行個體資源的
patch
方法,將唯讀備用資源轉換為唯讀集區。
使用任何要求資料之前,請先替換以下項目:
- READ_REPLICA_NAME:您要轉換的讀取用副本名稱,例如
my-read-replica
。
- NODE_COUNT:您希望讀取集區中的讀取集區節點數量。請選擇介於
1
到 20
之間的任何數字。
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_REPLICA_NAME
JSON 要求主體:
{
"instanceType": "READ_POOL_INSTANCE",
"nodeCount": NODE_COUNT
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \
-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/instances/READ_REPLICA_NAME"
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_REPLICA_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_REPLICA_NAME",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "OPERATION_ID",
"targetId": "READ_REPLICA_NAME",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
將讀取集區轉換為唯讀備用資源
gcloud
如要瞭解如何安裝及開始使用 gcloud CLI,請參閱「安裝 gcloud CLI」。如要瞭解如何啟動 Cloud Shell,請參閱「使用 Cloud Shell」一文。
使用下列 gcloud beta sql instances patch
指令轉換唯讀副本,以便與唯讀集區搭配使用:
gcloud beta sql instances patch READ_POOL_NAME \
--instance-type=READ_REPLICA_INSTANCE
請將以下項目改為對應的值:
- READ_POOL_NAME:您要轉換的讀取集區名稱。
REST v1
使用執行個體資源的
patch
方法,將讀取集區轉換為唯讀備用資源。
使用任何要求資料之前,請先替換以下項目:
- READ_POOL_NAME:讀取集區的名稱,例如
my-read-pool
。
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME
JSON 要求主體:
{
"instanceType": "READ_REPLICA_INSTANCE"
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \
-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/instances/READ_POOL_NAME"
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "OPERATION_ID",
"targetId": "READ_POOL_NAME",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
REST v1beta4
使用執行個體資源的
patch
方法,將讀取集區轉換為唯讀備用資源。
使用任何要求資料之前,請先替換以下項目:
- READ_POOL_NAME:讀取集區的名稱,例如
my-read-pool
。
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME
JSON 要求主體:
{
"instanceType": "READ_REPLICA_INSTANCE"
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \
-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/instances/READ_POOL_NAME"
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "OPERATION_ID",
"targetId": "READ_POOL_NAME",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
查看讀取集區資訊
gcloud
如要瞭解如何安裝及開始使用 gcloud CLI,請參閱「安裝 gcloud CLI」。如要瞭解如何啟動 Cloud Shell,請參閱「使用 Cloud Shell」一文。
使用下列 gcloud beta sql instances describe
指令來描述讀取集區:
gcloud beta sql instances describe READ_POOL_NAME
請將以下項目改為對應的值:
- READ_POOL_NAME:要說明的讀取集區名稱。
以下是包含 IP 位址和節點資訊的回應範例:
...
connectionName: my-project:us-central1:read-pool
ipAddresses:
- ipAddress: 10.3.0.108
type: PRIVATE
nodeCount: 2
nodes:
- dnsName: c5bdacb09ffc.j10o8yqc7pve.us-central1.sql.goog.
gceZone: us-central1-f
ipAddresses:
- ipAddress: 10.3.0.112
type: PRIVATE
name: read-pool-node-01
state: RUNNABLE
- dnsName: 8f77c454d6b2.j10o8yqc7pve.us-central1.sql.goog.
gceZone: us-central1-c
ipAddresses:
- ipAddress: 10.3.0.113
type: PRIVATE
name: read-pool-node-02
state: RUNNABLE
REST v1
使用
get
方法查看讀取集區詳細資料。
使用任何要求資料之前,請先替換以下項目:
- PROJECT:讀取集區所在專案的名稱。
- READ_POOL_NAME:讀取集區的名稱,例如
my-read-pool
。
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME"
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/instances/READ_POOL_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
[...],
"connectionName": "my-project:us-central1:read-pool",
"ipAddresses": [
{
"type": "PRIVATE",
"ipAddress": "10.3.0.108"
}
],
"nodeCount": 2,
"nodes": [
{
"ipAddresses": [
{
"type": "PRIVATE",
"ipAddress": "10.3.0.112"
}
],
"name": "read-pool-node-01",
"gceZone": "us-central1-f",
"dnsName": "c5bdacb09ffc.j10o8yqc7pve.us-central1.sql.goog.",
"state": "RUNNABLE"
},
{
"ipAddresses": [
{
"type": "PRIVATE",
"ipAddress": "10.3.0.113"
}
],
"name": "read-pool-node-02",
"gceZone": "us-central1-c",
"dnsName": "8f77c454d6b2.j10o8yqc7pve.us-central1.sql.goog.",
"state": "RUNNABLE"
}
]
}
REST v1beta4
使用
get
方法查看讀取集區詳細資料。
使用任何要求資料之前,請先替換以下項目:
- PROJECT:讀取集區所在專案的名稱。
- READ_POOL_NAME:讀取集區的名稱,例如
my-read-pool
。
HTTP 方法和網址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME"
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/instances/READ_POOL_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
{
[...],
"connectionName": "my-project:us-central1:read-pool",
"ipAddresses": [
{
"type": "PRIVATE",
"ipAddress": "10.3.0.108"
}
],
"nodeCount": 2,
"nodes": [
{
"ipAddresses": [
{
"type": "PRIVATE",
"ipAddress": "10.3.0.112"
}
],
"name": "read-pool-node-01",
"gceZone": "us-central1-f",
"dnsName": "c5bdacb09ffc.j10o8yqc7pve.us-central1.sql.goog.",
"state": "RUNNABLE"
},
{
"ipAddresses": [
{
"type": "PRIVATE",
"ipAddress": "10.3.0.113"
}
],
"name": "read-pool-node-02",
"gceZone": "us-central1-c",
"dnsName": "8f77c454d6b2.j10o8yqc7pve.us-central1.sql.goog.",
"state": "RUNNABLE"
}
]
}
新增或移除讀取集區節點
下列步驟會修改讀取集區中的讀取集區節點數量,藉此調整讀取集區的規模。但須遵守某些操作限制。詳情請參閱「讀取集區限制」。
gcloud
如要瞭解如何安裝及開始使用 gcloud CLI,請參閱「安裝 gcloud CLI」。如要瞭解如何啟動 Cloud Shell,請參閱「使用 Cloud Shell」一文。
使用下列 gcloud beta sql instances patch
指令擴充讀取集區:
gcloud beta sql instances patch READ_POOL_NAME \
--node-count=NODE_COUNT
請將以下項目改為對應的值:
- READ_POOL_NAME:讀取集區的名稱。
- NODE_COUNT:您想要在讀取集區中建立的讀取集區節點數量。請選擇介於
1
到 20
之間的任何數字。
REST v1
使用
patch
方法,藉由修改讀取集區中的讀取集區節點數量,來調整讀取集區的規模。
使用任何要求資料之前,請先替換以下項目:
- PROJECT:讀取集區所在專案的名稱。
- NODE_COUNT:您希望讀取集區中的讀取集區節點數量。請選擇介於
1
到 20
之間的任何數字。
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME
JSON 要求主體:
{
"nodeCount": NODE_COUNT
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \
-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/instances/READ_POOL_NAME"
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "OPERATION_ID",
"targetId": "READ_POOL_NAME",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
REST v1beta4
使用
patch
方法,藉由修改讀取集區中的讀取集區節點數量,來調整讀取集區的規模。
使用任何要求資料之前,請先替換以下項目:
- PROJECT:讀取集區所在專案的名稱。
- NODE_COUNT:您希望讀取集區中的讀取集區節點數量。請選擇介於
1
到 20
之間的任何數字。
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME
JSON 要求主體:
{
"nodeCount": NODE_COUNT
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \
-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/instances/READ_POOL_NAME"
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAMEINSTANCE_ID",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "OPERATION_ID",
"targetId": "READ_POOL_NAME",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
編輯讀取集區設定
下列步驟說明如何編輯讀取集區設定。如需更多詳細資訊,請參閱「關於執行個體設定」和「編輯執行個體」。
gcloud
如要瞭解如何安裝及開始使用 gcloud CLI,請參閱「安裝 gcloud CLI」。如要瞭解如何啟動 Cloud Shell,請參閱「使用 Cloud Shell」一文。
使用下列 gcloud beta sql instances patch
指令垂直擴充讀取集區,例如修改機器類型:
gcloud beta sql instances patch READ_POOL_NAME \
--tier=TIER
請將以下項目改為對應的值:
- READ_POOL_NAME:讀取集區的名稱。
- TIER:您要套用至讀取集區中每個讀取集區節點的機器類型,例如
db-perf-optimized-N-8
。
REST v1
使用
patch
方法修改讀取集區節點設定。設定會統一套用至讀取集區中的所有讀取集區節點。
使用任何要求資料之前,請先替換以下項目:
- PROJECT:讀取集區所在專案的名稱。
- TIER:您要為讀取集區中每個讀取集區節點使用的機器類型,例如
db-perf-optimized-N-4
。
- READ_POOL_NAME:讀取集區的名稱,例如
my-read-pool
。
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME
JSON 要求主體:
{
"settings": {
"tier": "TIER"
}
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \
-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/instances/READ_POOL_NAME"
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "OPERATION_ID",
"targetId": "READ_POOL_NAME",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
REST v1beta4
使用
patch
方法修改讀取集區節點設定。設定會統一套用至讀取集區中的所有讀取集區節點。
使用任何要求資料之前,請先替換以下項目:
- PROJECT:讀取集區所在專案的名稱。
- TIER:您要為讀取集區中每個讀取集區節點使用的機器類型,例如
db-perf-optimized-N-4
。
- READ_POOL_NAME:讀取集區的名稱,例如
my-read-pool
。
HTTP 方法和網址:
PATCH https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME
JSON 要求主體:
{
"settings": {
"tier": "TIER"
}
}
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X PATCH \
-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/instances/READ_POOL_NAME"
PowerShell (Windows)
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "UPDATE",
"name": "OPERATION_ID",
"targetId": "READ_POOL_NAME",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
連線至讀取集區
連線至讀取集區的方法有很多種。以下步驟說明其中一種方法,也就是在同一個虛擬私有雲網路中建立 VM,以做為連線來源,然後連線至具有私人 IP 位址的讀取集區。
如要進一步瞭解其他設定 Cloud SQL 執行個體連線方式,請參閱「關於 Cloud SQL 連線」。連線方法通常需要先取得執行個體的 IP 位址或連線名稱,如「查看讀取區資訊」一文所述。讀取集區支援其他 Cloud SQL 執行個體可用的大部分連線方法,但有一些限制。
如果您使用 Cloud SQL 驗證 Proxy 或 Cloud SQL 連接器連線,請務必更新至最新版本。針對讀取集區支援功能,最低版本需求如下:
- Cloud SQL 驗證 Proxy:v2.15.2
- Cloud SQL Python 連接器:v1.18.0
- Cloud SQL Go 連接器:v1.16.0
- Cloud SQL Node 連接器:v1.7.0
- Cloud SQL Java 連接器:1.24.0 版
刪除讀取集區
gcloud
如要瞭解如何安裝及開始使用 gcloud CLI,請參閱「安裝 gcloud CLI」。如要瞭解如何啟動 Cloud Shell,請參閱「使用 Cloud Shell」一文。
使用下列 gcloud sql instances delete
指令刪除讀取集區:
gcloud sql instances delete READ_POOL_NAME
請將以下項目改為對應的值:
- READ_POOL_NAME:要刪除的讀取集區名稱。
REST v1
使用
delete
方法刪除讀取集區。
使用任何要求資料之前,請先替換以下項目:
- PROJECT:讀取集區所在專案的名稱。
- READ_POOL_NAME:讀取集區的名稱,例如
my-read-pool
。
HTTP 方法和網址:
DELETE https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/instances/READ_POOL_NAME",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "DELETE",
"name": "OPERATION_ID",
"targetId": "READ_POOL_NAME",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
REST v1beta4
使用
delete
方法刪除讀取集區。
使用任何要求資料之前,請先替換以下項目:
- PROJECT:讀取集區所在專案的名稱。
- READ_POOL_NAME:讀取集區的名稱,例如
my-read-pool
。
HTTP 方法和網址:
DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME
如要傳送要求,請展開以下其中一個選項:
curl (Linux、macOS 或 Cloud Shell)
執行下列指令:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME"
PowerShell (Windows)
執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME" | Select-Object -Expand Content
您應該會收到如下的 JSON 回應:
回應
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/instances/READ_POOL_NAME",
"status": "PENDING",
"user": "[email protected]",
"insertTime": "2020-01-21T22:43:37.981Z",
"operationType": "DELETE",
"name": "OPERATION_ID",
"targetId": "READ_POOL_NAME",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT/operations/OPERATION_ID",
"targetProject": "PROJECT"
}
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-05-16 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-05-16 (世界標準時間)。"],[],[]]