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

# 通过 OpenAPI 对 DB ClickPipes 进行扩缩容

> 如何通过 OpenAPI 对 Postgres ClickPipes 进行扩缩容

<Warning>
  **大多数用户都不需要这个 API**

  DB ClickPipes 的默认配置开箱即用，足以处理绝大多数工作负载。如果你认为自己的工作负载需要扩缩容，请提交一个[支持请求](https://clickhouse.com/support/program)，我们会指导你针对具体使用场景选择最佳设置。
</Warning>

扩缩容 API 可能适用于以下场景：

* 大规模初始加载 (超过 4 TB)
* 希望尽可能快地迁移中等规模数据
* 在同一服务下支持超过 8 个 CDC ClickPipes

在尝试扩容之前，请先考虑：

* 确保源 DB 有足够的可用容量
* 在创建 ClickPipe 时，优先调整[初始加载并行度和分区](/zh/integrations/clickpipes/postgres/parallel-initial-load)
* 检查源端是否存在可能导致 CDC 延迟的[长事务](/zh/integrations/clickpipes/postgres/controlling-sync#transactions)

**提升扩容级别会按比例增加 ClickPipes 的计算成本。** 如果你只是为了初始加载而扩容，那么在快照完成后务必及时缩容，以避免产生意外费用。有关定价的更多详情，请参阅 [Postgres CDC 定价](/zh/products/cloud/reference/billing/clickpipes/index)。

<div id="prerequisites">
  ## 此流程的前置条件
</div>

开始之前，您需要具备：

1. 在目标 ClickHouse Cloud 服务上具有 Admin 权限的 [ClickHouse API key](/zh/products/cloud/features/admin-features/api/openapi)。
2. 曾在该服务中预配过一个 DB ClickPipe (Postgres、MySQL 或 MongoDB) 。CDC 基础设施会在创建第一个 ClickPipe 时一并创建，扩缩容端点也会从那时起可用。

<div id="cdc-scaling-steps">
  ## DB ClickPipes 扩缩容步骤
</div>

在运行任何命令之前，请先设置以下环境变量：

```bash theme={null}
ORG_ID=<Your ClickHouse organization ID>
SERVICE_ID=<Your ClickHouse service ID>
KEY_ID=<Your ClickHouse key ID>
KEY_SECRET=<Your ClickHouse key secret>
```

查看当前扩缩容配置 (可选) ：

```bash theme={null}
curl --silent --user $KEY_ID:$KEY_SECRET \
https://api.clickhouse.cloud/v1/organizations/$ORG_ID/services/$SERVICE_ID/clickpipesCdcScaling \
| jq

# example result:
{
  "result": {
    "replicaCpuMillicores": 2000,
    "replicaMemoryGb": 8
  },
  "requestId": "04310d9e-1126-4c03-9b05-2aa884dbecb7",
  "status": 200
}
```

设置所需的扩缩容规模。支持的配置为 1-32 个 CPU 核心，内存 (GB) 为 CPU 核心数的 4×：

```bash theme={null}
cat <<EOF | tee cdc_scaling.json
{
  "replicaCpuMillicores": 32000,
  "replicaMemoryGb": 128
}
EOF

curl --silent --user $KEY_ID:$KEY_SECRET \
-X PATCH -H "Content-Type: application/json" \
https://api.clickhouse.cloud/v1/organizations/$ORG_ID/services/$SERVICE_ID/clickpipesCdcScaling \
-d @cdc_scaling.json | jq
```

等待配置传播完成 (通常需要 3–5 分钟) 。扩缩容完成后，GET 端点将显示新的值：

```bash theme={null}
curl --silent --user $KEY_ID:$KEY_SECRET \
https://api.clickhouse.cloud/v1/organizations/$ORG_ID/services/$SERVICE_ID/clickpipesCdcScaling \
| jq

# example result:
{
  "result": {
    "replicaCpuMillicores": 32000,
    "replicaMemoryGb": 128
  },
  "requestId": "5a76d642-d29f-45af-a857-8c4d4b947bf0",
  "status": 200
}
```
