ch_fdw
Foreign data wrapper for federated access from PostgreSQL to ClickHouse.
ch_fdw · Foreign data wrapper for federated access from PostgreSQL to ClickHouse.
Overview
PostgreSQL · 13
Usage
Sources:
ch_fdw is an experimental, read-only foreign data wrapper that lets PostgreSQL query ClickHouse over its native TCP protocol. The implementation combines PostgreSQL C internals with Go through CGo and supports selected filter and aggregate pushdown.
Core Workflow
Create the extension, define a server, then map a PostgreSQL foreign table to an existing ClickHouse table with compatible column names and types:
Use EXPLAIN (VERBOSE) to confirm which filters and aggregates are actually sent to ClickHouse; unsupported expressions remain local or may fail at deparse/conversion boundaries.
Implemented Boundary
- The handler supplies scan, rescan, analyze, explain, and upper-path callbacks. It has no foreign-modification callbacks, so
INSERT,UPDATE, andDELETEare not supported. - Upstream documents
WHEREand aggregate pushdown. Source comments exclude joins, parameters, ordering pushdown, grouping sets, ordered-set aggregates, aggregateFILTER, and several expression forms. - Server options used by the reviewed code are
hostandport; the validator is a no-op, so misspelled or unsafe options are not rejected during DDL.
Operational Caveats
- Upstream labels the project experimental, says it has no active MessageBird development or use, and reports testing only with PostgreSQL 13, ClickHouse 20.3.19.4, and Ubuntu 20.04. Treat the repository as a reference implementation, not a maintained compatibility promise.
- The reviewed connection code forces ClickHouse driver’s debug mode and uses the default ClickHouse user when no username is supplied; its option parsing does not establish a documented production credential workflow. Inspect logs and code before using sensitive endpoints.
- Query pushdown changes semantics across PostgreSQL and ClickHouse type, time-zone, collation, null, numeric, and function rules. Compare pushed and non-pushed results with representative edge cases.
- CGo, C memory, Go runtime, and PostgreSQL memory contexts share one backend process. Stress cancellation, reconnect, errors, large results, repeated scans, and backend shutdown on the exact server build.