我可以通过 API 或以编程方式更改 Cloud SQL 实例的 CPU 和内存数量吗?
Can I change a Cloud SQL instance's number of CPUs and memory via API or programmatically?
我想通过 API 将 PostgreSQL 实例的 CPU 和内存数量编辑为自定义值,例如 2 个 vCPU 和 5 GB 内存,但还没有找到这样做的方法.
Instance settings page shows Cores and Memory as options, but when I try setting a simple JSON with the curl example given here,
{
"settings": {
"cores": 2,
"memory": 5
}
}
没有任何反应。
我找到了一种获取现有设置的方法,通过 curl -X GET -H "Authorization: Bearer "$(gcloud auth print-access-token) -H "Content-Type: application/json; charset=utf-8" "https://sqladmin.googleapis.com/v1/projects/MYPROJECT/instances/MYINSTANCE"
返回的 JSON 有 dataDiskSizeGb
,但与 CPU 或内存无关,这对我来说很明显。
{
"kind": "sql#instance",
"state": "RUNNABLE",
"databaseVersion": "POSTGRES_12",
"settings": {
"authorizedGaeApplications": [],
"tier": "db-custom-1-3840",
"kind": "sql#settings",
"availabilityType": "ZONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration": {
"privateNetwork": "projects/MYPROJECT/global/networks/default",
"authorizedNetworks": [],
"ipv4Enabled": true
},
"locationPreference": {
"zone": "southamerica-east1-c",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow": {
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration": {
"startTime": "08:00",
"kind": "sql#backupConfiguration",
"location": "us",
"backupRetentionSettings": {
"retentionUnit": "COUNT",
"retainedBackups": 7
},
"enabled": true,
"replicationLogArchivingEnabled": false,
"pointInTimeRecoveryEnabled": false,
"transactionLogRetentionDays": 7
},
"settingsVersion": "4",
"storageAutoResizeLimit": "0",
"storageAutoResize": false,
"dataDiskSizeGb": "10"
},
"etag": "079...039",
"ipAddresses": [
{
"type": "PRIMARY",
"ipAddress": "xx.xxx.x.xxx"
},
{
"type": "OUTGOING",
"ipAddress": "xx.xx.xxx.xx"
},
{
"type": "PRIVATE",
"ipAddress": "xx.xx.xxx.xx"
}
],
"serverCaCert": {
"kind": "sql#sslCert",
"certSerialNumber": "0",
"cert": "-----BEGIN CERTIFICATE-----\nMII......c=\n-----END CERTIFICATE-----",
"commonName": "C=US,O=Google\, Inc,CN=Google Cloud SQL Server CA,dnQualifier=9f7...e0c",
"sha1Fingerprint": "fff...8fb",
"instance": "MYINSTANCE",
"createTime": "2021-10-05T17:59:18.971Z",
"expirationTime": "2031-10-03T18:00:18.971Z"
},
"instanceType": "CLOUD_SQL_INSTANCE",
"project": "MYPROJECT",
"serviceAccountEmailAddress": "abc...@gcp-sa-cloud-sql.iam.gserviceaccount.com",
"backendType": "SECOND_GEN",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/MYPROJECT/instances/MYINSTANCE",
"connectionName": "MYPROJECT:southamerica-east1:MYINSTANCE",
"name": "MYINSTANCE",
"region": "southamerica-east1",
"gceZone": "southamerica-east1-c",
"createTime": "2021-10-05T17:57:47.539Z"
}
要更新CPU的数量和内存,在"settings" REST reference上有一个字段"tier"
代表实例的CPU和内存。在你的例子中它是 "db-custom-1-3840"
,值代表 CPU 和 Memory (db-custom-[CPU]-[Memory]) 这个表示它有 1 CPU 和 3840 内存。把机器改成2vCPU和5GB内存"tier"
应该有值"db-custom-2-5120"
.
出于测试目的,我最初创建了一个具有 26 GB 内存的 4 vCPU。
有关参考,请参阅初始实例配置:
要更改 CPU 和内存,请参阅以下步骤:
request.json:
{
"settings": {
"tier": "db-custom-2-5120"
}
}
注意:内存的值应该是 256MB 的倍数,因此值为 5120。
卷曲命令:
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/your-project-name/instances/your-instance-name"
这将 return 一个长 运行ning 操作:
当我 运行 GET curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) https://sqladmin.googleapis.com/v1/projects/your-project-name/instances/your-instance-name
变化被反映出来。
查看 GET 响应片段:
在 Cloud Console 查看新实例信息 > SQL > 编辑:
我想通过 API 将 PostgreSQL 实例的 CPU 和内存数量编辑为自定义值,例如 2 个 vCPU 和 5 GB 内存,但还没有找到这样做的方法.
Instance settings page shows Cores and Memory as options, but when I try setting a simple JSON with the curl example given here,
{
"settings": {
"cores": 2,
"memory": 5
}
}
没有任何反应。
我找到了一种获取现有设置的方法,通过 curl -X GET -H "Authorization: Bearer "$(gcloud auth print-access-token) -H "Content-Type: application/json; charset=utf-8" "https://sqladmin.googleapis.com/v1/projects/MYPROJECT/instances/MYINSTANCE"
返回的 JSON 有 dataDiskSizeGb
,但与 CPU 或内存无关,这对我来说很明显。
{
"kind": "sql#instance",
"state": "RUNNABLE",
"databaseVersion": "POSTGRES_12",
"settings": {
"authorizedGaeApplications": [],
"tier": "db-custom-1-3840",
"kind": "sql#settings",
"availabilityType": "ZONAL",
"pricingPlan": "PER_USE",
"replicationType": "SYNCHRONOUS",
"activationPolicy": "ALWAYS",
"ipConfiguration": {
"privateNetwork": "projects/MYPROJECT/global/networks/default",
"authorizedNetworks": [],
"ipv4Enabled": true
},
"locationPreference": {
"zone": "southamerica-east1-c",
"kind": "sql#locationPreference"
},
"dataDiskType": "PD_SSD",
"maintenanceWindow": {
"kind": "sql#maintenanceWindow",
"hour": 0,
"day": 0
},
"backupConfiguration": {
"startTime": "08:00",
"kind": "sql#backupConfiguration",
"location": "us",
"backupRetentionSettings": {
"retentionUnit": "COUNT",
"retainedBackups": 7
},
"enabled": true,
"replicationLogArchivingEnabled": false,
"pointInTimeRecoveryEnabled": false,
"transactionLogRetentionDays": 7
},
"settingsVersion": "4",
"storageAutoResizeLimit": "0",
"storageAutoResize": false,
"dataDiskSizeGb": "10"
},
"etag": "079...039",
"ipAddresses": [
{
"type": "PRIMARY",
"ipAddress": "xx.xxx.x.xxx"
},
{
"type": "OUTGOING",
"ipAddress": "xx.xx.xxx.xx"
},
{
"type": "PRIVATE",
"ipAddress": "xx.xx.xxx.xx"
}
],
"serverCaCert": {
"kind": "sql#sslCert",
"certSerialNumber": "0",
"cert": "-----BEGIN CERTIFICATE-----\nMII......c=\n-----END CERTIFICATE-----",
"commonName": "C=US,O=Google\, Inc,CN=Google Cloud SQL Server CA,dnQualifier=9f7...e0c",
"sha1Fingerprint": "fff...8fb",
"instance": "MYINSTANCE",
"createTime": "2021-10-05T17:59:18.971Z",
"expirationTime": "2031-10-03T18:00:18.971Z"
},
"instanceType": "CLOUD_SQL_INSTANCE",
"project": "MYPROJECT",
"serviceAccountEmailAddress": "abc...@gcp-sa-cloud-sql.iam.gserviceaccount.com",
"backendType": "SECOND_GEN",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/MYPROJECT/instances/MYINSTANCE",
"connectionName": "MYPROJECT:southamerica-east1:MYINSTANCE",
"name": "MYINSTANCE",
"region": "southamerica-east1",
"gceZone": "southamerica-east1-c",
"createTime": "2021-10-05T17:57:47.539Z"
}
要更新CPU的数量和内存,在"settings" REST reference上有一个字段"tier"
代表实例的CPU和内存。在你的例子中它是 "db-custom-1-3840"
,值代表 CPU 和 Memory (db-custom-[CPU]-[Memory]) 这个表示它有 1 CPU 和 3840 内存。把机器改成2vCPU和5GB内存"tier"
应该有值"db-custom-2-5120"
.
出于测试目的,我最初创建了一个具有 26 GB 内存的 4 vCPU。 有关参考,请参阅初始实例配置:
要更改 CPU 和内存,请参阅以下步骤:
request.json:
{
"settings": {
"tier": "db-custom-2-5120"
}
}
注意:内存的值应该是 256MB 的倍数,因此值为 5120。
卷曲命令:
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/your-project-name/instances/your-instance-name"
这将 return 一个长 运行ning 操作:
当我 运行 GET curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) https://sqladmin.googleapis.com/v1/projects/your-project-name/instances/your-instance-name
变化被反映出来。
查看 GET 响应片段:
在 Cloud Console 查看新实例信息 > SQL > 编辑: