Skip to main content

How to create a table that can query multiple remote clusters

How to create a table that can query multiple remote clusters

Question

How do I create a table that can query other clusters or instances?

Answer

Below is a simple example to test functionality.

In this example, ClickHouse Cloud is use but the example will work when using self-hosted clusters also. The targets will need to change to the urls/hosts/dns of a target node or load balancer.

In cluster A:

Create the database:

Create the table:

Insert some sample rows:

In cluster B:

Create the database:

Create the table:

Insert sample rows:

In Cluster C:
*this cluster will be used to gather the data from the other two clusters, however, can also be used as a source.

Create the database:

Create the remote tables with remoteSecure() to connect to the other clusters.
Definition for remote cluster A table:

Definition for remote cluster B table:

Create the merge table to be used to gather results:

Test the results:

For more info:
https://clickhouse.com/docs/en/sql-reference/table-functions/remote
https://clickhouse.com/docs/en/engines/table-engines/special/merge

· 3 min read