repobenchmarks // database scaling
COMPARISONS
$ db --compare postgresql clickhouse

ClickHouse vs PostgreSQL OLAP

Evaluating database scaling: Transactional OLTP row stability vs vectorized columnar analytical performance on billions of records.

Postgres: Row Store (ACID / OLTP) ClickHouse: Column Store (OLAP) Compression: 5x to 10x Savings
PostgreSQL Row: [1, Alice, 24] ACID Transactions ClickHouse Col: [24, 31, 19, 45] SIMD Vectorized

PostgreSQL is the undisputed default database for web applications: it handles user accounts, financial transactions, and relational models with battle-tested ACID guarantees. But when your application starts accumulating millions of audit logs, telemetry metrics, or clickstream events, running aggregation queries (like SELECT date_trunc('day', timestamp), count(*) FROM events GROUP BY 1) in PostgreSQL begins to crawl, choking CPU and exhausting disk buffer caches. This is the exact architectural threshold where introducing ClickHouse transforms your stack.

Why ClickHouse is 100x Faster for Analytics

  • Column-Oriented Storage: When querying only the timestamp and price columns across 500 million rows, ClickHouse reads only those two columns from disk. PostgreSQL must read every single row in its entirety.
  • Unmatched Compression (5x - 10x): Because data within a column has identical types and predictable patterns, ClickHouse compresses column blocks with LZ4 or ZSTD, turning 1TB of raw event logs into less than 150GB on disk.
  • SIMD Vectorized Execution: ClickHouse processes column data in CPU SIMD vector batches, executing aggregations at the speed of your processor's memory bandwidth.

Modern Dual-Database Architecture (OLTP + OLAP)

PostgreSQL OLTP and ClickHouse OLAP Architecture Shows web app writing transactions to PostgreSQL and streaming analytical events to ClickHouse for fast dashboarding. PostgreSQL (OLTP) Users, Auth, Orders, Billing Row Store / Strict ACID CDC / Kafka ClickHouse (OLAP) Telemetry, Pageviews, Sensor Events, Metrics Aggregates Billions of Rows in < 50ms

When to Use Which Database

Workload Type Recommended Engine Why
E-Commerce Orders & Checkout PostgreSQL Requires strict serializable transactions, row locks, foreign keys
Website Analytics (Plausible / PostHog) ClickHouse Billions of append-only events, instant aggregations
SaaS Audit Trail Logs ClickHouse High write throughput with 10x disk compression
⚠ Anti-Pattern Gotcha: Single-Row INSERTs in ClickHouse

ClickHouse is designed for bulk batch writes (e.g. 1,000 to 100,000 rows per insert). If your backend sends individual single-row INSERT statements on every HTTP request, ClickHouse will generate hundreds of tiny data parts per second on disk, triggering the dreaded "Too many parts in all data parts in table" error. Always buffer writes in memory or use an intermediary queue like Vector, Kafka, or Redis before flushing to ClickHouse.

Learn more at clickhouse.com and postgresql.org.