> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 API 和 cURL 管理 ClickHouse Cloud 服务

> 了解如何使用 API 端点和 cURL 命令启动、停止和恢复运行 ClickHouse Cloud 服务。

<div id="how-to-start-stop-and-resume-a-cloud-service-using-the-clickhouse-api-and-curl">
  ## 如何使用 ClickHouse API 和 cURL 启动、停止和恢复运行 Cloud 服务
</div>

<div id="question">
  ## 问题
</div>

如何通过 API 端点启动、停止和恢复运行 ClickHouse Cloud 服务？

<div id="answer">
  ## 答案
</div>

1. 要将处于空闲状态的 Cloud 服务唤醒/恢复，可以向该实例发送 Ping：

```bash theme={null}
curl -X GET https://abc123.us-west-2.aws.clickhouse.cloud:8443/ping
```

2. 要停止 Cloud 服务，请使用 `/state` 端点并执行 `stop` 命令。语法如下：

```bash theme={null}
curl -X PATCH https://api.clickhouse.cloud/v1/organizations/<org_uuid>/services/<service_uuid>/state -u <key_id>:<key_secret> -H "Content-Type: application/json" -d ''{"command": "<stop|start>"}''
```

例如，以下命令会停止 `2e2124ca-c5ac-459d-a6f2-abc123549d2a` 服务：

```bash theme={null}
curl -X PATCH https://api.clickhouse.cloud/v1/organizations/123abcd0-e9b5-4f55-9e42-0fb04392445c/services/2e2124ca-c5ac-459d-a6f2-abc123549d2a/state -u abc123:ABC123 -H "Content-Type: application/json" -d '{"command": "stop"}'
```

输出如下：

```response theme={null}
{"result":{"id":"2e2124ca-c5ac-459d-a6f2-abc123549d2a","name":"mars-s3","provider":"aws","regionId":"us-west-2","state":"stopping","endpoints":[{"protocol":"nativesecure","host":"abc123.us-west-2.aws.clickhouse.cloud","port":9440},{"protocol":"https","host":"abc123ntrb.us-west-2.aws.clickhouse.cloud","port":8443}],"tier":"production","idleScaling":true,"idleTimeoutMinutes":5,"minTotalMemoryGb":24,"maxTotalMemoryGb":48,"ipAccessList":[{"source":"[0.0.0.0/0](http://0.0.0.0/0)","description":"Anywhere"}],"createdAt":"2022-10-21T18:46:31Z"},"status":200}%
```

3. 要重新启动该服务，请使用 `start` 命令：

```bash theme={null}
curl -X PATCH https://api.clickhouse.cloud/v1/organizations/123abcd0-e9b5-4f55-9e42-0fb04392445c/services/2e2124ca-c5ac-459d-a6f2-abc123549d2a/state -u abc123:ABC123 -H "Content-Type: application/json" -d '{"command": "start"}'
```

<Note>
  以下是服务可能处于的各种状态：

  ```
  "state":"stopping"
  "state":"stopped"
  "state":"starting"
  "state":"running"
  "state":"idle"
  ```
</Note>

<Note>
  处于 **"idle"** 状态的 Cloud 服务仍视为已启动，因此 `start` 命令不会将其恢复/唤醒。请使用步骤 1 中所示的 `ping` 端点来唤醒服务。
</Note>
