ClickHouse and PostgreSQL - a Match Made in Data Heaven - part 1
ClickHouse can query PostgreSQL data in place through the postgresql table function and the PostgreSQL table engine. Simple WHERE clauses are pushed down to Postgres, while aggregation, joins, sorting and LIMIT run in ClickHouse. On the 28M-row UK house price dataset, a low-selectivity filter makes Postgres choose a parallel sequential scan over the index, taking about 28s, and querying through ClickHouse gives similar times because Postgres still does the scan. Queries using ClickHouse-specific functions such as toYear are not pushed down and can run much slower. Rewriting joins with conditional aggregates like medianIf, or copying the data into local MergeTree tables, is what delivers the large speedups.
Related posts
- ClickHouse and PostgreSQL - a Match Made in Data Heaven - part 2
ClickHouse mediumAdept
ClickHouse dictionaries backed by a PostgreSQL source can replace joins against Postgres-resident mapping tables, keeping the data in memory and refreshing it via LIFETIME and an invalidate_query. On the UK house price dataset, a regional price-change query took 48.5s in Postgres, 4.1s in ClickHouse when joining through the PostgreSQL table engine, and 0.44s using dictGet against a complex_key_hashed dictionary. The PostgreSQL table engine also supports "reverse ETL": an INSERT ... SELECT can push aggregated monthly price statistics computed in ClickHouse back into a Postgres summary table for a user-facing application to query.
- Introducing pg_clickhouse: A Postgres extension for querying ClickHouse
ClickHouse mediumAdept
pg_clickhouse v0.1.0 is an Apache 2-licensed PostgreSQL foreign data wrapper, derived from clickhouse_fdw, that runs analytics queries on ClickHouse from Postgres so existing queries can work unmodified by changing search_path. It modernizes the code with PGXS builds, CI across PostgreSQL 13-18 and ClickHouse 22-25, TLS, and Bool/Decimal/JSON types. Its main advance is pushdown: ordered-set aggregates like percentile_cont() are rewritten to ClickHouse quantile() and FILTER clauses become -If combinators. SEMI JOIN pushdown plus planner cost tuning brought 21 of 22 TPC-H queries under 1s, with 12 fully pushed down.
- Longbridge Technology simplifies their architecture and achieves 10x performance boost with ClickHouse
ClickHouse mediumAdept
Longbridge, a Singapore online brokerage, replaced a fragmented market-data stack of PostgreSQL (historical), Redis (real-time) and DynamoDB (high-write) with ClickHouse after evaluating it against TimescaleDB and TDengine for write throughput, Decimal support, time functions and aggregations. Historical data was migrated via ClickHouse external tables over OSS and Alibaba Cloud DTS, which merged 128 PostgreSQL sub-tables into one table and converted varchar fields to Decimal; Redis was kept for real-time data with ticker-level writes moved to ClickHouse. Reported results include about 5x compression (500GB down to 100GB), 10x faster single-table writes than PostgreSQL, and built-in aggregation and window functions replacing scheduled statistics jobs.
- You can’t UPDATE what you can’t find: ClickHouse vs PostgreSQL
ClickHouse mediumAdept
ClickHouse 25.7's SQL-standard UPDATEs were benchmarked against PostgreSQL 17.5 on identical hardware using the 600M-row TPC-H lineitem table, with cold and hot runs. ClickHouse wins bulk updates by up to 4,000× because most bulk WHERE clauses can't use the primary key index. That forces full scans, where PostgreSQL takes 380–390 s and ClickHouse's columnar, parallel scan takes 0.09–5.23 s. Point updates are roughly at parity and cached point updates stay competitive. The comparison isn't apples-to-apples: PostgreSQL wraps every statement in a transaction and fsyncs WAL at commit by default, while ClickHouse skips per-statement transactions and defaults to fsync_after_insert=false.
- HIFI’s migration from BigQuery to ClickHouse
ClickHouse mediumAdept
HIFI moved music royalty analytics from BigQuery to ClickHouse because BigQuery's per-query pricing discouraged exploratory use and slot reservations didn't fit a startup's shifting workloads. Dashboard loads for accounts with 25M+ rows dropped from up to 30 seconds (with timeouts) to a few seconds. The migration surfaced ClickHouse-specific join behaviour: bulk updates work better via a Join engine table and joinGet, and LEFT joins from PostgreSQL to large ClickHouse tables can exhaust memory because the hash join loads the right side into memory, which pre-aggregating the right side with GROUP BY fixes (under 1 second). A community Node.js client also silently converted NULLs to empty strings on insert, which they patched.