Test and validate ClickHouse Cloud connection using clickhouse-connect for gapless-crypto-clickhouse.
Validate ClickHouse Cloud connectivity and troubleshoot connection issues for gapless-crypto-clickhouse service.
Test connection to ClickHouse Cloud service using clickhouse-connect library with credentials from Doppler. This skill guides the workflow of:
secure=True for Cloud)Use this skill when:
Triggers: User mentions "test connection", "connection failed", "ClickHouse unreachable", "validate credentials"
Required Environment Variables (loaded from Doppler aws-credentials/prd):
CLICKHOUSE_HOST: Service hostname (e.g., ebmf8f35lu.us-west-2.aws.clickhouse.cloud)CLICKHOUSE_PORT: HTTPS port (8443)CLICKHOUSE_USER: Database user (default)CLICKHOUSE_PASSWORD: Database passwordRequired Library:
# Install clickhouse-connect (if not already installed)
uv pip install clickhouse-connect
# Run Python with Doppler environment
doppler run --project aws-credentials --config prd -- python test_connection.py
Environment Loading: Doppler injects all CLICKHOUSE_* secrets as environment variables
import os
import clickhouse_connect
# Load from environment (set by Doppler)
client = clickhouse_connect.get_client(
host=os.getenv("CLICKHOUSE_HOST"),
port=int(os.getenv("CLICKHOUSE_PORT", "8443")),
username=os.getenv("CLICKHOUSE_USER", "default"),
password=os.getenv("CLICKHOUSE_PASSWORD"),
secure=True # CRITICAL: Required for ClickHouse Cloud
)
Key Configuration:
secure=True: Enforces TLS/SSL for ClickHouse Cloud (HTTPS endpoint)8443: HTTPS protocol (not 8123 for HTTP)# Query ClickHouse version and current user
result = client.query("SELECT version() as version, currentUser() as user")
version = result.result_rows[0][0]
current_user = result.result_rows[0][1]
print(f"✅ Connection successful!")
print(f" ClickHouse version: {version}")
print(f" User: {current_user}")
Expected Output:
✅ Connection successful!
ClickHouse version: 25.8.1.8702
User: default
# Test query: Count tables in system database
result = client.query("SELECT count() FROM system.tables")
table_count = result.result_rows[0][0]
print(f" Tables visible: {table_count}")
Success Criteria: Query executes without errors, returns numeric count
# Test query: Fetch first row from gapless_crypto.klines (if exists)
try:
result = client.query("SELECT * FROM gapless_crypto.klines LIMIT 1")
print(f" Data accessible: ✅ (gapless_crypto.klines)")
except Exception as e:
print(f" Data accessible: ⚠️ (table not yet created)")
See: references/connection-test.py for complete executable example
Quick Test (one-liner):
doppler run --project aws-credentials --config prd -- python -c "
import os, clickhouse_connect
client = clickhouse_connect.get_client(
host=os.getenv('CLICKHOUSE_HOST'),
port=int(os.getenv('CLICKHOUSE_PORT')),
username=os.getenv('CLICKHOUSE_USER'),
password=os.getenv('CLICKHOUSE_PASSWORD'),
secure=True
)
print('✅ Connected:', client.query('SELECT version()').result_rows[0][0])
"
default userIssue: "Connection refused" or "Timeout"
CLICKHOUSE_HOST is correct (should be *.aws.clickhouse.cloud)8443 (HTTPS), not 8123 (HTTP)running (may be paused due to idle scaling)Issue: "Authentication failed"
CLICKHOUSE_PASSWORD in Doppler matches console passwordIssue: "SSL/TLS error"
secure=True parameter is set in get_client()secure=TrueIssue: "Query slow (>10 seconds)"
Issue: "Table not found (gapless_crypto.klines)"
| Parameter | Value | Description |
|---|---|---|
host |
ebmf8f35lu.us-west-2.aws.clickhouse.cloud |
Service hostname (us-west-2) |
port |
8443 |
HTTPS port (not 8123) |
username |
default |
Default database user |
password |
(from Doppler) | Database password |
secure |
True |
Required for ClickHouse Cloud (TLS/SSL) |
a3163f31-21f4-4e22-844e-ef3fbc26ace22404d339-6921-4f1c-bf80-b07d5e23b91a)references/connection-test.pyAfter successful connection validation: