pg_clickhouse
pg_clickhouse : Interfaces to query ClickHouse databases from PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2460 | pg_clickhouse | pg_clickhouse | 0.10.0 |
OLAP | Apache-2.0 | C++ |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pg_stat_ch duckdb_fdw pg_duckdb pg_mooncake pg_ducklake pg_lake hdfs_fdw kafka_fdw aws_s3 pg_parquet |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.10.0 |
18 17 16 15 14 | pg_clickhouse |
- |
| RPM | PIGSTY | 0.10.0 |
18 17 16 15 14 | pg_clickhouse_$v |
openssl, libcurl, libuuid, lz4-libs, libzstd |
| DEB | PIGSTY | 0.10.0 |
18 17 16 15 14 | postgresql-$v-clickhouse |
`libssl3 |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| el8.aarch64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| el9.x86_64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| el9.aarch64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| el10.x86_64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| el10.aarch64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| d12.x86_64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| d12.aarch64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| d13.x86_64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| d13.aarch64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| u22.x86_64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| u22.aarch64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| u24.x86_64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| u24.aarch64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| u26.x86_64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
| u26.aarch64 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 | PIGSTY 0.10.0 |
Source
github.com/ClickHouse/pg_clickhouse
pg_clickhouse-0.10.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
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.