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.
On this page
- The benchmark, and how to read it
- The strangest result: every Postgres query takes 4 minutes
- Postgres reads rows, ClickHouse reads columns
- Columns compress, and small data stays in memory
- Then the engine: one row at a time vs blocks
- So is it the engine? ClickBench tested that too
- Two shortcuts that need the right layout
- Where Postgres wins
- The answer is usually both
- Which one do you need?
- FAQ
- Sources
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.
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:
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
- ClickBench repository, README and result files: github.com/ClickHouse/ClickBench (PostgreSQL 2026-09-21, ClickHouse 2026-11-13, PostgreSQL with indexes 2025-03-10, pg_duckdb 2025-09-04, pg_duckdb (Parquet) 2026-05-11, TimescaleDB 2026-05-10; all c6a.4xlarge).
- PostgreSQL documentation, Database Page Layout; executor README; PostgreSQL wiki, Slow Counting.
- R. Schulze et al., ClickHouse - Lightning Fast Analytics for Everyone, PVLDB 17(12), 2024.
- ClickHouse docs: Why is ClickHouse so fast?, MergeTree, Updating data; source src/Core/Defines.h and
src/Core/Settings.cpp. - ClickHouse blog: Managed Postgres GA and Xata acquisition (Nov 9, 2026), Introducing ClickHouse Managed Postgres, Introducing pg_clickhouse; press release “ClickHouse Announces Native Postgres Service” (Business Wire, Jan 22, 2026).