ClickHouse vs PostgreSQL for analytics: 4 minutes vs 33 ms, and why

Same 100 million rows, same machine: PostgreSQL needs 258 s for a SUM that ClickHouse answers in 33 ms. ClickBench's published numbers, and the storage layout that explains them.

Take one table of web analytics, 99,997,497 rows and 105 columns, and one cloud machine with 16 vCPUs and 32 GB of RAM. Ask for SUM(AdvEngineID), COUNT(*), AVG(ResolutionWidth). In ClickBench’s published results, PostgreSQL 17 needs 258 seconds on a warm run. ClickHouse needs 0.033 seconds. That is almost 8,000 times faster for the same rows on the same hardware.

“ClickHouse vs Postgres” is the first thing Google suggests after “clickhouse vs”, and most answers stop at “ClickHouse is columnar”. This post goes one level down: what each database actually reads from disk for that query, why the gap is so large, which part of it is the engine and which part is the storage layout, and where Postgres still wins. All numbers are other people’s published measurements, mostly from ClickBench; none were run for this post.

The benchmark, and how to read it

ClickBench is a public benchmark for analytical databases. Its dataset “was obtained from the actual traffic recording of one of the world’s largest web analytics platforms” and anonymized. It is one flat table with exactly 99,997,497 rows and 105 columns, and 43 queries: counts, group-bys, string searches, top-N and a few point lookups. Every entry runs on the same AWS c6a.4xlarge with a 500 GB gp2 disk, and every query runs three times. The first run is the cold run; the faster of the other two is the warm (hot) run, which is what I quote unless I say otherwise.

Two things to keep in mind. ClickBench is maintained by ClickHouse, and its README lists its own limits (one flat table, one query at a time, no concurrency) and sums them up as “All Benchmarks Are Liars”, with a ruder word crossed out. On the other hand every install script, query and result file is in the repository, and anyone can submit an entry. The PostgreSQL entry used here (September 21, 2026) runs version 17 with shared_buffers at a quarter of RAM, parallel workers enabled and no indexes; the ClickHouse entry is a nightly run from November 13, 2026, with the table’s primary key set to (CounterID, EventDate, UserID, EventTime, WatchID).

Same 99,997,497 rows, c6a.4xlarge PostgreSQL 17 ClickHouse
Size on disk 106.5 GB 9.42 GB
Load time 1,004 s 191 s
SUM(AdvEngineID), COUNT(*), AVG(ResolutionWidth), cold / warm 269.8 s / 258.4 s 0.382 s / 0.033 s
COUNT(*), warm 258.3 s 0.001 s
One user by UserID, warm 258.3 s (0.000 s in the “with indexes” entry) 0.002 s
All 43 queries, sum of cold runs 12,404 s (3 h 26 min) 99 s

The strangest result: every Postgres query takes 4 minutes

Plot all 43 queries and the Postgres side is almost a flat line. Counting rows, finding one user, searching URLs, grouping by phrase: not one query finished in under 258 seconds, and 25 of 43 landed between 258 and 260 s. ClickHouse answered 37 of the 43 in under a second; its slowest took 2.3 s.

