pg_clickhouse

Interfaces to query ClickHouse databases from PostgreSQL

Overview

PackageVersionCategoryLicenseLanguage
pg_clickhouse0.2.0OLAPApache-2.0C++
IDExtensionBinLibLoadCreateTrustRelocSchema
2460pg_clickhouseNoYesYesYesNoYes-
Relatedpg_duckdb duckdb_fdw citus columnar citus_columnar clickhouse_fdw postgres_fdw dblink

release 0.2.0; SQL v0.2

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.2.01817161514pg_clickhouse-
RPMPIGSTY0.2.01817161514pg_clickhouse_$v-
DEBPIGSTY0.2.01817161514postgresql-$v-clickhouse-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u22.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u22.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u24.x86_64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
u24.aarch64
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0
PIGSTY 0.2.0

Build

You can build the RPM / DEB packages for pg_clickhouse using pig build:

pig build pkg pg_clickhouse         # build RPM / DEB packages

Install

You can install pg_clickhouse directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_clickhouse;          # Install for current active PG version
pig ext install -y pg_clickhouse -v 18  # PG 18
pig ext install -y pg_clickhouse -v 17  # PG 17
pig ext install -y pg_clickhouse -v 16  # PG 16
pig ext install -y pg_clickhouse -v 15  # PG 15
pig ext install -y pg_clickhouse -v 14  # PG 14
dnf install -y pg_clickhouse_18       # PG 18
dnf install -y pg_clickhouse_17       # PG 17
dnf install -y pg_clickhouse_16       # PG 16
dnf install -y pg_clickhouse_15       # PG 15
dnf install -y pg_clickhouse_14       # PG 14
apt install -y postgresql-18-clickhouse   # PG 18
apt install -y postgresql-17-clickhouse   # PG 17
apt install -y postgresql-16-clickhouse   # PG 16
apt install -y postgresql-15-clickhouse   # PG 15
apt install -y postgresql-14-clickhouse   # PG 14

Preload:

shared_preload_libraries = 'pg_clickhouse';

Create Extension:

CREATE EXTENSION pg_clickhouse;

Usage

Sources: README, reference, tutorial, v0.2.0 release notes

pg_clickhouse runs analytics queries on ClickHouse from PostgreSQL through the clickhouse_fdw foreign data wrapper. Upstream documents PostgreSQL 13+ and ClickHouse 23+ support.

Connect PostgreSQL to ClickHouse

CREATE EXTENSION pg_clickhouse;

CREATE SERVER taxi_srv
FOREIGN DATA WRAPPER clickhouse_fdw
OPTIONS (driver 'binary', host 'localhost', dbname 'taxi');

CREATE USER MAPPING FOR CURRENT_USER
SERVER taxi_srv
OPTIONS (user 'default');

CREATE SCHEMA taxi;
IMPORT FOREIGN SCHEMA taxi FROM SERVER taxi_srv INTO taxi;

Server options documented upstream:

  • driver: required, binary or http
  • host
  • port
  • dbname
  • fetch_size: HTTP streaming batch size; 0 disables streaming

User mapping options:

  • user
  • password

Common operations

ALTER EXTENSION pg_clickhouse UPDATE;
ALTER EXTENSION pg_clickhouse UPDATE TO '0.2';
DROP SERVER taxi_srv CASCADE;

IMPORT FOREIGN SCHEMA also supports LIMIT TO (...) and EXCEPT (...). The reference warns that imported mixed-case identifiers are double-quoted in PostgreSQL and must be queried with quotes.

Version and pushdown notes

  • The reference documents separate library and extension versions; pgch_version() was added in release v0.2.0.
  • Patch-only releases update the library without requiring ALTER EXTENSION.
  • Release v0.2.0 added more pushdown for arrays, regex functions, split_part(), array operators, and current date/time expressions, plus the pg_clickhouse.pushdown_regex setting.

Caveats

  • This is positioned upstream as an analytics-first extension; the roadmap still lists broader DML support as future work.
  • For full examples, follow the official tutorial, which creates a ClickHouse taxi database, imports it through IMPORT FOREIGN SCHEMA, and queries the resulting foreign tables.

Last Modified 2026-04-19: update extension stub docs (9f178c3)