> ## 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.

> Set up Google Cloud SQL Postgres instance as a source for ClickPipes

# Google Cloud SQL Postgres source setup guide

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

<Info>
  If you use one of the supported providers (in the sidebar), please refer to the specific guide for that provider.
</Info>

<h2 id="supported-postgres-versions">
  Supported Postgres versions
</h2>

Anything on or after Postgres 12

<h2 id="enable-logical-replication">
  Enable logical replication
</h2>

**You don't need** to follow the below steps if the setting `cloudsql. logical_decoding` is on. This setting should mostly be pre-configured if you're migrating from another data replication tool.

1. Click on **Edit** button on the Overview page.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/a9Bs4XObb7pMATI7/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/edit.png?fit=max&auto=format&n=a9Bs4XObb7pMATI7&q=85&s=155e2904690884822e02118c53e54828" alt="Edit Button in Cloud SQL Postgres" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/edit.png" />

2. Go to Flags and change `cloudsql.logical_decoding` to on. This change will need restarting your Postgres server.

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/a9Bs4XObb7pMATI7/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/cloudsql_logical_decoding1.png?fit=max&auto=format&n=a9Bs4XObb7pMATI7&q=85&s=ceac343ba913bb44586099929758879c" alt="Change cloudsql.logical_decoding to 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-3a82795f/a9Bs4XObb7pMATI7/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/cloudsql_logical_decoding3.png?fit=max&auto=format&n=a9Bs4XObb7pMATI7&q=85&s=7ca4e440af1320b514c1223f0dba6205" alt="Restart Server" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/cloudsql_logical_decoding3.png" />

<h2 id="creating-clickpipes-user-and-granting-permissions">
  Creating ClickPipes user and granting permissions
</h2>

Connect to your Cloud SQL Postgres through the admin user and run the below commands:

1. Create a dedicated user for ClickPipes:

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

2. Grant schema-level, read-only access to the user you created in the previous step. The following example shows permissions for the `public` schema. Repeat these commands for each schema containing tables you want to replicate:

   ```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. Grant replication privileges to the user:

   ```sql theme={null}
   ALTER USER clickpipes_user WITH REPLICATION;
   ```

4. Create a [publication](https://www.postgresql.org/docs/current/logical-replication-publication.html) with the tables you want to replicate. We strongly recommend only including the tables you need in the publication to avoid performance overhead.

<Warning>
  Any table included in the publication must either have a **primary key** defined *or* have its **replica identity** configured to `FULL`. See the [Postgres FAQs](/integrations/clickpipes/postgres/faq#how-should-i-scope-my-publications-when-setting-up-replication) for guidance on scoping.
</Warning>

* To create a publication for specific tables:

  ```sql theme={null}
  CREATE PUBLICATION clickpipes FOR TABLE table_to_replicate, table_to_replicate2;
  ```

* To create a publication for all tables in a specific schema:

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

The `clickpipes` publication will contain the set of change events generated from the specified tables, and will later be used to ingest the replication stream.

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

<h2 id="add-clickpipes-ips-to-firewall">
  Add ClickPipes IPs to Firewall
</h2>

Please follow the below steps to add ClickPipes IPs to your network.

<Note>
  If your are using SSH Tunneling, then you need to add the [ClickPipes IPs](/integrations/clickpipes/home#list-of-static-ips) to the firewall rules of the Jump Server/Bastion.
</Note>

1. Go to **Connections** section

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/a9Bs4XObb7pMATI7/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections.png?fit=max&auto=format&n=a9Bs4XObb7pMATI7&q=85&s=ee3f0a333b0ed7dd1d8ca4fd0877b073" alt="Connections Section in Cloud SQL" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections.png" />

2. Go to the Networking subsection

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/a9Bs4XObb7pMATI7/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections_networking.png?fit=max&auto=format&n=a9Bs4XObb7pMATI7&q=85&s=b73f13d6e2dca805bc2893c4da19d46b" alt="Networking Subsection in Cloud SQL" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/connections_networking.png" />

3. Add the [public IPs of ClickPipes](/integrations/clickpipes/home#list-of-static-ips)

<Image img="https://mintcdn.com/private-7c7dfe99-mintlify-3a82795f/a9Bs4XObb7pMATI7/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/firewall1.png?fit=max&auto=format&n=a9Bs4XObb7pMATI7&q=85&s=9ea93839597efd4a5c9fe5d82c20533a" alt="Add ClickPipes Networks to Firewall" 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-3a82795f/a9Bs4XObb7pMATI7/images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/firewall2.png?fit=max&auto=format&n=a9Bs4XObb7pMATI7&q=85&s=d1c3a79720a4a8cbf76cf56349e5fae9" alt="ClickPipes Networks Added to Firewall" size="lg" border width="3024" height="1964" data-path="images/integrations/data-ingestion/clickpipes/postgres/source/google-cloudsql/firewall2.png" />

<h2 id="whats-next">
  What's next?
</h2>

You can now [create your ClickPipe](/integrations/clickpipes/postgres) and start ingesting data from your Postgres instance into ClickHouse Cloud.
Make sure to note down the connection details you used while setting up your Postgres instance as you will need them during the ClickPipe creation process.
