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

> Amazon RDS Postgres を ClickPipes のソースとして設定する

# RDS Postgres ソース設定ガイド

export const IAMAuthentication = ({engine, service, children}) => {
  const services = {
    aurora: {
      name: 'Aurora',
      resource: 'cluster',
      id: 'cluster-xxxxxxxxxxxxxx'
    },
    rds: {
      name: 'RDS',
      resource: 'instance',
      id: 'db-xxxxxxxxxxxxxx'
    }
  };
  const createUserStatements = {
    postgres: `CREATE USER clickpipes_iam_user;
GRANT rds_iam TO clickpipes_iam_user;`,
    mysql: `CREATE USER 'clickpipes_iam_user' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';`
  };
  const svc = services[String(service).toLowerCase()];
  const createUserSql = createUserStatements[String(engine).toLowerCase()];
  if (!svc) throw new Error(`Unsupported IAM authentication service: ${service}`);
  if (!createUserSql) throw new Error(`Unsupported IAM authentication engine: ${engine}`);
  return <>
      <p>
        Instead of a password, you can authenticate the ClickPipes user with an AWS IAM role. This lets ClickPipes connect to your Amazon {svc.name} {svc.resource} without storing database credentials.
      </p>

      <h4 id="enable-iam-authentication">Enable IAM authentication</h4>

      <ol>
        <li>Log in to your AWS account and go to the {svc.name} {svc.resource} you want to configure.</li>
        <li>Click <strong>Modify</strong>.</li>
        <li>Scroll to the <strong>Database authentication</strong> section.</li>
        <li>Select <strong>Password and IAM database authentication</strong>.</li>
        <li>Click <strong>Continue</strong>.</li>
        <li>Review the changes and select <strong>Apply immediately</strong>.</li>
      </ol>

      <h4 id="create-database-user">Create the ClickPipes user</h4>

      <p>Create the ClickPipes user with IAM authentication enabled, then grant it the same schema and replication privileges shown above:</p>

      <CodeBlock language="sql">{createUserSql}</CodeBlock>

      {children}

      <h4 id="obtaining-the-clickhouse-service-iam-role-arn">Obtain the ClickHouse service IAM role ARN</h4>

      <ol>
        <li>Log in to your ClickHouse Cloud account.</li>
        <li>Select the ClickHouse service you want to connect.</li>
        <li>Select the <strong>Settings</strong> tab.</li>
        <li>Scroll to the <strong>Network security information</strong> section at the bottom of the page.</li>
        <li>Copy the service's <strong>Service role ID (IAM)</strong> value, shown below.</li>
      </ol>

      <Frame>
        <img src="/images/cloud/security/secures3_arn.webp" alt="Service role ID (IAM) value in the Network security information section" />
      </Frame>

      <p>This value is your <code>{'{ClickHouse_IAM_ARN}'}</code> — the role ClickPipes uses to access your {svc.name} {svc.resource}.</p>

      <h4 id="obtaining-the-rds-resource-id">Obtain the resource ID</h4>

      <ol>
        <li>Log in to your AWS account and go to the {svc.name} {svc.resource} you want to configure.</li>
        <li>Select the <strong>Configuration</strong> tab.</li>
        <li>Note the <strong>Resource ID</strong> value — it looks like <code>{svc.id}</code>. This is your <code>{'{RDS_RESOURCE_ID}'}</code>, which you reference in the permissions policy.</li>
      </ol>

      <h4 id="manually-create-iam-role">Create the IAM role</h4>

      <ol>
        <li>Log in to your AWS account with an IAM user that has permission to create and manage IAM roles.</li>
        <li>Open the IAM console.</li>
        <li>
          Create a new IAM role with the following trust and permissions policies.

          <p>Trust policy (replace <code>{'{ClickHouse_IAM_ARN}'}</code> with the IAM role ARN of your ClickHouse instance):</p>

          <CodeBlock language="json">{`{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "{ClickHouse_IAM_ARN}"
      },
      "Action": [
        "sts:AssumeRole",
        "sts:TagSession"
      ]
    }
  ]
}`}</CodeBlock>

          <p>Permissions policy (replace <code>{'{RDS_RESOURCE_ID}'}</code> with the resource ID of your {svc.name} {svc.resource}, <code>{'{RDS_REGION}'}</code> with its region, and <code>{'{AWS_ACCOUNT}'}</code> with your AWS account ID):</p>

          <CodeBlock language="json">{`{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "rds-db:connect"
      ],
      "Resource": [
        "arn:aws:rds-db:{RDS_REGION}:{AWS_ACCOUNT}:dbuser:{RDS_RESOURCE_ID}/clickpipes_iam_user"
      ]
    }
  ]
}`}</CodeBlock>
        </li>
        <li>Once the role is created, copy its ARN. This is your <code>{'{RDS_ACCESS_IAM_ROLE_ARN}'}</code>.</li>
      </ol>

      <p>You can now use this IAM role to authenticate with your {svc.name} {svc.resource} from ClickPipes.</p>
    </>;
};

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="supported-postgres-versions">
  ## サポートされているPostgresのバージョン
</div>

ClickPipes は Postgres 12 以降をサポートしています。

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

RDSインスタンスで以下の設定がすでに有効になっている場合は、このセクションはスキップできます。

* `rds.logical_replication = 1`

以前に別のデータレプリケーションツールを使用していた場合は、通常この設定はあらかじめ有効になっています。

