Deploy ClickHouse on your own infrastructure, then connect it to PostgreSQL for lightning-fast analytics.
Self-hosting gives full control over hardware, security, and cost. You can fine-tune storage, keep data on-prem, and avoid recurring SaaS fees. Teams with strict compliance or large data volumes benefit most.
ClickHouse runs on any modern 64-bit Linux. Prefer SSDs, 32+ GB RAM, and multiple CPU cores. Use RAID-10 for redundancy.Network-attached storage can throttle performance, so keep data on local disks when possible.
version: "3.9"
services:
clickhouse:
image: clickhouse/clickhouse-server:latest
container_name: ch_server
ports:
- "9000:9000" # native client
- "8123:8123" # HTTP interface
ulimits:
nofile:
soft: 262144
hard: 262144
volumes:
- ./ch_data:/var/lib/clickhouse
docker compose up -d
Verify with docker logs -f ch_server
.The server is ready when you see “Ready for connections.”
CREATE TABLE Customers (
id UInt32,
name String,
email String,
created_at DateTime
) ENGINE = MergeTree()
ORDER BY id;
CREATE TABLE Orders (
id UInt32,
customer_id UInt32,
order_date Date,
total_amount Decimal(10,2)
) ENGINE = MergeTree()
ORDER BY (customer_id, order_date);
Use clickhouse-client
with --query
piping:
PGPASSWORD=$PG_PASS psql -h pg_host -U pg_user -d shop -c \
"COPY (SELECT * FROM Customers) TO STDOUT" | \
clickhouse-client --query="INSERT INTO Customers FORMAT CSV" --format_csv_delimiter=','
Repeat for each table or automate with clickhouse-cloud-export
or Airbyte.
SELECT
p.name AS product,
sum(oi.quantity) AS units_sold,
sum(oi.quantity * p.price) AS revenue
FROM OrderItems oi
JOIN Products p ON p.id = oi.product_id
GROUP BY product
ORDER BY revenue DESC
LIMIT 10;
This query scans billions of rows in milliseconds thanks to ClickHouse’s columnar engine.
Enable replicated
tables for HA, schedule OPTIMIZE TABLE
, monitor disk I/O, and keep merges under control with proper PARTITION BY
.Encrypt traffic with TLS and restrict ports in your firewall.
Skipping ORDER BY
leads to slow reads. Over-partitioning inflates metadata and increases merges. See details below.
.
No. You can use DEB/RPM packages or compile from source, but Docker simplifies upgrades and isolation.
ClickHouse focuses on analytics, not OLTP writes. Use materialized views + Kafka or ETL tools to copy results into PostgreSQL if needed.
Deploy multiple replicas with ReplicatedMergeTree
engines and use a Distributed
table to query across shards.