PostgreSQL 17ClickHouse1 ms10 ms0.1 s1 s10 s100 s1000 sQ1: PostgreSQL 258.348 sQ1: ClickHouse 0.001 sQ2: PostgreSQL 258.405 sQ2: ClickHouse 0.001 sQ3: PostgreSQL 258.393 sQ3: ClickHouse 0.033 sQ4: PostgreSQL 258.399 sQ4: ClickHouse 0.039 sQ5: PostgreSQL 272.345 sQ5: ClickHouse 0.229 sQ6: PostgreSQL 278.518 sQ6: ClickHouse 0.396 sQ7: PostgreSQL 258.363 sQ7: ClickHouse 0.008 sQ8: PostgreSQL 258.412 sQ8: ClickHouse 0.009 sQ9: PostgreSQL 284.296 sQ9: ClickHouse 0.455 sQ10: PostgreSQL 286.07 sQ10: ClickHouse 0.518 sQ11: PostgreSQL 259.033 sQ11: ClickHouse 0.138 sQ12: PostgreSQL 259.47 sQ12: ClickHouse 0.14 sQ13: PostgreSQL 263.448 sQ13: ClickHouse 0.35 sQ14: PostgreSQL 267.169 sQ14: ClickHouse 0.543 sQ15: PostgreSQL 265.007 sQ15: ClickHouse 0.405 sQ16: PostgreSQL 272.606 sQ16: ClickHouse 0.223 sQ17: PostgreSQL 438.935 sQ17: ClickHouse 1.122 sQ18: PostgreSQL 268.767 sQ18: ClickHouse 0.011 sQ19: PostgreSQL 302.215 sQ19: ClickHouse 1.914 sQ20: PostgreSQL 258.343 sQ20: ClickHouse 0.002 sQ21: PostgreSQL 258.435 sQ21: ClickHouse 0.358 sQ22: PostgreSQL 258.397 sQ22: ClickHouse 0.107 sQ23: PostgreSQL 258.397 sQ23: ClickHouse 0.547 sQ24: PostgreSQL 258.406 sQ24: ClickHouse 0.048 sQ25: PostgreSQL 258.391 sQ25: ClickHouse 0.016 sQ26: PostgreSQL 258.414 sQ26: ClickHouse 0.196 sQ27: PostgreSQL 258.405 sQ27: ClickHouse 0.017 sQ28: PostgreSQL 258.405 sQ28: ClickHouse 0.156 sQ29: PostgreSQL 268.473 sQ29: ClickHouse 1.495 sQ30: PostgreSQL 258.348 sQ30: ClickHouse 0.036 sQ31: PostgreSQL 262.555 sQ31: ClickHouse 0.242 sQ32: PostgreSQL 265.027 sQ32: ClickHouse 0.35 sQ33: PostgreSQL 459.208 sQ33: ClickHouse 2.286 sQ34: PostgreSQL 347.642 sQ34: ClickHouse 1.692 sQ35: PostgreSQL 346.65 sQ35: ClickHouse 1.606 sQ36: PostgreSQL 265.033 sQ36: ClickHouse 0.221 sQ37: PostgreSQL 258.385 sQ37: ClickHouse 0.03 sQ38: PostgreSQL 258.365 sQ38: ClickHouse 0.019 sQ39: PostgreSQL 258.37 sQ39: ClickHouse 0.019 sQ40: PostgreSQL 258.406 sQ40: ClickHouse 0.074 sQ41: PostgreSQL 258.4 sQ41: ClickHouse 0.011 sQ42: PostgreSQL 258.408 sQ42: ClickHouse 0.01 sQ43: PostgreSQL 258.373 sQ43: ClickHouse 0.008 sQ1Q10Q20Q30Q43
ClickBench warm runs on the same c6a.4xlarge (16 vCPUs, 32 GB). Plain PostgreSQL 17 never finishes a query in under 258 s; ClickHouse answers 37 of 43 in under a second. Note the log scale.

When every question takes the same time, the database is doing the same work every time: without an index, each query is a full scan of the table, and the scan costs the same whether you then count, sum or search. So why is that scan so expensive?

Postgres reads rows, ClickHouse reads columns

PostgreSQL’s built-in table storage (the heap) is row-oriented. The page layout docs say every table “is stored as an array of pages of a fixed size (usually 8 kB)”, and each row is “a fixed-size header (occupying 23 bytes on most machines), followed by an optional null bitmap, an optional object ID field, and the user data”, which is all of the row’s columns, side by side. That is exactly right for an application: load one customer and the whole row arrives in one read. But to add up one column, Postgres has to read every page, which means every column of every row.

ClickHouse stores each column separately. In MergeTree’s Wide format “each column is stored in a separate file”, and the ClickHouse VLDB 2024 paper describes a part as “a directory on disk, containing one file for each column” (tiny parts under 10 MB put all columns in one file). Our query touches two of the 105 columns, AdvEngineID and ResolutionWidth, both 2-byte integers. Uncompressed, that is 99,997,497 × 2 × 2 bytes ≈ 400 MB, against the 106.5 GB that Postgres keeps on disk. ClickHouse opens two files and never touches the other 103.

Columns compress, and small data stays in memory

Values in one column have the same type and are often similar or repeated, so they compress far better than mixed rows. ClickHouse compresses each column in blocks (max_compress_block_size is 1 MiB of uncompressed data) and, since 26.9, picks LZ4 or ZSTD(3) per part by size; the rule and its trade-offs are in the default compression codec post, and specialised number codecs in the time-series codecs post. The result for this table, as ClickBench reports it:

PostgreSQL + indexesPostgreSQL + indexes: 124.4 GB124.4 GBPostgreSQLPostgreSQL: 106.5 GB106.5 GBTimescaleDB (columnstore)TimescaleDB (columnstore): 19.3 GB19.3 GBParquet fileParquet file: 14.8 GB14.8 GBClickHouseClickHouse: 9.42 GB9.42 GB
On-disk size of the same 99,997,497 rows as reported by ClickBench (Postgres: its whole data directory). The column stores are 6–11× smaller than plain PostgreSQL.

Smaller is not just cheaper storage. ClickHouse’s 9.42 GB fits in the machine’s 32 GB of memory, so warm runs read from the page cache. PostgreSQL’s copy does not fit, so its warm run is barely faster than its cold one: 269.8 s versus 258.4 s on our query, about 4%. (ClickBench measures Postgres’s size as its whole data directory, write-ahead log included, so the table alone is somewhat smaller; it is still well over 32 GB.)

Then the engine: one row at a time vs blocks

PostgreSQL’s executor is, in its own README’s words, “a demand-pull pipeline of tuple processing operations. Each node, when called, will produce the next tuple in its output sequence”. Parallel workers split the table, but each worker still moves rows through the plan one at a time.

