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

# ClickHouse integration

> Replicate your Postgres data to ClickHouse using built-in CDC capabilities

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

export const galaxyOnClick = eventName => () => {
  try {
    if (typeof window !== "undefined" && window.galaxy && eventName) {
      window.galaxy.track(eventName, {
        interaction: "click"
      });
    }
  } catch (e) {}
};

export const BetaBadge = ({link, galaxyTrack, galaxyEvent}) => {
  if (link) {
    return <a href={link} target="_blank" rel="noopener noreferrer" className="betaBadge" onClick={galaxyTrack && galaxyEvent ? galaxyOnClick(galaxyEvent) : undefined}>
                <Icon />
                <span>Beta</span>
            </a>;
  }
  return <div className="betaBadge">
            <Icon />
            <span>
                Beta feature. 
                <u>
                    <a href="/docs/beta-and-experimental-features#beta-features">
                        Learn more.
                    </a>
                </u>
            </span>
        </div>;
};

Every Managed Postgres instance comes with built-in CDC capabilities to any of your ClickHouse services. This allows you to move some or all of the data on your Postgres instance to ClickHouse and have changes in data on Postgres be reflected on ClickHouse continuous and nearly real-time. This is powered by [ClickPipes](/integrations/clickpipes/home) under the hood.

To access this, click on **ClickHouse Integration** in the sidebar of your Postgres instance.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/rF8ZX2ZZNpnwXrqH/images/managed-postgres/clickhouse-integration-intro.png?fit=max&auto=format&n=rF8ZX2ZZNpnwXrqH&q=85&s=182be74ef4356aec60b6d41aea29acfd" alt="ClickHouse integration landing page showing the integration option in the sidebar" size="md" border width="2682" height="1274" data-path="images/managed-postgres/clickhouse-integration-intro.png" />

<Note>
  Before you proceed, ensure that your Postgres service is accessible to the ClickPipes service. This should be the case by default, but if you've restricted IP access you may need to grant access to some source IPs from [this](/integrations/clickpipes/home#list-of-static-ips) list based on the region where your **ClickHouse service** is located.
</Note>

Click **Replicate data in ClickHouse** to start setting up your ClickPipe.

<Steps>
  <Step>
    <h2 id="configure-replication-service">
      Configure the replication service
    </h2>

    Fill in the replication settings:

    * **Integration name**: A name for this ClickPipe
    * **ClickHouse service**: Select an existing ClickHouse Cloud service or create a new one
    * **Postgres database**: The source database to replicate from
    * **Replication method**: Choose one of:
      * **Initial load + CDC**: Import existing data and keep tables updated with new changes (recommended)
      * **Initial load only**: One-time snapshot of existing data with no ongoing updates
      * **CDC only**: Skip the initial snapshot and only capture new changes going forward

    <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/rF8ZX2ZZNpnwXrqH/images/managed-postgres/replication-service-step.png?fit=max&auto=format&n=rF8ZX2ZZNpnwXrqH&q=85&s=59e844c6d9d90ab2b4792cedc6d731c6" alt="Replication service configuration showing integration name, destination service, and replication method options" size="md" border width="2076" height="1290" data-path="images/managed-postgres/replication-service-step.png" />

    Click **Next** to proceed.
  </Step>

  <Step>
    <h2 id="replication-settings">
      Configure replication settings
    </h2>

    Fine-tune how data is replicated:

    * **Sync interval (seconds)**: How often changes are pulled from Postgres (default: 60)
    * **Parallel threads for initial load**: Number of threads used during the initial snapshot (default: 4)
    * **Pull batch size**: Number of rows fetched per batch during replication (default: 100000)
    * **Snapshot number of rows per partition**: Rows per partition during the initial snapshot (default: 100000)
    * **Snapshot number of tables in parallel**: How many tables are snapshotted concurrently (default: 1)

    <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/rF8ZX2ZZNpnwXrqH/images/managed-postgres/integration-replication-settings.png?fit=max&auto=format&n=rF8ZX2ZZNpnwXrqH&q=85&s=db209b08ae9a29d76ec8159bd269ceee" alt="Replication settings step showing sync interval, parallel threads, pull batch size, and snapshot configuration options" size="md" border width="3680" height="2392" data-path="images/managed-postgres/integration-replication-settings.png" />

    Click **Next** to proceed.
  </Step>

  <Step>
    <h2 id="select-tables">
      Select tables to replicate
    </h2>

    Choose a destination database and select which tables to replicate:

    * **Destination database**: Select an existing ClickHouse database or create a new one
    * **Prefix default destination table names with schema name**: Adds the Postgres schema as a prefix to avoid naming conflicts
    * **Preserve NULL values from source**: Maintains NULL values instead of converting to defaults
    * **Remove deleted rows during merges**: For [ReplacingMergeTree](/reference/engines/table-engines/mergetree-family/replacingmergetree) tables, physically removes deleted rows during background merges

    Expand schemas and select individual tables to replicate. You can also customize destination table names and column settings.

    <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/rF8ZX2ZZNpnwXrqH/images/managed-postgres/select-tables-step.png?fit=max&auto=format&n=rF8ZX2ZZNpnwXrqH&q=85&s=c70cbf2e9e02dec82986173032f53973" alt="Select tables step showing database selection, replication options, and table picker grouped by schema" size="md" border width="2454" height="1804" data-path="images/managed-postgres/select-tables-step.png" />

    Click **Replicate data to ClickHouse** to start the replication.
  </Step>

  <Step>
    <h2 id="monitor-clickpipe">
      Monitor your ClickPipe
    </h2>

    Once the ClickPipe starts, you'll see it listed in the same menu. The initial snapshot of all data may take some time depending on the size of your tables.

    <Image img="https://mintcdn.com/private-7c7dfe99-mintlify-fbfa8bee/rF8ZX2ZZNpnwXrqH/images/managed-postgres/integration-running.png?fit=max&auto=format&n=rF8ZX2ZZNpnwXrqH&q=85&s=1318bb3e532ee705df7598d2a3f7412e" alt="ClickHouse integration list showing a running ClickPipe with its destination service and status" size="md" border width="2518" height="622" data-path="images/managed-postgres/integration-running.png" />

    Click on the integration name to view detailed status, monitor progress, view errors, and manage the ClickPipe. See [Lifecycle of a Postgres ClickPipe](/integrations/clickpipes/postgres/lifecycle) to understand the different states your ClickPipe may be in.
  </Step>
</Steps>
