pg_clickhouse
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_clickhouse | 0.10.0 | OLAP | Apache-2.0 | C++ |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2460 | pg_clickhouse | No | Yes | No | Yes | No | Yes | - |
| Related | pg_stat_ch duckdb_fdw pg_duckdb pg_mooncake pg_ducklake pg_lake hdfs_fdw kafka_fdw aws_s3 pg_parquet |
|---|
Release v0.10.0, control SQL version 0.10; preloading is optional; no llvmjit subpackage on el9.x86_64 in the 2026-08-12 build.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.10.0 | 1817161514 | pg_clickhouse | - |
| RPM | PIGSTY | 0.10.0 | 1817161514 | pg_clickhouse_$v | openssl, libcurl, libuuid, lz4-libs, libzstd |
| DEB | PIGSTY | 0.10.0 | 1817161514 | postgresql-$v-clickhouse | `libssl3 |
Build
You can build the RPM / DEB packages for pg_clickhouse using pig build:
Install
You can install pg_clickhouse directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources:
- pg_clickhouse v0.10.0 README
- pg_clickhouse v0.10.0 reference
- pg_clickhouse v0.10.0 tutorial
- pg_clickhouse v0.10.0 changelog
- pg_clickhouse v0.10.0 control file
- pg_clickhouse 0.3 to 0.10 upgrade SQL
- Pigsty pg_clickhouse package matrix
pg_clickhouse 0.10.0 exposes ClickHouse tables to PostgreSQL through the clickhouse_fdw foreign data wrapper. Upstream targets PostgreSQL 13 or later and ClickHouse 23.3 or later; current Pigsty packages cover PostgreSQL 14–18. No preload is required for normal use; session_preload_libraries and shared_preload_libraries are optional connection-startup optimizations.
Connect PostgreSQL to ClickHouse
The required driver option is binary or http. Common server options include host, port, dbname, compression, secure, and min_tls_version; user mappings accept user and password. Version 0.10 deprecates and ignores fetch_size because both drivers now stream the same Native format.
IMPORT FOREIGN SCHEMA supports LIMIT TO (...) and EXCEPT (...). Imported mixed-case identifiers remain quoted and must be referenced with matching quotes.
Query and Write Foreign Tables
SELECT, EXPLAIN, prepared statements, INSERT, and COPY operate on foreign tables. In version 0.10 the binary driver flushes inserts in bounded 64 MiB batches, so COPY is no longer merely expanded into one statement per row. Use EXPLAIN (VERBOSE) to inspect remote SQL and verify which filters, joins, aggregates, and functions were pushed down.
Direct Query and Command APIs
Version 0.10 adds typed arbitrary-query and command interfaces:
clickhouse_query(server, sql) returns rows using the caller-provided column definition, while clickhouse_perform(server, sql) discards any result. Both can run arbitrary remote SQL, so EXECUTE is revoked from PUBLIC and should be granted narrowly. clickhouse_raw_query() is deprecated in favor of these interfaces.
Pushdown and Session Settings
Version 0.10 expands aggregate and function pushdown, improves aggregate execution over mixed local and foreign partitions, and fixes several PostgreSQL NULL-semantics mismatches. Subquery pushdown requires ClickHouse 25.8 or later; older servers evaluate those subqueries locally.
The default pg_clickhouse.session_settings preserves PostgreSQL-compatible behavior, including join_use_nulls = 1, group_by_use_nulls = 1, final = 1, and transform_null_in = 0. If it is overridden, retain the settings needed by the workload—especially transform_null_in = 0, which is required for safe IN pushdown.
Upgrade and Operational Boundaries
The extension SQL version is 0.10, while pgch_version() reports the full library version 0.10.0. An installation upgraded from SQL version 0.3 must run ALTER EXTENSION after the new files are installed.
If pg_clickhouse is placed in session_preload_libraries, new sessions load it automatically. If it is placed in shared_preload_libraries, changing the library requires a PostgreSQL restart. Neither setting is mandatory, unlike extensions that register postmaster hooks.
Lightweight UPDATE and DELETE remain outside the documented write surface. Treat direct remote SQL as privileged, test pushdown with production-shaped NULL and type cases, and validate both PostgreSQL and ClickHouse versions before relying on a version-gated optimization.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)