ClickHouse uses “the same vectorization model as MonetDB/X100, i.e. operators produce, pass, and consume multiple rows (data chunks) instead of single rows” (VLDB paper). The default block is max_block_size = 65,409 rows; the source explains the odd number as 65,536 minus padding for SIMD instructions. Hot loops are compiled several times, as a plain kernel, an auto-vectorized AVX2 kernel and a hand-written AVX-512 kernel, and “the fastest kernel is chosen at runtime based on the cpuid instruction”. For GROUP BY it picks one of “30+ precompiled hash table variants” (docs).

So is it the engine? ClickBench tested that too

ClickBench has an entry called pg_duckdb: DuckDB’s vectorized, columnar query engine running inside Postgres (duckdb.force_execution = true) on a normal Postgres table. And it has pg_duckdb (Parquet): the same extension reading the same rows from a Parquet file, which stores data by column. Same query as above, warm runs:

Entry Where the rows live Warm run
PostgreSQL 17 heap (rows) 258.4 s
pg_duckdb heap (rows) 258.4 s
pg_duckdb (Parquet) Parquet file (columns) 0.21 s
ClickHouse MergeTree (columns) 0.033 s

A much faster engine on top of row storage gave exactly the same 258 seconds. Changing only the layout made the same engine about 1,200 times faster. The engine matters (ClickHouse is still 6× faster than DuckDB-on-Parquet here), but the first factor of a thousand is the layout.

Two shortcuts that need the right layout

Counting. SELECT COUNT(*) FROM hits takes ClickHouse 1 ms because it doesn’t count: with optimize_trivial_count_query (on by default) it answers “using metadata from MergeTree”, which already knows how many rows each part holds. Postgres can’t, and the PostgreSQL wiki explains why: with MVCC “PostgreSQL must walk through all rows to determine visibility” (the same MVCC behind why your Postgres table is bigger than its data).

Skipping. Seven ClickBench queries look at one website (WHERE CounterID = 62). ClickHouse answers them in 8 to 74 ms because the table is sorted by CounterID, so its sparse primary index jumps to the few granules that hold that website and skips the rest; the MergeTree post shows how that works. Plain Postgres has no index in this entry, so it scans: 258 s again.

Where Postgres wins

Give PostgreSQL indexes (the tuned “PostgreSQL (with indexes)” entry) and the picture changes for selective queries: looking up one user by UserID takes under a millisecond (reported as 0.000 s) against ClickHouse’s 2 ms, and the one-website queries drop to 0.2–1 s. Indexes don’t help a query that has to read a whole column, though: our SUM still took 237.6 s with indexes.

And Postgres is built for the application side: changing single rows, unique and foreign keys, multi-statement transactions. ClickHouse is built the other way around. Its MergeTree docs say it “does not require a unique primary key”, and its updating-data guide describes the engine as optimised for “read-heavy analytics and high throughput append-only operations”: classic ALTER TABLE ... UPDATE mutations are “I/O-heavy, rewriting all parts that match the WHERE expression” (newer lightweight updates write small “patch parts” instead).

The answer is usually both

The most telling fact in this comparison isn’t a benchmark. In January 2026 ClickHouse announced its own managed Postgres service (built with Ubicloud), and on November 9, 2026 it became generally available, together with the acquisition of Xata. The pitch is “Postgres for transactions with ClickHouse for analytics”: changes replicate from Postgres to ClickHouse through CDC, and the Apache-2.0 pg_clickhouse extension lets Postgres “transparently execute analytics queries on ClickHouse”.

If you’d rather stay inside Postgres, ClickBench also lists column-oriented options for it: TimescaleDB with its columnstore (19.3 GB, our SUM in 0.26 s warm but 65 s cold) and pg_duckdb over Parquet (14.8 GB, 0.21 s).

Which one do you need?

  • Mostly fetching and updating a few rows by key, with transactions and constraints: PostgreSQL.
  • Scanning millions of rows but only a few columns (dashboards, logs, events, metrics): a column store. ClickHouse, or a columnar extension if the data is small enough.
  • Both: keep Postgres as the system of record and stream changes into ClickHouse for analytics. That’s the architecture ClickHouse itself now sells.

FAQ

Is ClickHouse faster than PostgreSQL? For analytical queries over many rows, yes: in ClickBench’s warm runs it was at least 158× faster on every one of the 43 queries, with a median of about 1,850×. For selective lookups with an index, Postgres is as fast or faster.

Why is ClickHouse so fast? Mostly because it reads less: only the needed columns, compressed (the whole table takes 11× less space than Postgres’s copy), with granules skipped by the sort order. Then a vectorized engine that processes up to 65,409 rows per block with SIMD kernels.

Is ClickBench fair to Postgres? It’s a single flat table and one query at a time, which favours analytical engines, and it’s run by ClickHouse. But the setup is public and reproducible, and the Postgres result matches what row storage predicts: the same full scan for almost every query.

Can Postgres be columnar? Not with its built-in heap. Extensions such as TimescaleDB’s columnstore or pg_duckdb with Parquet add column storage, and they are what close most of the gap in ClickBench.

Sources