Deploy ClickHouse

Self-hosted ClickHouse: a fast column database for real-time analytics.

Deploy ClickHouse

Just deployed

/var/lib/clickhouse

Deploy and Host ClickHouse on Railway

ClickHouse logo

ClickHouse is the open-source columnar database built for real-time analytics, with 50,000+ GitHub stars. It scans billions of rows per second on modest hardware, which is why teams use it for product analytics, logs, observability and dashboards that must answer instantly. This template runs the official ClickHouse server on Railway with a persistent volume, a generated password, HTTPS on the HTTP interface and sensible logging defaults that keep disk use under control. ClickHouse Cloud bills compute by the hour. A dedicated instance on Railway costs about $10–20/month for small workloads, with a predictable bill and your data on your own volume.


What This Template Deploys

ServicePurpose
ClickHouseThe official clickhouse/clickhouse-server image (25.8) with the HTTP interface on port 8123, served publicly over HTTPS on port 443 and privately on 8123.
Persistent VolumeMounted at /var/lib/clickhouse. Tables, parts and metadata survive every redeploy.

A single ClickHouse server with a default database (railway) and a password-protected user (clickhouse). Railway checks /ping to confirm the server is healthy. Ready-made connection strings for HTTP and JDBC, private and public, are created automatically.


About Hosting ClickHouse

ClickHouse is fast because it stores each column separately, compresses aggressively and processes data in vectorised batches. That makes it ideal for aggregations over huge tables: event streams, logs, metrics, clickstreams and time series. Running it well means persistent storage, authentication, a reachable endpoint and keeping its own system logs from quietly filling the disk.

That last point is easy to miss. By default, ClickHouse writes many internal diagnostic tables that can grow to gigabytes on a busy server. This template disables the noisiest of them (trace, text and metric logs, among others) and keeps only the useful ones (query, part and error logs) for 7 days. On Railway, you also get HTTPS on the public endpoint, private networking for your apps, and a volume you can back up from the dashboard.

HTTP interface, not the native protocol. The template exposes ClickHouse's HTTP interface (port 8123 inside Railway, HTTPS on 443 publicly). Most drivers, BI tools and HTTP clients support it. Tools that need the native TCP protocol on port 9000 can connect from inside your Railway project, or through a TCP proxy you add.

Typical cost: ~$10–20/month on Railway for a small instance, depending on RAM and data size. ClickHouse Cloud is usage-based, with compute from about $0.39 per unit-hour on its Enterprise tier.


Deploy ClickHouse in Under 5 Minutes

  1. Click Deploy on Railway. ClickHouse starts with the railway database and a generated password (about 1–2 minutes).
  2. Copy PUBLIC_DATABASE_URL (for outside access) or DATABASE_URL (for apps in the same project) from the Variables tab.
  3. Run a test query: open https://your-app.up.railway.app/play in a browser, or call the HTTP endpoint with your user and password.
  4. Create a table with the MergeTree engine and insert data from your app, a CSV file or a pipeline.
  5. Connect a dashboard such as Grafana, Metabase or Superset using the HTTP or JDBC connection string.

No cluster setup. No log tables filling your disk. No per-query bills.


Common Use Cases

  • Product and web analytics. Store raw events and query funnels, retention and dashboards in milliseconds.
  • Log and observability storage. A cheaper backend for logs, traces and metrics than most hosted log tools.
  • Real-time dashboards. Power Grafana, Metabase or Superset charts over billions of rows.
  • Time series and IoT. Ingest sensor or market data at high rates and aggregate it on the fly.
  • Analytics for your SaaS. Give customers fast in-app reports on their own usage data.
  • Data warehouse for startups. A low-cost alternative to per-query warehouses for analytical SQL.
  • Backends for analytics tools. Self-hosted tools such as PostHog-style pipelines, Plausible-style analytics or OpenTelemetry collectors that write to ClickHouse.

Configuration

VariableRequiredDescription
CLICKHOUSE_USER✅ Setclickhouse, the database user.
CLICKHOUSE_PASSWORD🔐 Auto-generated32-character password for that user.
CLICKHOUSE_DB✅ Setrailway, the default database.
DATABASE_URL, DATABASE_JDBC_URL✅ Auto-injectedPrivate HTTP and JDBC connection strings for apps in the same project.
PUBLIC_DATABASE_URL, PUBLIC_DATABASE_JDBC_URL✅ Auto-injectedPublic HTTPS and JDBC connection strings for tools outside Railway.
HOST, PORT, PUBLIC_HOST, PUBLIC_PORT✅ Auto-injectedPrivate host and port 8123, public host and port 443.
CLICKHOUSE_LOG_RETENTION_DAYSOptional7 days of query, part and error logs before they're deleted.
CLICKHOUSE_EXTRA_CONFIG_XMLOptionalExtra server config, written to config.d. The default disables noisy diagnostic logs.
CLICKHOUSE_EXTRA_USERS_XMLOptionalExtra users, profiles and quotas, written to users.d.

