Skip to main content

Introduction

This library provides PostgreSQL extensions for executing chDB queries in Postgres, and for copying data to and from a variety of formats anb object stores.

chdb Extension

The chdb extension runs chDB queries. The chdb_query() function executes a single query. For example, this query:
Outputs:
See the chdb documentation for details.

chdb_hook Module

The chdb_hook module hooks into the COPY command to copy data to or from an S3, GCS, Azure Blob, file, or http URL. This example loads records from multiple CSV files on S3 in a single COPY command:
After which the times table contains the records from each file it loaded:
A CREATE TABLE may also derive its columns, and load its rows, from such a URL:
See the chdb_hook documentation for details.

Benchmarking Formats

A benchmark compare the performance of chdb_hook COPY to that of aws_s3, pg_duckdb, and pg_lake for ca. 1m rows of NYC Taxi dataset in a variety of formats. NYC Taxi Data Benchmark Of the four extensions, chdb exhibits the most consistent performance. pg_duckdb and pg_lake, both backed by [DuckDB], take around 2-3x as long to import data from CSV, JSON, and Parquet. Only aws_s3 approaches chdb_hook’s performance, but it supports a much more limited array of data formats: Additional benchmarking demonstrates relatively consistent performance importing the NYC Taxi dataset in a variety of formats: Import Benchmark The benchmark uses the [JSONCompact] format for compatibility with the other extensions; Other JSON formats, such as [JSONCompactEachRow], will more closely approximate the performance of the other formats.

Architecture

The chdb and chdb_hook extensions rely on a chdb_helper process to execute chDB queries. The helper keeps the resource consumption of chDB separate from the main Postgres process, an advantage for an occasionally-used workflow such as loading data from a data lake.
Unlike a background worker, the helper holds no Postgres shared memory and the postmaster does not manage it. This isolates crashes from affecting Postgres. A helper that dies triggers an error only in the backend that started it, leaving other sessions untouched.

Dependencies

The chdb extension requires PostgreSQL 15 or higher and the chDB library v26.7.0 or greater (currently available only for Linux and macOS). The simplest way to install it is via the lib.chdb.io shell script:
To statically compile chDB into the helper app, set the following variables before running the Installation make commands.
The Makefile will download the static libchdb library and compile it into the app. On Linux, you can also have the installation process download and install the dynamic libchdb library by setting export BUNDLE_LIBCHDB=1 before running the Installation make commands.

Compile from source

To build chdb, just do this:
If you encounter an error such as:
You need to use GNU make, which may well be installed on your system as gmake:
If you encounter an error such as:
Be sure that you have pg_config installed and in your path. If you used a package management system such as RPM to install PostgreSQL, be sure that the -devel package is also installed. If necessary tell the build process where to find it:
If you encounter an error such as:
You either need to install chDB or tell the compiler where to find it. If, for example, you installed it via the lib.chdb.io shell script, point to /usr/local:
If you encounter an error such as:
You need to run the test suite using a super user, such as the default “postgres” super user:
To install the extension in a custom prefix on PostgreSQL 18 or later, pass the prefix argument to install (but no other make targets):
Then ensure that the prefix is included in the following postgresql.conf parameters:

Authors

Copyright (c) 2026, ClickHouse
Last modified on September 7, 2026