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

> ClickHouse Cloud 中的手动水平扩缩容

# 水平扩缩容

export const ScalePlanFeatureBadge = ({feature = '此功能', linking_verb_are = false}) => {
  return <div className="scalePlanFeatureContainer">
            <div className="scalePlanFeatureBadge">
                Scale 计划功能
            </div>
            <div>
                <p>{feature} {linking_verb_are ? '仅在' : '仅在'} Scale 和 Enterprise 计划中可用。要升级，请访问 Cloud Console 中的计划页面。</p>
            </div>
        </div>;
};

export const Image = ({img, alt, size = "lg"}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} />
      </Frame>
    </div>;
};

<div id="manual-horizontal-scaling">
  ## 手动水平扩缩容
</div>

您可以使用 ClickHouse Cloud 的[公共 API](/api-reference/organization/get-list-of-available-organizations#/paths/~1v1~1organizations~1:organizationId~1services~1:serviceId~1scaling/patch)，通过更新服务的扩缩容设置来对服务进行扩缩容，或者在 ClickHouse Cloud 控制台中调整副本数量。

**Scale** 和 **Enterprise** 层级也支持单副本服务。服务在完成横向扩容后，最少可再缩减回 1 个副本。请注意，单副本服务的可用性较低，不建议用于生产环境。

<Note>
  服务最多可水平扩容到 20 个副本。如果您需要更多副本，请联系我们的支持团队。
</Note>

<div id="horizontal-scaling-via-api">
  ### 通过 API 进行水平扩缩容
</div>

要对集群进行水平扩缩容，请通过 API 发送 `PATCH` 请求来调整副本数量。下方截图展示了一个 API 调用：将一个 `3` 副本集群扩容到 `6` 个副本，以及对应的响应。

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/I0yKDIFW2QfsHJIe/images/cloud/manage/scaling-patch-request.webp?fit=max&auto=format&n=I0yKDIFW2QfsHJIe&q=85&s=baa8074e50ede48c5a843b9fb0901423" size="lg" alt="扩缩容 PATCH 请求" border width="1600" height="538" data-path="images/cloud/manage/scaling-patch-request.webp" />

*用于更新 `numReplicas` 的 `PATCH` 请求*

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/I0yKDIFW2QfsHJIe/images/cloud/manage/scaling-patch-response.webp?fit=max&auto=format&n=I0yKDIFW2QfsHJIe&q=85&s=42559bcb885c746f5c46b263c24fa003" size="md" alt="扩缩容 PATCH 响应" border width="1122" height="1166" data-path="images/cloud/manage/scaling-patch-response.webp" />

*`PATCH` 请求的响应*

如果某个扩缩容操作已在进行中，而你又发起了新的扩缩容请求，或连续发起多个请求，扩缩容服务会忽略中间状态，并最终收敛到最后指定的副本数量。

<div id="horizontal-scaling-via-ui">
  ### 通过 UI 进行水平扩缩容
</div>

要通过 UI 对服务进行水平扩缩容，可以在 **Settings** 页面调整该服务的副本数量。

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/I0yKDIFW2QfsHJIe/images/cloud/manage/scaling-configure.webp?fit=max&auto=format&n=I0yKDIFW2QfsHJIe&q=85&s=c21127b0aea0f4c90ff569b327ac330d" size="md" alt="扩缩容配置" border width="1330" height="624" data-path="images/cloud/manage/scaling-configure.webp" />

*ClickHouse Cloud 控制台中的服务扩缩容设置*

服务完成扩缩容后，ClickHouse Cloud 控制台中的指标仪表板应显示分配给该服务的正确资源。下方截图显示，该集群已扩展到总内存 `96 GiB`，即 `6` 个副本，每个副本分配 `16 GiB` 内存。

<Image img="https://mintcdn.com/private-7c7dfe99-detect-table-modification/I0yKDIFW2QfsHJIe/images/cloud/manage/scaling-memory-allocation.webp?fit=max&auto=format&n=I0yKDIFW2QfsHJIe&q=85&s=69fcd78f79585e7c4195d54f5abd9b77" size="md" alt="扩缩容内存分配" border width="1282" height="402" data-path="images/cloud/manage/scaling-memory-allocation.webp" />
