Connect ClickHouse to dbt by installing the dbt-clickhouse adapter and adding a ClickHouse profile in profiles.yml.
Install Python ≥3.8, dbt-core ≥1.5, and have network access to your ClickHouse server. Confirm you can log in with the native client or HTTP interface.
Run pip install dbt-clickhouse
. The command adds the adapter, dependencies, and a new clickhouse
target type to dbt.
Create ~/.dbt/profiles.yml
and add a type: clickhouse
output with host
, port
, user
, password
, database
, schema
, and time-outs.Each key matches a ClickHouse client argument.
Yes. Wrap any sensitive value in {{ env_var('VAR_NAME') }}
to avoid committing credentials.
Run dbt debug --target dev
. A green success message confirms dbt can open and close a ClickHouse session.
Place models in /models
, reference tables like Orders
and OrderItems
, then execute dbt run
.dbt creates or replaces materialized views in ClickHouse.
SELECT order_date, sum(total_amount) AS daily_revenue FROM {{ source('public','Orders') }} GROUP BY order_date;
Partition large tables by date, set materialized_view
configs for fast refresh, and limit threads
to ClickHouse’s CPU cores.
Using the HTTP port 8123 instead of the native port 9000 causes TLS errors.Quoting case-sensitive identifiers forces full table scans.
Add tests (unique
, not_null
) and schedule dbt run
in CI/CD to keep ClickHouse models current.
.
Yes. Use materialized='incremental'
and a unique_key. dbt issues ALTER TABLE ... INSERT
to append only new rows.
Absolutely. Define separate outputs in one profile and switch with --target
. Models and tests stay portable.
Yes. Set secure: True
and verify: False
(or point to a CA bundle) in the profile to enable encrypted traffic.