Five Methods For Database Obfuscation
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.
Related posts
- ClickHouse Newsletter November 2022: The purifying effects of obfuscation
ClickHouse mediumAdept
ClickHouse Cloud pricing now charges only for compute and storage, and ClickHouse 22.10 adds S3 backups (full and incremental), `SET setting = DEFAULT`, forced merging of old parts via `min_age_to_force_merge_seconds`, a relaxed too-many-parts check for large partitions, new random-distribution functions and a preview Kafka Connect sink with exactly-once semantics. The featured query shows how `clickhouse-obfuscator` turns a real dataset, demonstrated on 26.7M UK property sales in Parquet, into synthetic data that keeps row count, cardinality and value distributions close to the original. That matters for realistic GROUP BY memory and performance testing, but the output is neither encrypted nor hashed and is not automatically safe to share. Also covered: upcoming meetups and webinars, plus links to migration stories and tuning posts.
- Compressing nginx logs 170x with column storage
ClickHouse mediumAdept
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.
- Speeding up LZ4 in ClickHouse
ClickHouse hardMaster
LZ4 decompression often tops ClickHouse query profiles because highly compressible, cached columnar data shifts the cost onto CPU, yet storing data uncompressed proved impractical due to disk space. LZ4 is an LZ77 variant whose compressed blocks alternate literals and matches within a 64 KB sliding window, and whose compressor finds matches through a hash-based "cache table". Decompression speeds up when generic memcpy is replaced by inlined over-copying routines such as wildCopy8, which may safely read and write extra bytes inside buffer bounds. The fast decoder skips bounds checks on match copies, so untrusted input needs checksums, guard pages or the safe decoder.
- 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.
- 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.