gpt4 book ai didi

google-cloud-sql - 我可以通过 API 或以编程方式更改 Cloud SQL 实例的 CPU 数量和内存吗?

转载 作者:行者123 更新时间:2023-12-04 14:48:46 25 4
gpt4 key购买 nike

我想通过 API 将 PostgreSQL 实例的 CPU 和内存数量编辑为自定义值,例如 2 个 vCPU 和 5 GB 内存,但还没有找到这样做的方法。

Instance settings页面将核心和内存显示为选项,但是当我尝试使用给定的 curl 示例设置简单的 JSON 时 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 和内存 (db-custom-[CPU]-[Memory])表示它有1个CPU和3840内存。要将机器更改为 2vCPU 和 5GB 内存,"tier" 的值应为 "db-custom-2-5120"

出于测试目的,我最初创建了一个 4 个 vCPU 和 26 GB 内存。有关引用,请参阅初始实例配置:

enter image description here

要更改 CPU 和内存,请参阅以下步骤:

请求.json:

{
"settings": {
"tier": "db-custom-2-5120"
}
}

注意:内存的值应该是 256MB 的倍数,因此值为 5120。

curl 命令:

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"

这将返回一个长时间运行的操作:

enter image description here

当我运行 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 更改已反射(reflect)出来。

查看 GET 响应片段:

enter image description here

在 Cloud Console 查看新实例信息 > SQL > 编辑:

enter image description here

关于google-cloud-sql - 我可以通过 API 或以编程方式更改 Cloud SQL 实例的 CPU 数量和内存吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69455697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com