You can connect to the hosts of DoubleCloud Managed Service for ClickHouse® via IDEs,
CLI tools,
or sample connection scripts for different languages.
You can also connect to your cluster directly in your browser using WebSQL.
You can only connect to your cluster hosts using an SSL connection.
Warning
By default, Managed ClickHouse® clusters on DoubleCloud allow connections only from IP addresses and ranges added to allowlists.
Before you connect to your cluster,
check the allowlist configuration:
WebSQL is a DoubleCloud service that allows you to connect to your Managed ClickHouse® clusters from your browser tab.
It provides a full-fledged SQL editor that you can use to run SQL queries.
Learn more about WebSQL
To connect to a Managed ClickHouse® cluster with WebSQL:
On the Clusters
page in the console, select the Managed ClickHouse® cluster you want to connect to.
Click WebSQL at the top right:
After you've connected to a cluster,
select a database in the connection manager on the left:
Enter a query in the query editor and click Execute:
Connect with IDEs
We tested the connections in the following environments:
Connect to your ClickHouse® host. You can copy the value of the Native Interface field from the Overview tab on your cluster information page. It has the following structure:
clickhouse-client --host <FQDN of the host> \
--secure \
--user <Cluster user name> \
--password <Cluster user password> \
--port 9440
If you run a RedHat 7-based Linux distribution, including Cent OS 7, Oracle Linux 7 and others, you need to download and install trusted certificates, and manually add the path to them in the clickhouse-client configuration file as follows:
Locate your clickhouse-client configuration file (by default, you can find it at /etc/clickhouse-client/config.xml) and add the path to the certificates into the <openSSL> section:
<client><!-- Used for connection to server's secure tcp port --><loadDefaultCAFile>true</loadDefaultCAFile><cacheSessions>true</cacheSessions><disableProtocols>sslv2,sslv3</disableProtocols><preferServerCiphers>true</preferServerCiphers><caConfig>/etc/ssl/certs/ca-bundle.crt</caConfig><!-- Use for self-signed: <verificationMode>none</verificationMode> --><invalidCertificateHandler><!-- Use for self-signed: <name>AcceptCertificateHandler</name> --><name>RejectCertificateHandler</name></invalidCertificateHandler></client>
Connect to your ClickHouse® host. You can copy the value of the Native Interface field from the Overview tab on your cluster information page. It has the following structure:
clickhouse-client --host <FQDN of the host> \
--secure \
--user <Cluster user name> \
--password <Cluster user password> \
--port 9440
cURL
Type the following in your terminal:
curl -H "X-ClickHouse-User: <Cluster user name>" \
-H "X-ClickHouse-Key: <Cluster user password>" \
'https://<FQDN of any ClickHouse® host in your cluster>:8443/?database=<Database name>&query=SELECT%20version()'
You will see the current ClickHouse® version in the output if your query is successful.
In a container, run a command that contains a connection string. Use the value of the Native Interface field from the Overview tab on your cluster information page as part of the Docker connection string. The command has the following structure:
docker run --network host --rm -i -t clickhouse/clickhouse-client \
--host <FQDN of the host> \
--secure \
--user <Cluster user name> \
--password <Cluster user password> \
--port 9440
Powershell
Type the following in your Powershell:
curl.exe \
-H "X-ClickHouse-User: <Cluster user name>" \
-H "X-ClickHouse-Key: <Cluster user password>" \
'https://<FQDN of any ClickHouse® host on your cluster>:8443/?database=<Database name>query=SELECT+version()'
You will see the current ClickHouse® version in the output if your query is successful.
Sample connection scripts
We tested the connections in the following environments:
#include<iostream>#include<clickhouse/client.h>intmain(){
clickhouse::Client client(clickhouse::ClientOptions()
.SetHost("<FQDN of any ClickHouse® host on your cluster>")
.SetPort(9440)
.SetUser("<Cluster user name>")
.SetPassword("<Cluster user password>")
.SetSSLOptions(clickhouse::ClientOptions::SSLOptions())
);
client.Select("SELECT version();", [](const clickhouse::Block &block) {
for (size_t i = 0; i < block.GetRowCount(); ++i) {
std::cout << block[0]->As<clickhouse::ColumnString>()->At(i) << std::endl;
}
});
}
In the same folder, create a CMakeLists.txt file to compile your script:
Build your C++ environment, then compile your script:
git clone https://github.com/ClickHouse/clickhouse-cpp \
mkdir build && cd biuld \
cmake ../ \
make
Connect to your cluster:
./junk
If your script works, you'll see the current ClickHouse® version in the output.
C#
Create a directory for your .NET project: ClickHouseTest.
Go to the project directory, install the template and dependencies for your environment:
cd ClickHouseTest \
dotnet new console -o ClickHouseTest -f net6.0 \
dotnet add ClickHouseTest package ClickHouse.Ado --version 1.4.3
Write the script to connect to your database:
Program.cs
using ClickHouse.Ado;
string cstr = "Encrypt=True;"+
"Host=<FQDN of any ClickHouse® host on your cluster>;"+
"Port=9440;"+
"Database=default;"+
"User=<Cluster user name>;"+
"Password=<Cluster user password>";
var settings = new ClickHouseConnectionSettings(cstr);
var conn = new ClickHouseConnection(settings);
conn.Open();
var cmd = conn.CreateCommand("SELECT version()");
var reader = cmd.ExecuteReader();
do {
while (reader.Read()) {
Console.Write(reader.GetValue(0));
Console.WriteLine();
}
} while (reader.NextResult());
conn.Close();
Run your program:
dotnet run
If your script works, you'll see the current ClickHouse® version in the output.
Go
Install the software:
Install the Go language interpreter:
sudo apt update && sudo apt install -y golang-go
Install Git:
sudo apt update && sudo apt install -y git
Install clickhouse-go with the necessary packages:
go get -v -u github.com/ClickHouse/clickhouse-go/v2 \
github.com/google/uuid \
github.com/pierrec/lz4/v4 \
github.com/ClickHouse/clickhouse-go/lib/proto/query.go:25:2
Write the script to connect to your database:
dc_connect.go
package main
import (
"database/sql""fmt""log"
_ "github.com/ClickHouse/clickhouse-go/v2"
)
funcmain() {
host := "<FQDN of any ClickHouse® host on your cluster>"
user := "<Cluster user name>"
password := "<Cluster user password>"
dsn := fmt.Sprintf("clickhouse://%s:%s@%s:9440?username=%s&password=%s&secure=true", user, password, host)
connect, err := sql.Open("clickhouse", dsn)
if err != nil {
log.Fatal(err)
}
if err := connect.Ping(); err != nil {
panic(err)
}
rows, err := connect.Query("SELECT version()")
if err != nil {
panic(err)
}
defer rows.Close()
for rows.Next() {
var version stringif err := rows.Scan(&version); err != nil {
panic(err)
}
log.Printf("version: %s", version)
}
if err := rows.Err(); err != nil {
panic(err)
}
}
Connect to your cluster:
go run dc_connect.go
If your query is successful, you'll see the current ClickHouse® version in the output.