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

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

# Neon Postgres ソースセットアップガイド

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

これは、ClickPipes のレプリケーションに使用できる Neon Postgres のセットアップ方法を説明するガイドです。
このセットアップを行う前に、[Neon console](https://console.neon.tech/app/projects) にサインインしていることを確認してください。

<div id="creating-a-user-with-permissions">
  ## 権限を持つユーザーの作成
</div>

管理者ユーザーとして Neon インスタンスに接続し、以下のコマンドを実行します。

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

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

Neon では、UI から論理レプリケーションを有効にできます。これは、ClickPipes の CDC (変更データキャプチャ) がデータをレプリケートするために必要です。
**Settings** タブを開き、**Logical Replication** セクションに移動します。

<Image size="lg" img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/a9Bs4XObb7pMATI7/images/integrations/data-ingestion/clickpipes/postgres/source/setup/neon-postgres/neon-enable-replication.png?fit=max&auto=format&n=a9Bs4XObb7pMATI7&q=85&s=233da8530bb6b148292f9a8e72d05e87" alt="論理レプリケーションを有効にする" border width="3414" height="1336" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/setup/neon-postgres/neon-enable-replication.png" />

ここでは **Enable** をクリックすれば完了です。有効化すると、以下の成功メッセージが表示されます。

<Image size="lg" img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/a9Bs4XObb7pMATI7/images/integrations/data-ingestion/clickpipes/postgres/source/setup/neon-postgres/neon-enabled-replication.png?fit=max&auto=format&n=a9Bs4XObb7pMATI7&q=85&s=441f67c0e455eda355473842cd234f9a" alt="論理レプリケーションが有効" border width="3414" height="1336" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/setup/neon-postgres/neon-enabled-replication.png" />

Neon Postgres インスタンスで、以下の設定を確認しましょう。

```sql theme={null}
SHOW wal_level; -- logical である必要があります
SHOW max_wal_senders; -- 10 である必要があります
SHOW max_replication_slots; -- 10 である必要があります
```

<div id="ip-whitelisting-for-neon-enterprise-plan">
  ## IP の許可リスト登録 (Neon Enterprise プラン向け)
</div>

Neon Enterprise プランをご利用の場合は、[ClickPipes の IP](/ja/integrations/clickpipes/home#list-of-static-ips) を許可リストに追加することで、ClickPipes からお使いの Neon Postgres インスタンスへのレプリケーションを許可できます。
これを行うには、**Settings** タブをクリックし、**IP Allow** セクションに移動します。

<Image size="lg" img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/a9Bs4XObb7pMATI7/images/integrations/data-ingestion/clickpipes/postgres/source/setup/neon-postgres/neon-ip-allow.png?fit=max&auto=format&n=a9Bs4XObb7pMATI7&q=85&s=21d980d2b9f93369bc02668024c3546a" alt="IP 許可画面" border width="2184" height="1184" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/setup/neon-postgres/neon-ip-allow.png" />

<div id="copy-connection-details">
  ## 接続情報をコピーする
</div>

ユーザーと publication の準備が整い、レプリケーションも有効になったので、新しい ClickPipe を作成するために接続情報をコピーできます。
**ダッシュボード**に移動し、接続文字列が表示されているテキストボックスで、表示を **パラメータのみ** に変更します。次のステップでこれらのパラメータが必要です。

<Image size="lg" img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/a9Bs4XObb7pMATI7/images/integrations/data-ingestion/clickpipes/postgres/source/setup/neon-postgres/neon-conn-details.png?fit=max&auto=format&n=a9Bs4XObb7pMATI7&q=85&s=487a71874ca69e0ba11132c20bbca959" alt="接続情報" border width="1932" height="1438" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/setup/neon-postgres/neon-conn-details.png" />

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

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