Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 14 min read How-to mediumAdept

Compressing nginx logs 170x with column storage

Parsing nginx access logs into typed columns in ClickHouse and tuning storage raises compression from roughly 38x (ZSTD on the raw file) to about 178x on a 66.7M-line, 20 GB dataset. Regex extraction into separate columns alone reaches 56x. Choosing tighter types (IPv4, UInt16/UInt32), LowCardinality dictionary encoding for columns under ~100k distinct values, and codecs such as Delta plus ZSTD lifts it to 92x. Picking an ordering key that groups low-cardinality, high-volume columns so similar values sit together pushes it past 170x, though production keys must also balance query access patterns.

Assumes: SQL basicscolumnar database conceptscompression basics

Related posts

  • Optimizing ClickHouse with Schemas and Codecs

    ClickHouse mediumAdept

    Tightening a ClickHouse schema with strict types cuts a 1B-row NOAA weather dataset from 131.58 GiB to 71.38 GiB uncompressed. The changes are right-sized integers instead of Int64, Int16 elevation, an Enum8 for weather type, LowCardinality for ~100k-value strings, and Float32 lat/lon in place of a Point. Compressed size moves less, from 4.07 GiB to 3.83 GiB, but smaller uncompressed data lowers RAM use and improves CPU cache efficiency at query time. Each step is checked against per-column system.columns stats and a benchmark query, before moving on to tuning column codecs for the largest columns such as date and temperatures.

  • Five Methods For Database Obfuscation

    ClickHouse hardMaster

    ClickHouse needed publishable benchmark data that kept the properties driving analytical query performance in its private web analytics dataset: compression ratio, per-column and cross-column cardinality, and value distributions such as power laws. The post compares approaches to obfuscating that data. Hand-written probabilistic models in C++ were too laborious and specific to one dataset. An LSTM that generated TSV dumps produced gigabyte-sized models, ran at about 100 rows per second and distorted character frequencies. Mutating the literals inside LZ4-compressed data preserved compression ratio and decompression speed while removing every original byte, guided by heuristics that keep structure such as valid UTF-8.

  • Improve logs compression with log clustering

    ClickHouse mediumAdept

    Drain3 log template mining, run inside ClickHouse as a Python executable UDF, can turn unstructured application logs into structured columnar data. Templates mined from a sample of each service's logs become regex patterns in a materialized view, which extracts variable fields into a Map column keyed by template number at ingest time. Two templates covered 99.99% of one service's logs, and unmatched lines are kept raw. The approach reached nearly 50x compression while keeping logs queryable and fully reconstructable, though evaluating every pattern against every log line needs optimization to scale.

  • ClickHouse Release 24.6

    ClickHouse mediumAdept

    ClickHouse 24.6 adds an optimize_row_order setting for plain MergeTree tables. Within each range of identical ORDER BY values, it sorts rows by the remaining columns in ascending cardinality, creating long runs that LZ4 and ZSTD compress better. Loading 1 billion PyPI download rows shows about 30% better compression (25.36 GiB down to 17.52 GiB), at the cost of 30-50% slower inserts. It helps only with no or low-cardinality sort keys. The release also brings chDB 2.0, which queries Pandas DataFrames, Arrow tables and Python dicts in-process, plus Hilbert curve encoding functions that complement Morton encoding for locality-preserving multi-column sort keys.

  • So, is ClickHouse winning the observability wars?

    ClickHouse mediumAdept

    ClickHouse has become a common storage and query layer for observability, and the main reason is its columnar architecture. Data sorted by an ordering key compresses well (users report 10–50x), queries read only the columns they need, sparse primary and skip indexes prune granules, and execution is vectorized and SIMD-friendly and runs in parallel across shards. The newer inverted-index full-text search cut multi-term log searches in one customer report from 30–45s to about 400ms. High-cardinality fields cost little in a columnar store compared with Prometheus's per-series model, though grouping by millions of values still costs memory. The engine is only the foundation; collection, schema, correlation and workflows still have to be built, which is where ClickStack comes in.

The quest for software engineering knowledge.

Look:
Layout: