> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Run analytics queries on ClickHouse right from PostgreSQL without rewriting any SQL

# pg_clickhouse reference documentation

<h2 id="introduction">
  Introduction
</h2>

[pg\_clickhouse][pg_clickhouse], an open-source PostgreSQL extension, runs analytics queries
on ClickHouse right from PostgreSQL without rewriting any SQL. It supports
PostgreSQL 13 and later and ClickHouse v23 and later.

Once [ClickPipes](/integrations/clickpipes/home) starts syncing data ClickHouse,
use pg\_clickhouse to quickly and easily [import foreign tables] into a
PostgreSQL schema. Then run your existing PostgreSQL queries to against those
tables, preserving your existing code base while pushing execution down to
ClickHouse.

<h2 id="getting-started">
  Getting started
</h2>

The simplest way to try pg\_clickhouse is the [Docker image], which contains
the standard PostgreSQL Docker image with the pg\_clickhouse and [re2]
extensions:

```sh theme={null}
docker run --name pg_clickhouse -e POSTGRES_PASSWORD=my_pass \
       -d ghcr.io/clickhouse/pg_clickhouse:19
docker exec -it pg_clickhouse psql -U postgres -c 'CREATE EXTENSION pg_clickhouse'
```

See the [tutorial] to get started importing ClickHouse tables and pushing down
queries.

<h2 id="test-case-tpc-h">
  Test case: TPC-H
</h2>

This table compares [TPC-H] query performance between regular PostgreSQL
tables and pg\_clickhouse connected to ClickHouse, both loaded at scaling
factor 1; ✔︎ indicates full pushdown, while a dash indicates a query
cancellation after 1m. All tests run on a MacBook Pro M4 Max with 36 GB of
memory.

|       Query | PostgreSQL | pg\_clickhouse | Pushdown |
| ----------: | ---------: | -------------: | :------: |
|  \[Query 1] |    4693 ms |         268 ms |    ✔︎    |
|  \[Query 2] |     458 ms |        3446 ms |          |
|  \[Query 3] |     742 ms |         111 ms |    ✔︎    |
|  \[Query 4] |     270 ms |         130 ms |    ✔︎    |
|  \[Query 5] |     337 ms |        1460 ms |    ✔︎    |
|  \[Query 6] |     764 ms |          53 ms |    ✔︎    |
|  \[Query 7] |     619 ms |          96 ms |    ✔︎    |
|  \[Query 8] |     342 ms |         156 ms |    ✔︎    |
|  \[Query 9] |    3094 ms |         298 ms |    ✔︎    |
| \[Query 10] |     581 ms |         197 ms |    ✔︎    |
| \[Query 11] |     212 ms |          24 ms |          |
| \[Query 12] |    1116 ms |          84 ms |    ✔︎    |
| \[Query 13] |     958 ms |        1368 ms |          |
| \[Query 14] |     181 ms |          73 ms |    ✔︎    |
| \[Query 15] |    1118 ms |         557 ms |          |
| \[Query 16] |     497 ms |        1714 ms |          |
| \[Query 17] |    1846 ms |       32709 ms |          |
| \[Query 18] |    5823 ms |       10649 ms |          |
| \[Query 19] |      53 ms |         206 ms |    ✔︎    |
| \[Query 20] |     421 ms |              - |          |
| \[Query 21] |    1349 ms |        4434 ms |          |
| \[Query 22] |     258 ms |        1415 ms |          |

<h3 id="compile-from-source">
  Compile from source
</h3>

<h4 id="general-unix">
  General Unix
</h4>

The PostgreSQL and curl development packages include `pg_config` and
`curl-config` in the path, so you should be able to just run `make` (or
`gmake`), then `make install`, then in your database
`CREATE EXTENSION pg_clickhouse`.

<h4 id="debian--ubuntu--apt">
  Debian / Ubuntu / APT
</h4>

See [PostgreSQL Apt] for details on pulling from the PostgreSQL Apt repository.

```sh theme={null}
sudo apt install \
  postgresql-server-19 \
  libcurl4-openssl-dev \
  uuid-dev \
  libssl-dev \
  make \
  cmake \
  g++
```

<h4 id="redhat--centos--yum">
  RedHat / CentOS / Yum
</h4>

```sh theme={null}
sudo yum install \
  postgresql-server \
  libcurl-devel \
  libuuid-devel \
  openssl-libs \
  automake \
  cmake \
  gcc
```

See [PostgreSQL Yum] for details on pulling from the PostgreSQL Yum repository.

<h4 id="install-from-pgxn">
  Install from PGXN
</h4>

With the above dependencies satisfied use the [PGXN client] (available as
[Homebrew], [Apt] and Yum packages named `pgxnclient`) to download, compile,
and install `pg_clickhouse`:

```sh theme={null}
pgxn install pg_clickhouse
```

<h4 id="compile-and-install">
  Compile and Install
</h4>

To build and install the ClickHouse library and `pg_clickhouse`, run:

```sh theme={null}
make
sudo make install
```

If your host has several PostgreSQL installations, you might need to specify
the appropriate version of `pg_config`:

```sh theme={null}
export PG_CONFIG=/usr/lib/postgresql/18/bin/pg_config
make
sudo make install
```

If `curl-config` isn't in the path on you host, you can specify the path
explicitly:

```sh theme={null}
export CURL_CONFIG=/opt/homebrew/opt/curl/bin/curl-config
make
sudo make install
```

If you encounter an error such as:

```text theme={null}
"Makefile", line 8: Need an operator
```

You need to use GNU make, which may well be installed on your system as
`gmake`:

```sh theme={null}
gmake
gmake install
gmake installcheck
```

If you encounter an error such as:

```text theme={null}
make: pg_config: Command not found
```

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:

```sh theme={null}
export PG_CONFIG=/path/to/pg_config
make
sudo make install
```

To install the extension in a custom prefix on PostgreSQL 18 or later, pass
the `prefix` argument to `install` (but no other `make` targets):

```sh theme={null}
sudo make install prefix=/usr/local/extras
```

Then ensure that the prefix is included in the following [`postgresql.conf`
parameters]:

```ini theme={null}
extension_control_path = '/usr/local/extras/postgresql/share:$system'
dynamic_library_path   = '/usr/local/extras/postgresql/lib:$libdir'
```

<h4 id="testing">
  Testing
</h4>

To run the test suite, once the extension has been installed, run

```sh theme={null}
make installcheck
```

If you encounter an error such as:

```text theme={null}
ERROR:  must be owner of database regression
```

You need to run the test suite using a super user, such as the default
"postgres" super user:

```sh theme={null}
make installcheck PGUSER=postgres
```

<h3 id="loading">
  Loading
</h3>

Once `pg_clickhouse` is installed, you can add it to a database by connecting
as a super user and running:

```sql theme={null}
CREATE EXTENSION pg_clickhouse;
```

If you want to install `pg_clickhouse` and all of its supporting objects into
a specific schema, use the `SCHEMA` clause to specify the schema, like so:

```sql theme={null}
CREATE SCHEMA env;
CREATE EXTENSION pg_clickhouse SCHEMA env;
```

<h2 id="dependencies">
  Dependencies
</h2>

The `pg_clickhouse` extension requires [PostgreSQL] 13 or higher, [libcurl],
[libuuid]. Building the extension requires a C and C++ compiler, [libSSL], [GNU
make], and [CMake].

<h2 id="road-map">
  Road Map
</h2>

Our top focus is finishing pushdown coverage for analytic workloads before
adding DML features. Our road map:

* Get the remaining 10 un-pushed-down TPC-H queries optimally planned
* Test and fix pushdown for the ClickBench queries
* Support transparent pushdown of all PostgreSQL aggregate functions
* Support transparent pushdown of all PostgreSQL functions
* Allow server-level and session-level ClickHouse settings via CREATE SERVER
  and GUCs