```text theme={null}
postgres=> SHOW rds.logical_replication ;
 rds.logical_replication
-------------------------
 on
(1 row)
```

まだ設定していない場合は、以下の手順に従ってください。

1. 必要な設定を含む、使用中の Postgres バージョン用の新しいパラメータグループを作成します。
   * `rds.logical_replication` を 1 に設定します

<Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/ZEyvJTCdFXKmprnu/images/integrations/data-ingestion/clickpipes/postgres/source/rds/parameter_group_in_blade.webp?fit=max&auto=format&n=ZEyvJTCdFXKmprnu&q=85&s=fc09fae739bd271f51157b919ec4079e" alt="RDS でパラメータグループを確認する場所" size="lg" border width="1800" height="819" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/rds/parameter_group_in_blade.webp" />

<Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/ZEyvJTCdFXKmprnu/images/integrations/data-ingestion/clickpipes/postgres/source/rds/change_rds_logical_replication.webp?fit=max&auto=format&n=ZEyvJTCdFXKmprnu&q=85&s=ab9ebf451918ea46d2f3696e36e5b332" alt="rds.logical_replication の変更" size="lg" border width="1800" height="795" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/rds/change_rds_logical_replication.webp" />

2. 新しいパラメータグループを RDS Postgres データベースに適用します

<Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/ZEyvJTCdFXKmprnu/images/integrations/data-ingestion/clickpipes/postgres/source/rds/modify_parameter_group.webp?fit=max&auto=format&n=ZEyvJTCdFXKmprnu&q=85&s=28151b7458c492a53092c800d6c70c35" alt="新しいパラメータグループを使用して RDS Postgres を変更" size="lg" border width="1800" height="1352" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/rds/modify_parameter_group.webp" />

3. 変更を反映するため、RDS インスタンスを再起動します

<Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/ZEyvJTCdFXKmprnu/images/integrations/data-ingestion/clickpipes/postgres/source/rds/reboot_rds.webp?fit=max&auto=format&n=ZEyvJTCdFXKmprnu&q=85&s=9189cc820a053ed0de6f77234abcff75" alt="RDS Postgres の再起動" size="lg" border width="1800" height="757" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/rds/reboot_rds.webp" />

<div id="configure-database-user">
  ## データベースユーザーを設定する
</div>

管理者ユーザーとして RDS 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}
   GRANT rds_replication TO clickpipes_user;
   ```

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 トラフィックが増加し、レプリケーション全体の効率が低下するためです。

<div id="iam-authentication">
  ### IAM認証を使用する (任意)
</div>

<IAMAuthentication engine="postgres" service="rds">
  <Note>
    レプリケーションで IAM認証 を使用するには、`rds.iam_auth_for_replication` パラメータを `1` に設定する必要があります。これは PostgreSQL バージョン 11 以降でサポートされています。以前のバージョンでは、`Initial Load Only` の ClickPipes のみ実行できます。
  </Note>
</IAMAuthentication>

<div id="configure-network-access">
  ## ネットワークアクセスを設定する
</div>

<div id="ip-based-access-control">
  ### IP ベースのアクセス制御
</div>

RDS インスタンスへのトラフィックを制限する場合は、RDS のセキュリティグループの `Inbound rules` に、[ドキュメントに記載されている固定 NAT IP](/ja/integrations/clickpipes/networking/static-ips) を追加してください。

<Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/ZEyvJTCdFXKmprnu/images/integrations/data-ingestion/clickpipes/postgres/source/rds/security_group_in_rds_postgres.webp?fit=max&auto=format&n=ZEyvJTCdFXKmprnu&q=85&s=94cc4fa3069d9cd9a68aef2be77d731a" alt="RDS Postgres でセキュリティグループはどこにありますか？" size="lg" border width="1800" height="707" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/rds/security_group_in_rds_postgres.webp" />

<Image img="https://mintcdn.com/private-7c7dfe99-trino-dialect/ZEyvJTCdFXKmprnu/images/integrations/data-ingestion/clickpipes/postgres/source/rds/edit_inbound_rules.webp?fit=max&auto=format&n=ZEyvJTCdFXKmprnu&q=85&s=7e5852a4a8a42c9a438075b917532273" alt="上記のセキュリティグループの Inbound rules を編集" size="lg" border width="1800" height="935" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/rds/edit_inbound_rules.webp" />

<div id="private-access-via-aws-privatelink">
  ### AWS PrivateLink を介したプライベートアクセス
</div>

プライベートネットワーク経由で RDS インスタンスに接続するには、AWS PrivateLink を使用できます。接続を設定するには、[ClickPipes 向け AWS PrivateLink セットアップガイド](/ja/resources/support-center/knowledge-base/cloud-services/aws-privatelink-setup-for-clickpipes)を参照してください。

<div id="workarounds-for-rds-proxy">
  ### RDS Proxy の回避策
</div>

RDS Proxy は論理レプリケーション接続をサポートしていません。RDS で動的 IP アドレスを使用していて、DNS 名または Lambda を使えない場合は、次の代替手段があります。

1. cron ジョブを使って定期的に RDS エンドポイントの IP を名前解決し、変更されていた場合は NLB を更新します。
2. EventBridge/SNS と RDS Event Notifications を使用する: AWS RDS のイベント通知を使って更新を自動的にトリガーします
3. 固定 EC2: EC2 インスタンスをデプロイし、ポーリングサービスまたは IP ベースのプロキシとして動作させます
4. Terraform や CloudFormation などのツールを使用して、IP アドレス管理を自動化します。

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

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