How to Connect Metabase to a ClickHouse Database

Galaxy Glossary

How do I connect Metabase to a ClickHouse database?

Connecting Metabase to ClickHouse involves installing the ClickHouse driver, configuring connection details in Metabase, and optimizing settings for high-performance analytical querying.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Description

Overview

Metabase is an open-source business intelligence tool that lets you build dashboards and run ad-hoc queries through a friendly UI. ClickHouse is a high-performance, column-oriented OLAP database designed for sub-second analytics at scale. Connecting the two enables data teams to explore massive datasets with visual, self-service analytics while leveraging ClickHouse’s speed.

Why Pair Metabase with ClickHouse?

ClickHouse’s superior read performance makes it ideal for time-series, event, and log data. Metabase adds an intuitive layer on top so non-technical stakeholders can build charts without memorizing SQL. Together, they create an analytics stack that is both powerful and accessible.

Prerequisites

  • A running ClickHouse server (≥ v21.8 recommended).
  • Metabase version 0.46 or later (native ClickHouse driver ships out of the box).
  • Network connectivity between Metabase and ClickHouse (default port 8123 for HTTP, 9000 for native TCP).
  • Credentials for a ClickHouse user with SELECT permissions on relevant databases.

Step-by-Step Connection Guide

1. Gather Connection Details

You’ll need the ClickHouse host, port, database name, username, and password. If you use TLS, note the HTTPS port (8443 by default) and CA certificates.

2. Verify Network Access

From the Metabase host, test connectivity with:

curl https://clickhouse.example.com:8443/ping
# or non-TLS
curl http://clickhouse.example.com:8123/ping

If you get Ok. as the response, ClickHouse is reachable.

3. Log In to Metabase

Open http://<metabase-host>:3000 in your browser and sign in as an admin.

4. Add ClickHouse as a Data Source

  1. Navigate to Admin → Databases → Add database.
  2. Select ClickHouse from the list.
  3. Fill in:
    • Name: Friendly label, e.g., “Prod ClickHouse”.
    • Host: clickhouse.example.com
    • Port: 8443 for HTTPS or 8123 for HTTP.
    • Database name: Default is default.
    • Username / Password: Your ClickHouse credentials.
  4. Optional advanced settings:
    • Use TLS: Check if you enabled HTTPS.
    • CA Certificate: Paste PEM-encoded CA if using self-signed certs.
    • Sample Size: Reduce if schemas are huge to speed up sync.
  5. Click Save.

Metabase runs a connection test, then starts a background sync to ingest metadata.

5. Verify Metadata Sync

Open Admin → Databases, click your ClickHouse entry, and confirm tables appear under Browse data. Large schemas may take minutes—watch the progress log at Admin → Troubleshooting → Logs.

Performance Optimization Tips

  • Prefer Aggregate Tables: Pre-compute daily or hourly rollups in ClickHouse; Metabase queries become lightning fast.
  • Leverage Materialized Views: Funnel raw events into summary tables on insert.
  • Use Sampling Keys: For interactive exploration, create tables with SAMPLE clause so Metabase can run fast approximations.
  • Set max_bytes_before_external_group_by higher for heavy aggregations.
  • Index Time Columns First: Sort order impacts query speed (ORDER BY (timestamp, id)).

Security Considerations

  • Enable TLS on ClickHouse’s HTTP interface and supply CA certs in Metabase.
  • Create a restricted ClickHouse user with readonly profile.
  • Use Metabase’s Row-Level Permissions to limit sensitive data exposure.

Common Pitfalls and Fixes

Schema Sync Seems Stuck

Large schemas or many partitions slow down Metabase’s initial field fingerprinting. Reduce Sample Size to 1000 rows or temporarily disable voluminous tables.

Connection Test Fails with “Code: 516”

Error 516 indicates invalid credentials or user lacks permission on system tables. Grant SELECT on system.* or use a more privileged role.

Dashboard Filters Not Working

Metabase relies on field types. If a ClickHouse column is String but stores ISO dates, Metabase classifies it as Category. Override the field type to Date under Admin → Data Model.

Using Galaxy to Validate ClickHouse Queries

Before wiring a question or dashboard in Metabase, many engineers prototype queries in a dedicated SQL editor. Galaxy offers a native ClickHouse connection with context-aware AI that autocompletes functions like quantileMerge and arrayJoin. You can:

  • Iterate quickly on complex aggregations.
  • Share vetted queries inside your Galaxy Collection for peer endorsement.
  • Copy the final SQL into Metabase’s native editor or a Native Query card, confident it will run.

End-to-End Example

Suppose you store page-view events in ClickHouse:

CREATE TABLE prod.events
(
event_time DateTime,
user_id UInt32,
page String,
duration_ms UInt32
)
ENGINE = MergeTree()
ORDER BY (event_time, user_id);

In Galaxy you test:

SELECT page,
count() AS views,
quantileExact(0.9)(duration_ms) AS p90_load
FROM prod.events
WHERE event_time >= today() - 7
GROUP BY page
ORDER BY views DESC
LIMIT 20;

After validation, paste the SQL into Metabase’s Native Query card, add visualization settings, and pin it to a dashboard. Done!

Best Practices Checklist

  • Run Metabase on the same region or VPC as ClickHouse to reduce latency.
  • Cap dashboard cards at <10M rows; use rollups for larger data.
  • Schedule nightly syncs rather than hourly if schemas change infrequently.
  • Document validated queries in Galaxy to create a single source of truth.

Conclusion

Connecting Metabase to ClickHouse is straightforward: supply credentials, pass the connection test, and let Metabase ingest metadata. From there you gain a high-performance, self-service analytics environment over billions of rows. Combine this setup with Galaxy’s developer-friendly SQL editor to prototype and share ClickHouse queries even faster.

Why How to Connect Metabase to a ClickHouse Database is important

ClickHouse delivers lightning-fast analytical queries, but without a visualization layer its power remains inaccessible to stakeholders. Metabase bridges that gap, enabling self-service dashboards on top of petabyte-scale data. Mastering this connection lets data engineers expose insights securely and rapidly across an organization.

How to Connect Metabase to a ClickHouse Database Example Usage


SELECT count() FROM prod.events WHERE event_time >= today() - 1;

Common Mistakes

Frequently Asked Questions (FAQs)

Is a separate driver still required for ClickHouse?

No. Since Metabase 0.46 the ClickHouse JDBC driver is bundled by default, so you only need to configure the connection.

Can I use Galaxy to test my ClickHouse queries before adding them to Metabase?

Absolutely. Galaxy connects to ClickHouse natively, letting you prototype complex SQL with AI-driven autocompletion. Once your query is polished, copy it into Metabase’s Native Query interface.

How do I secure the connection over the internet?

Enable HTTPS on ClickHouse, upload the CA certificate in Metabase, and restrict the user to readonly access. Alternatively, place both services behind the same VPN.

Why are my Metabase filters not working on a String-typed date column?

Metabase infers field types during sync. Override the problematic column’s type to Date or Timestamp in Admin → Data Model so filters become available.

Want to learn about other SQL terms?