> ## 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.

> 将 Azure PostgreSQL 灵活服务器配置为 ClickPipes 的源

# Azure PostgreSQL 灵活服务器源设置指南

export const Image = ({img, alt, size}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

ClickPipes 支持 Postgres 12 及以上版本。

<div id="enable-logical-replication">
  ## 启用逻辑复制
</div>

如果 `wal_level` 已设置为 `logical`，则**无需**执行以下步骤。如果你是从其他数据复制工具迁移过来的，通常该设置已经预先配置好了。

1. 点击 **Server parameters** 部分

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/8xU-7NRzcVe16bmG/images/integrations/data-ingestion/clickpipes/postgres/source/azure-flexible-server-postgres/server_parameters.png?fit=max&auto=format&n=8xU-7NRzcVe16bmG&q=85&s=3cf1657436550cfbdd918ccaea023886" alt="Azure PostgreSQL 灵活服务器中的 Server Parameters" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/azure-flexible-server-postgres/server_parameters.png" />

2. 将 `wal_level` 设置为 `logical`

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/8xU-7NRzcVe16bmG/images/integrations/data-ingestion/clickpipes/postgres/source/azure-flexible-server-postgres/wal_level.png?fit=max&auto=format&n=8xU-7NRzcVe16bmG&q=85&s=ae0ad0836f33276dfe05da921c6b84a6" alt="在 Azure PostgreSQL 灵活服务器中将 wal_level 更改为 logical" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/azure-flexible-server-postgres/wal_level.png" />

3. 此更改需要重启服务器，因此请在系统提示时进行重启。

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/8xU-7NRzcVe16bmG/images/integrations/data-ingestion/clickpipes/postgres/source/azure-flexible-server-postgres/restart.png?fit=max&auto=format&n=8xU-7NRzcVe16bmG&q=85&s=cbb9e07703a6c54bebc9b50dc20e9af8" alt="更改 wal_level 后重启服务器" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/azure-flexible-server-postgres/restart.png" />

<div id="creating-clickpipes-user-and-granting-permissions">
  ## 创建 ClickPipes 用户并授予权限
</div>

通过管理员用户连接到你的 Azure Database for PostgreSQL 灵活服务器，并运行以下命令：

1. 为 ClickPipes 创建一个专用用户。

   ```sql theme={null}
   CREATE USER clickpipes_user PASSWORD 'some-password';
   ```

2. 为你在上一步创建的用户授予 schema 级只读权限。以下示例展示了 `public` schema 的权限。请对每个包含你要复制的表的 schema 重复执行这些命令：

   ```sql theme={null}
   GRANT USAGE ON SCHEMA "public" TO clickpipes_user;
   GRANT SELECT ON ALL TABLES IN SCHEMA "public" TO clickpipes_user;
   ALTER DEFAULT PRIVILEGES IN SCHEMA "public" GRANT SELECT ON TABLES TO clickpipes_user;
   ```

3. 为该用户授予复制权限：

   ```sql theme={null}
   ALTER USER clickpipes_user WITH REPLICATION;
   ```

4. 使用你要复制的表创建一个 [publication](https://www.postgresql.org/docs/current/logical-replication-publication.html)。我们强烈建议只在 publication 中包含实际需要的表，以避免额外的性能开销。

<Warning>
  publication 中包含的任何表都必须定义了**主键**，\_或者\_将其**副本标识**配置为 `FULL`。有关如何确定 publication 范围的指导，请参阅 [Postgres 常见问题](/zh/integrations/clickpipes/postgres/faq#how-should-i-scope-my-publications-when-setting-up-replication)。
</Warning>

* 为特定表创建 publication：

  ```sql theme={null}
  CREATE PUBLICATION clickpipes FOR TABLE table_to_replicate, table_to_replicate2;
  ```

  * 为特定 schema 中的所有表创建 publication：

    ```sql theme={null}
    CREATE PUBLICATION clickpipes FOR TABLES IN SCHEMA "public";
    ```

`clickpipes` publication 将包含由指定表生成的一组变更事件，后续将用于摄取复制 stream。

<div id="add-clickpipes-ips-to-firewall">
  ## 将 ClickPipes IP 地址添加到防火墙
</div>

请按照以下步骤，将 [ClickPipes IP 地址](/zh/integrations/clickpipes/home#list-of-static-ips) 添加到您的网络中。

1. 前往 **Networking** 选项卡，将 [ClickPipes IP 地址](/zh/integrations/clickpipes/home#list-of-static-ips) 添加到 Azure Database for PostgreSQL 灵活服务器的防火墙中；如果您使用 SSH 隧道，请将其添加到 Jump Server/堡垒机的防火墙中。

<Image img="https://mintcdn.com/private-7c7dfe99-fix-nav-issues/8xU-7NRzcVe16bmG/images/integrations/data-ingestion/clickpipes/postgres/source/azure-flexible-server-postgres/firewall.png?fit=max&auto=format&n=8xU-7NRzcVe16bmG&q=85&s=7b5af7ae361e173373f714724f774ffa" alt="在 Azure PostgreSQL 灵活服务器中将 ClickPipes IP 地址添加到防火墙" size="lg" width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/azure-flexible-server-postgres/firewall.png" />

<div id="whats-next">
  ## 下一步是什么？
</div>

您现在可以[创建 ClickPipe](/zh/integrations/clickpipes/postgres)，并开始将 Postgres 实例中的数据摄取到 ClickHouse Cloud。
请务必记下您在设置 Postgres 实例时使用的连接信息，因为在创建 ClickPipe 的过程中需要用到这些信息。