Adding read-only users. Put a user definition in CLICKHOUSE_EXTRA_USERS_XML with readonly set in its profile, or create users with SQL (CREATE USER ... IDENTIFIED BY ... and GRANT SELECT ...). Give dashboards and analysts read-only accounts instead of the main password.

Connecting from another Railway service. Reference ${{ClickHouse.DATABASE_URL}} in your app's variables. Traffic stays on Railway's private network.


ClickHouse on Railway vs. Alternatives

ClickHouse on RailwayClickHouse CloudGoogle BigQueryTinybird
Monthly cost~$10–20 usage, predictableUsage-based, $300 trial$6.25 per TiB scanned (on-demand)Free tier, then paid plans
Self-hosted✅ Yes❌ No❌ No❌ No
Pay per query✅ No⚠️ Compute hours❌ Per data scanned⚠️ By plan
Full SQL and table engines✅ Full ClickHouse✅ Full ClickHouse⚠️ BigQuery SQL⚠️ Managed subset
Real-time inserts and sub-second queries✅ Yes✅ Yes⚠️ Seconds✅ Yes
Data on your own volume✅ Yes❌ Hosted❌ Hosted❌ Hosted
License✅ Apache-2.0✅ Apache-2.0 core, hosted❌ Proprietary❌ Proprietary service

Dependencies for ClickHouse Hosting

  • Railway account. Hobby works for small datasets; Pro for more RAM and larger volumes.
  • A client: any ClickHouse driver, an HTTP client, or a BI tool such as Grafana, Metabase or Superset.
  • Optional: an ingestion pipeline (Vector, Kafka, your app) to stream data in.

Deployment Dependencies

Implementation Details

The service runs the official server image through a small start command. Before ClickHouse starts, it writes any extra config and users XML from the environment into config.d and users.d, then hands over to the image's own entrypoint, which creates the user and database. The default extra config removes high-volume diagnostic tables and adds a TTL to the useful logs, so system tables stay small.

The image is pinned to the 25.8 long-term-support line. Newer LTS releases exist, so you can change the tag to a newer LTS line after backing up the volume.


Frequently Asked Questions

What is ClickHouse, and why self-host it? ClickHouse is an open-source columnar database for fast analytics. Self-hosting gives you a predictable monthly cost, no per-query billing and full control over your data.

How much does it cost compared to ClickHouse Cloud or BigQuery? About $10–20/month on Railway for a small instance. ClickHouse Cloud charges for compute hours and storage, and BigQuery's on-demand pricing is $6.25 per TiB scanned, which adds up with frequent dashboards.

Why can't my client connect on port 9000? This template exposes the HTTP interface, not the native protocol. Use an HTTP-capable driver with PUBLIC_DATABASE_URL, connect from inside your Railway project, or add a TCP proxy for port 9000.

Do I lose data when Railway redeploys? No. Tables and metadata are on the volume at /var/lib/clickhouse, so redeploys and restarts keep everything.

Why is the disk not filling up with system logs? The default config turns off ClickHouse's noisiest diagnostic logs and keeps query, part and error logs for CLICKHOUSE_LOG_RETENTION_DAYS days.

Can I scale it up later? Yes. Give the service more RAM and CPU in Railway as your data grows. For multi-node clusters with replication, you'd need a more complex setup than this single-node template.


Why Deploy and Host ClickHouse on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying ClickHouse on Railway, you get a fast, production-ready analytics database with HTTPS, persistent storage and tidy logging defaults, at a predictable monthly cost.


Template Content

More templates in this category

View Template
RustFS | (Just Updated) S3 Object Store, Public URL and Keys Set
S3-compatible object store, keys and public URL preset, volume kept

SuperSlowSloth
0
View Template
TimescaleDB
A PostgreSQL-based time-series database for analytics on Railway.

Rakit
1
View Template
Garage S3 Storage
Ultra-light S3 server: fast, open-source, plug-and-play.

PROJETOS
8