* Support all ClickHouse data types
* Support lightweight DELETEs and UPDATEs
* Support batch insertion via COPY
* Add a function to execute an arbitrary ClickHouse query and return its
  results as a tables
* Add support for pushdown of UNION queries when they all query the remote
  database

<h2 id="authors">
  Authors
</h2>

* [David E. Wheeler](https://justatheory.com/)
* [Ildus Kurbangaliev](https://github.com/ildus)
* [Ibrar Ahmed](https://github.com/ibrarahmad)

<h2 id="copyright">
  Copyright
</h2>

* Copyright (c) 2025-2026, ClickHouse
* Portions Copyright (c) 2023-2025, Ildus Kurbangaliev
* Portions Copyright (c) 2019-2023, Adjust GmbH
* Portions Copyright (c) 2012-2019, PostgreSQL Global Development Group

[pg_clickhouse]: https://github.com/clickHouse/pg_clickhouse "pg_clickhouse on GitHub"

[import foreign tables]: /products/managed-postgres/extensions/pg_clickhouse/reference#import-foreign-schema

[Docker image]: https://github.com/ClickHouse/pg_clickhouse/pkgs/container/pg_clickhouse "Latest Docker release"

[tutorial]: /products/managed-postgres/extensions/pg_clickhouse/tutorial "pg_clickhouse Tutorial"

[PostgreSQL Apt]: https://wiki.postgresql.org/wiki/Apt

[PostgreSQL Yum]: https://yum.postgresql.org

[PGXN client]: https://pgxn.github.io/pgxnclient/ "PGXN Client’s documentation"

[Homebrew]: https://formulae.brew.sh/formula/pgxnclient#default "PGXN client on Homebrew"

[Apt]: https://tracker.debian.org/pkg/pgxnclient "PGXN client on Debian Apt"

[`postgresql.conf` parameters]: https://www.postgresql.org/docs/devel/runtime-config-client.html#RUNTIME-CONFIG-CLIENT-OTHER

[PostgreSQL]: https://www.postgresql.org "PostgreSQL: The World's Most Advanced Open Source Relational Database"

[libcurl]: https://curl.se/libcurl/ "libcurl — your network transfer library"

[libuuid]: https://linux.die.net/man/3/libuuid "libuuid - DCE compatible Universally Unique Identifier library"

[GNU make]: https://www.gnu.org/software/make "GNU Make"

[CMake]: https://cmake.org/ "CMake: A Powerful Software Build System"

[LibSSL]: https://openssl-library.org "OpenSSL Library"

[TPC-H]: https://www.tpc.org/tpch/

[re2]: https://github.com/ClickHouse/pg_re2 "pg_re2: ClickHouse-compatible regex functions using RE2"

\[Query 1] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/1.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/1.sql)
\[Query 2] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/2.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/2.sql)
\[Query 3] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/3.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/3.sql)
\[Query 4] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/4.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/4.sql)
\[Query 5] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/5.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/5.sql)
\[Query 6] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/6.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/6.sql)
\[Query 7] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/7.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/7.sql)
\[Query 8] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/8.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/8.sql)
\[Query 9] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/9.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/9.sql)
\[Query 10] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/10.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/10.sql)
\[Query 11] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/11.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/11.sql)
\[Query 12] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/12.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/12.sql)
\[Query 13] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/13.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/13.sql)
\[Query 14] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/14.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/14.sql)
\[Query 15] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/15.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/15.sql)
\[Query 16] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/16.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/16.sql)
\[Query 17] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/17.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/17.sql)
\[Query 18] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/18.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/18.sql)
\[Query 19] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/19.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/19.sql)
\[Query 20] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/20.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/20.sql)
\[Query 21] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/21.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/21.sql)
\[Query 22] [https://github.com/ClickHouse/pg\_clickhouse/blob/main/dev/tpch/queries/22.sql](https://github.com/ClickHouse/pg_clickhouse/blob/main/dev/tpch/queries/22.sql)
