> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.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}) => {
  return <Frame>
      <img src={img} alt={alt} />
    </Frame>;
};

<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-mintlify-8a08bda2/KeiVE4MGTrCd9SX4/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/edit.png?fit=max&auto=format&n=KeiVE4MGTrCd9SX4&q=85&s=2ea2321d449fd02090d5bc7c9f2304e5" alt="Cloud SQL Postgres の Edit ボタン" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/edit.png" />

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

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8a08bda2/KeiVE4MGTrCd9SX4/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/cloudsql_logical_decoding1.png?fit=max&auto=format&n=KeiVE4MGTrCd9SX4&q=85&s=238da2a9e622700f31eda2bd203bdd0f" 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.png" />

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8a08bda2/KeiVE4MGTrCd9SX4/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/cloudsql_logical_decoding3.png?fit=max&auto=format&n=KeiVE4MGTrCd9SX4&q=85&s=22179551b6437ce6227d41e4504b43d1" alt="サーバーを再起動する" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/cloudsql_logical_decoding3.png" />

<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 には、指定したテーブルから生成された変更イベントのセットが含まれ、後でレプリケーションストリームを取り込む際に使用されます。

[//]: # "TODO Add SSH Tunneling"

<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-mintlify-8a08bda2/KeiVE4MGTrCd9SX4/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections.png?fit=max&auto=format&n=KeiVE4MGTrCd9SX4&q=85&s=fc7611b010f8407430a9907a6f259f4a" alt="Cloud SQL の Connections セクション" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections.png" />

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

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8a08bda2/KeiVE4MGTrCd9SX4/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections_networking.png?fit=max&auto=format&n=KeiVE4MGTrCd9SX4&q=85&s=b7618f3bf8850180e89bae933d8cbebd" alt="Cloud SQL の Networking サブセクション" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections_networking.png" />

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

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-8a08bda2/KeiVE4MGTrCd9SX4/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/firewall1.png?fit=max&auto=format&n=KeiVE4MGTrCd9SX4&q=85&s=72d7b49781c5b9a89680fb2e825e8de6" alt="ClickPipes のネットワークをファイアウォールに追加" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/firewall1.png" />

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

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

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