A VPS for ClickHouse: memory-to-data ratio, compression and disk
ClickHouse works differently from PostgreSQL or MySQL: it stores data by column, compresses it heavily and runs each query over millions of rows on all cores at once. So the server for it is chosen by different rules. Below is how to estimate a configuration for your volume of events, logs or metrics, and where ClickHouse on a VPS most often stumbles.
How much memory you need for your data volume
The ClickHouse documentation gives a clear guideline: while the compressed data is small, up to roughly 200 GB, it's best to have as much memory as data. Then the hot columns sit in the OS page cache and queries barely touch the disk. At larger volumes nothing fits in memory entirely any more, but interactive reports still get faster with every extra gigabyte.
The minimum recommended for production is 32 GB; on machines with less than 16 GB, heavy queries with default settings start failing with out-of-memory errors. You can run ClickHouse on a few gigabytes if you limit max_memory_usage, enable spilling to disk for GROUP BY and sorts (max_bytes_before_external_group_by, max_bytes_before_external_sort) and write data in infrequent large batches. For a test environment and small product analytics that is a workable option; for production, look at a VPS with 32 GB or 64 GB of memory.
Cores matter here too: a single query is parallelised across all available threads, so 8 cores compute an aggregation noticeably faster than 4. The documentation recommends the performance frequency governor, but on a VPS the host controls the frequency, and it matters more that the cores are not oversold.
Compression: how much space the data will really take
By default columns are compressed with LZ4; for archive tables you can specify ZSTD, and for time series the special codecs Delta, DoubleDelta and Gorilla before the main compression. Typical logs and events compress 5–10 times, monotonic metrics even more, while random identifiers and hashes barely compress at all. A query to system.columns comparing data_compressed_bytes and data_uncompressed_bytes will show the real picture for your tables: load a week of data and extrapolate before choosing the disk size.
Leave headroom: background merges of parts temporarily need space for the new part next to the old ones, and TTL removes expired data not instantly but at the next merge. Keep at least a third of the disk free.
Disk: throughput matters more than IOPS
A transactional database needs low latency for small writes, whereas ClickHouse reads and writes in large sequential blocks. What matters to it is throughput in megabytes per second, so on a VPS test that rather than 4K IOPS. NVMe speeds up cold queries and merges; with a large archive a sensible scheme is fresh data on a fast disk and old data on a cheap high-capacity volume via storage policies (storage_policy with moves by TTL ... TO VOLUME). Plans from the Storage VPS selection suit such a volume.
The main mistake is inserting data one row at a time. Each insert creates a new part on disk, merges can't keep up, and the server responds with a Too many parts error. Write in batches of thousands of rows or enable asynchronous inserts (async_insert).
ZooKeeper or ClickHouse Keeper
A single server doesn't need a coordinator at all: the MergeTree engine works without one. You will need Keeper once you have replicated tables (ReplicatedMergeTree) or distributed ON CLUSTER DDL queries. These days the built-in ClickHouse Keeper is usually installed instead of ZooKeeper: it is protocol-compatible, written in C++ and doesn't require a separate JVM.
- There should be an odd number of Keeper nodes, usually three: a quorum of two nodes won't survive the failure of one.
- The documentation recommends running Keeper on separate machines or at least on a separate disk: it constantly writes its log with fsync, and a heavy merge on the same disk causes session timeouts.
- Small VPS plans with 2–4 GB of memory are enough for Keeper, but with a fast disk and on the same network as the ClickHouse servers.
What to configure right after installation
- Set transparent huge pages to
madviseandvm.overcommit_memoryto 0 or 1; don't disable overcommit. - Use an ext4 or XFS file system with the
noatimeoption. - Keep the HTTP port 8123 and the native port 9000 on localhost or a private network only; set a password for the
defaultuser. - Monitor
system.parts, the merge queue and free space; for more on collecting metrics, see the VPS for monitoring page.