Skip to main content
You can follow this path yourself, script it, or hand it to an AI agent. Switch to the Cloud UI view for the console version.This page covers provisioning ClickHouse Managed Postgres, loading data, replicating it to ClickHouse, and querying it, all from the command line with the ClickHouse CLI (clickhousectl) and psql. Commands are non-interactive; clickhousectl emits JSON with --json.

Prerequisites

Install the ClickHouse CLI:
You also need psql (PostgreSQL client tools; on macOS, brew install libpq) and jq.Write operations (create, delete) require API key authentication; OAuth login is read-only:
Alternatively, set the CLICKHOUSE_CLOUD_API_KEY and CLICKHOUSE_CLOUD_API_SECRET environment variables. Verify with clickhousectl cloud auth status; expect an entry with scope read/write.

Part 1: Create Postgres and load data

Create a Postgres service

Create the service and save the response; the password is shown only once:
The response includes the service ID, hostname, and a ready-to-use connection string:
Extract what the rest of this guide needs:
If the password is lost, generate a new one with clickhousectl cloud postgres reset-password $PG_ID --generate.

Wait for the service to provision

Provisioning takes a few minutes. Poll until the state is running:

Load sample data

Create two tables and insert 1 million events over psql:
The 1M-row insert completes in about 7 seconds on c6gd.large (the smallest size) thanks to NVMe storage. Verify with a query; row counts vary between runs because the data is generated with random():

Part 2: Replicate to ClickHouse

Create a ClickHouse service

Create a service in the same region and save the response; the password appears only in the create response:
Wait until it’s running; the ClickPipe requires a running destination:
To use an existing service instead, set CH_ID from clickhousectl cloud service list and CH_PASSWORD to its default user password, which the pg_clickhouse step needs.

Replicate the tables to ClickHouse

Create a Postgres CDC ClickPipe on the ClickHouse service, pointing at the Managed Postgres hostname. The pipe copies the existing rows, then keeps ClickHouse in sync with ongoing changes:
Notes:
  • The replicated tables land in the default database on the ClickHouse service, named by the --table-mapping targets
  • The publication and replication slot are created automatically, with the publication scoped to the mapped tables; pass --publication-name to use one you manage yourself
  • Use the direct Postgres hostname; replication isn’t supported via PgBouncer

Wait for the pipe to reach Running

The pipe moves through Provisioning, Setup, and (for larger tables) Snapshot before reaching Running, which takes about 4 minutes for the first pipe on a service. Failed and InternalError are terminal:

Query the replicated data in ClickHouse

Run SQL against the ClickHouse service directly from the CLI. The first call provisions a Query API endpoint and a service-scoped API key automatically:
New writes to Postgres replicate continuously. Insert a row and poll until the count reaches 1,000,001 (typically under a minute):

Query ClickHouse from Postgres

The pg_clickhouse extension lets Postgres act as a unified query layer for both transactional and analytical data. Grab the ClickHouse HTTPS hostname, then set up the extension over psql:
The heredoc is unquoted on purpose, so the shell substitutes $CH_HOST and $CH_PASSWORD before the SQL reaches Postgres. The replicated tables are now visible as foreign tables in the organization schema; queries against them execute in ClickHouse.Measured on c6gd.large with this dataset, analytical queries run 6-9x faster through the foreign tables (for example, a 5-aggregation GROUP BY: 176 ms via ClickHouse vs 1,133 ms locally; a JOIN with aggregations: 298 ms vs 2,764 ms).

Cleanup

Delete the ClickPipe first, then the Postgres service. Deleting a service removes all of its data permanently:
A running ClickHouse service can’t be deleted directly. Stop it, wait for stopped, then delete:
Last modified on July 24, 2026