Quickstart for Managed Postgres
This is a quickstart guide to help you create your first Managed Postgres service and integrate it with ClickHouse. Having an existing ClickHouse instance will help you explore the full capabilities of Managed Postgres.
Create a database
To create a new Managed Postgres service, click on the New service button in the service list of the Cloud Console. You should then be able to select Postgres as the database type.
Enter a name for your database instance and click on Create service. You will be taken to the overview page.
Your Managed Postgres instance will be provisioned and ready for use in a few minutes.
Connect and have some data ready
In the sidebar on the left, you will see a Connect button. Click on it to view your connection details and connection strings in multiple formats.
You can copy the connection string in your preferred format and use it to connect to your database using any Postgres-compatible client such as psql, DBeaver, or any application library.
To get started quickly, you can use the following SQL commands to create two sample tables and insert some data:
Let's insert into the events table:
And then insert into the users table:
Setup integration with ClickHouse
Now that we have tables and data in Postgres, let's replicate the tables to ClickHouse for analytics. We start by clicking on ClickHouse integration in the sidebar. Then you can click on Replicate data in ClickHouse.
In the form that follows, you can enter a name for your integration and select an existing ClickHouse instance to replicate to. If you don't have a ClickHouse instance yet, you can create one by following the Quickstart for ClickHouse Cloud guide.
Make sure the ClickHouse service you select is Running before proceeding.
Click on Next, to be taken to the table picker. Here all you need to do is:
- Select a ClickHouse database to replicate to.
- Expand the public schema and select the users and events table we created earlier.
- Click on Replicate data to ClickHouse.
The replication process will start, and you will be taken to the integration overview page. Being the first integration, it can take 2-3 minutes to setup the initial infrastructure. In the meantime let's check out the new pg_clickhouse extension.
pg_clickhouse extension
pg_clickhouse is a Postgres extension we built which enables you to query ClickHouse data from a Postgres interface. A full introduction can be found here. To use the extension, connect to your Managed Postgres instance using any Postgres-compatible client and run the following SQL commands:
Then, we create what is known as a foreign data wrapper (FDW) to connect to ClickHouse:
You can get the host for the above by going to your ClickHouse service, clicking on Connect in the sidebar, and choosing Native.
Now, we map the Postgres user to the ClickHouse service's credentials:
It's time to import data! Add the organization schema, just import it all of the tables from the remote ClickHouse database into a Postgres schema:
Done! You can now see all the ClickHouse tables in your Postgres client:
Analytics after integration
Let's check back in on the integration page. You should see that the initial replication is complete. You can click on the name of the integration to view more details on it.
If you click on the service name, you will be taken to the ClickHouse console where you can see the two tables we replicated.