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

> Google Cloud SQL の Postgres インスタンスを ClickPipes のソースとして設定する

# Google Cloud SQL Postgres ソース設定ガイド

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>;
};

<Info>
  サイドバーにあるサポート対象のプロバイダのいずれかを使用している場合は、そのプロバイダ向けのガイドを参照してください。
</Info>

<div id="supported-postgres-versions">
  ## サポート対象の Postgres バージョン
</div>

Postgres 12 以降

<div id="enable-logical-replication">
  ## 論理レプリケーションを有効にする
</div>

設定 `cloudsql.logical_decoding` がオンになっている場合は、以下の手順に従う**必要はありません**。別のデータレプリケーションツールから移行している場合は、この設定は通常あらかじめ構成されています。

1. **概要** ページで **Edit** ボタンをクリックします。

<Image img="https://mintcdn.com/private-7c7dfe99-revert-104359-revert-104251-parquet-single/ICsmB-Qg9LaQwDEB/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/edit.webp?fit=max&auto=format&n=ICsmB-Qg9LaQwDEB&q=85&s=1a2f60875485ec8458c012dd3221485c" alt="Cloud SQL Postgres の Edit ボタン" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/edit.webp" />

2. Flags に移動し、`cloudsql.logical_decoding` を on に変更します。この変更を反映するには、Postgres サーバーの再起動が必要です。

<Image img="https://mintcdn.com/private-7c7dfe99-revert-104359-revert-104251-parquet-single/ICsmB-Qg9LaQwDEB/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/cloudsql_logical_decoding1.webp?fit=max&auto=format&n=ICsmB-Qg9LaQwDEB&q=85&s=2c1de9e7a434ad9856b2b1813cf7dcda" alt="`cloudsql.logical_decoding` を on に変更する" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/cloudsql_logical_decoding1.webp" />

<Image img="https://mintcdn.com/private-7c7dfe99-revert-104359-revert-104251-parquet-single/ICsmB-Qg9LaQwDEB/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/cloudsql_logical_decoding3.webp?fit=max&auto=format&n=ICsmB-Qg9LaQwDEB&q=85&s=81134473a1a683800f3ec8d3ba8e845c" alt="サーバーを再起動する" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/cloudsql_logical_decoding3.webp" />

<div id="creating-clickpipes-user-and-granting-permissions">
  ## ClickPipes ユーザーの作成と権限の付与
</div>

管理者ユーザーで Cloud SQL Postgres に接続し、以下のコマンドを実行します。

1. ClickPipes 専用のユーザーを作成します。

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

2. 前の手順で作成したユーザーに、スキーマレベルの読み取り専用アクセス権を付与します。以下の例は `public` スキーマに対する権限です。レプリケーションしたいテーブルを含む各スキーマに対して、これらのコマンドを繰り返し実行してください。

   ```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 に含めるテーブルには、**主キー**が定義されているか、*または* **replica identity** が `FULL` に設定されている必要があります。スコープ設定のガイダンスについては、[Postgres のよくある質問](/ja/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;
  ```

  * 特定のスキーマ内のすべてのテーブルに対する publication を作成するには:

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

`clickpipes` publication は、変更イベントが ClickPipes にストリーミングされる対象テーブルの集合を定義します。すべてのテーブルをレプリケーションするつもりでない限り、`FOR ALL TABLES` の使用は推奨しません。不要なテーブルを含めると、Postgres から ClickPipes への WAL トラフィックが増加し、レプリケーション全体の効率が低下するためです。

[//]: # "TODO SSH トンネリングを追加"

<div id="add-clickpipes-ips-to-firewall">
  ## ClickPipes の IP アドレスをファイアウォールに追加する
</div>

以下の手順に従って、ClickPipes の IP アドレスをネットワークに追加してください。

<Note>
  SSH トンネリングを使用している場合は、ジャンプサーバー/踏み台サーバーのファイアウォールルールに [ClickPipes の IP アドレス](/ja/integrations/clickpipes/home#list-of-static-ips) を追加する必要があります。
</Note>

1. **Connections** セクションに移動します

<Image img="https://mintcdn.com/private-7c7dfe99-revert-104359-revert-104251-parquet-single/ICsmB-Qg9LaQwDEB/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections.webp?fit=max&auto=format&n=ICsmB-Qg9LaQwDEB&q=85&s=b3313ecb3859d757328351c71a66b89f" alt="Cloud SQL の Connections セクション" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections.webp" />

2. Networking サブセクションに移動します

<Image img="https://mintcdn.com/private-7c7dfe99-revert-104359-revert-104251-parquet-single/ICsmB-Qg9LaQwDEB/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections_networking.webp?fit=max&auto=format&n=ICsmB-Qg9LaQwDEB&q=85&s=176fd1b730a9a4f3e5cbc72a33e7332c" alt="Cloud SQL の Networking サブセクション" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections_networking.webp" />

3. [ClickPipes のパブリック IP アドレス](/ja/integrations/clickpipes/home#list-of-static-ips) を追加します

<Image img="https://mintcdn.com/private-7c7dfe99-revert-104359-revert-104251-parquet-single/ICsmB-Qg9LaQwDEB/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/firewall1.webp?fit=max&auto=format&n=ICsmB-Qg9LaQwDEB&q=85&s=1c7ba14135cb11e48226d243b9aa4945" alt="ClickPipes のネットワークをファイアウォールに追加" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/firewall1.webp" />

<Image img="https://mintcdn.com/private-7c7dfe99-revert-104359-revert-104251-parquet-single/ICsmB-Qg9LaQwDEB/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/firewall2.webp?fit=max&auto=format&n=ICsmB-Qg9LaQwDEB&q=85&s=2e5d7acce0709f615a481fe36de0446e" alt="ClickPipes のネットワークがファイアウォールに追加された状態" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/firewall2.webp" />

<div id="whats-next">
  ## 次のステップ
</div>

これで、[ClickPipe を作成](/ja/integrations/clickpipes/postgres/index)して、Postgres インスタンスから ClickHouse Cloud へのデータ取り込みを開始できます。
ClickPipe の作成時に必要になるため、Postgres インスタンスの設定時に使用した接続情報は必ず控えておいてください。
