有没有办法获取 Google 云 SQL 故障转移副本实例的详细信息?

Is there a way to get the details of a Google Cloud SQL failover replica instance?

我知道我可以使用 gcloud sql instances describe 或 Cloud SQL REST API 来获取 Cloud SQL 实例的详细信息,而且我还可以获得故障转移完成后的辅助区域(例如 gceZone)。

为 Cloud SQL 实例启用高可用性(区域)功能后,是否可以获取 Cloud SQL 故障转移副本实例的详细信息?

Is there a way to get the details of Cloud SQL failover replica instance?

,以前可以在第1代CloudSQL实例中查看主实例对应的CloudSQL故障转移副本,但是随着第二代实例的到来,它发生了变化。

因此,从用户的角度来看,此信息现在已被屏蔽。

如果你真的想看到它,你可以trigger a failover manually并且主实例将被故障转移副本替换。

您可以在触发故障转移时尝试 运行 gcloud sql instances describe,看看是否可以看到有关故障转移的更多详细信息,但我无法确认它会给您任何信息更多信息。

希望对您有所帮助。

正如约翰还提到的,您可以使用云 SQL 管理员 API:Method: instances.failover

  1. 获取设置版本:

      gcloud sql instances describe my-instance | grep settingsVersion
    
  2. 设置请求参数:

      project = your-project
      instance = your-instance
      Request body = {
        "failoverContext": {
          "settingsVersion": "settingsVersion you got from command 1",
          "kind": "sql#failoverContext"
          }
      }
    
  3. 响应:

      {
     "kind": "sql#operation",
     "targetLink": "https://content- 
     sqladmin.googleapis.com/sql/v1beta4/projects/my-project/instances/my-instance
     "status": "PENDING",
     "user": "user@gmail.com",
     "insertTime": "2019-12-30T16:30:29.446Z",
     "operationType": "FAILOVER",
     "name": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
     "targetId": "my-instance
     "selfLink": "https://content-sqladmin.googleapis.com/sql/v1beta4/projects/my-projects/operations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
     "targetProject": "my-project"
    }
    
  4. 使用 curl 命令:

      curl --request POST \
     'https://sqladmin.googleapis.com/sql/v1beta4/projects/my-project/instances/my-instance/failover' \
          --header 'Authorization: Bearer $ACCESS_TOKEN' \
          --header 'Accept: application/json' \
          --header 'Content-Type: application/json' \
          --data '{"failoverContext":{"kind":"sql#failoverContext","settingsVersion" $SETTINGS_VERSION:}}' \
          --compressed 
    
      where ACCESS_TOKEN=$(gcloud auth print-access-token)