pg_stat_ch
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_stat_ch | 0.3.4 | STAT | Apache-2.0 | C++ |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 6020 | pg_stat_ch | No | Yes | Yes | Yes | No | No | - |
| Related | pg_tracing pg_stat_monitor pg_stat_kcache powa |
|---|
Release tag 0.3.4 still ships extension SQL version 0.1 by upstream design; source tarball bundles third-party dependencies.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.3.4 | 1817161514 | pg_stat_ch | - |
| RPM | PIGSTY | 0.3.4 | 1817161514 | pg_stat_ch_$v | - |
| DEB | PIGSTY | 0.3.4 | 1817161514 | postgresql-$v-pg-stat-ch | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el8.aarch64 | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS | PIGSTY MISS |
| el9.x86_64 | PIGSTY 0.3.4 el9.x86_64.pg18 : pg_stat_ch_18 pg_stat_ch_18-0.3.4-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.3.4 el9.x86_64.pg17 : pg_stat_ch_17 pg_stat_ch_17-0.3.4-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.3.4 el9.x86_64.pg16 : pg_stat_ch_16 pg_stat_ch_16-0.3.4-1PIGSTY.el9.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el9.aarch64 | PIGSTY 0.3.4 el9.aarch64.pg18 : pg_stat_ch_18 pg_stat_ch_18-0.3.4-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.3.4 el9.aarch64.pg17 : pg_stat_ch_17 pg_stat_ch_17-0.3.4-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.3.4 el9.aarch64.pg16 : pg_stat_ch_16 pg_stat_ch_16-0.3.4-1PIGSTY.el9.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el10.x86_64 | PIGSTY 0.3.4 el10.x86_64.pg18 : pg_stat_ch_18 pg_stat_ch_18-0.3.4-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.3.4 el10.x86_64.pg17 : pg_stat_ch_17 pg_stat_ch_17-0.3.4-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.3.4 el10.x86_64.pg16 : pg_stat_ch_16 pg_stat_ch_16-0.3.4-1PIGSTY.el10.x86_64.rpm
| PIGSTY MISS | PIGSTY MISS |
| el10.aarch64 | PIGSTY 0.3.4 el10.aarch64.pg18 : pg_stat_ch_18 pg_stat_ch_18-0.3.4-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.3.4 el10.aarch64.pg17 : pg_stat_ch_17 pg_stat_ch_17-0.3.4-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.3.4 el10.aarch64.pg16 : pg_stat_ch_16 pg_stat_ch_16-0.3.4-1PIGSTY.el10.aarch64.rpm
| PIGSTY MISS | PIGSTY MISS |
| d12.x86_64 | PIGSTY 0.3.4 d12.x86_64.pg18 : postgresql-18-pg-stat-ch postgresql-18-pg-stat-ch_0.3.4-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.3.4 d12.x86_64.pg17 : postgresql-17-pg-stat-ch postgresql-17-pg-stat-ch_0.3.4-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.3.4 d12.x86_64.pg16 : postgresql-16-pg-stat-ch postgresql-16-pg-stat-ch_0.3.4-1PIGSTY~bookworm_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| d12.aarch64 | PIGSTY 0.3.4 d12.aarch64.pg18 : postgresql-18-pg-stat-ch postgresql-18-pg-stat-ch_0.3.4-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.3.4 d12.aarch64.pg17 : postgresql-17-pg-stat-ch postgresql-17-pg-stat-ch_0.3.4-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.3.4 d12.aarch64.pg16 : postgresql-16-pg-stat-ch postgresql-16-pg-stat-ch_0.3.4-1PIGSTY~bookworm_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
| d13.x86_64 | PIGSTY 0.3.4 d13.x86_64.pg18 : postgresql-18-pg-stat-ch postgresql-18-pg-stat-ch_0.3.4-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.3.4 d13.x86_64.pg17 : postgresql-17-pg-stat-ch postgresql-17-pg-stat-ch_0.3.4-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.3.4 d13.x86_64.pg16 : postgresql-16-pg-stat-ch postgresql-16-pg-stat-ch_0.3.4-1PIGSTY~trixie_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| d13.aarch64 | PIGSTY 0.3.4 d13.aarch64.pg18 : postgresql-18-pg-stat-ch postgresql-18-pg-stat-ch_0.3.4-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.3.4 d13.aarch64.pg17 : postgresql-17-pg-stat-ch postgresql-17-pg-stat-ch_0.3.4-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.3.4 d13.aarch64.pg16 : postgresql-16-pg-stat-ch postgresql-16-pg-stat-ch_0.3.4-1PIGSTY~trixie_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
| u22.x86_64 | PIGSTY 0.3.4 u22.x86_64.pg18 : postgresql-18-pg-stat-ch postgresql-18-pg-stat-ch_0.3.4-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.3.4 u22.x86_64.pg17 : postgresql-17-pg-stat-ch postgresql-17-pg-stat-ch_0.3.4-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.3.4 u22.x86_64.pg16 : postgresql-16-pg-stat-ch postgresql-16-pg-stat-ch_0.3.4-1PIGSTY~jammy_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| u22.aarch64 | PIGSTY 0.3.4 u22.aarch64.pg18 : postgresql-18-pg-stat-ch postgresql-18-pg-stat-ch_0.3.4-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.3.4 u22.aarch64.pg17 : postgresql-17-pg-stat-ch postgresql-17-pg-stat-ch_0.3.4-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.3.4 u22.aarch64.pg16 : postgresql-16-pg-stat-ch postgresql-16-pg-stat-ch_0.3.4-1PIGSTY~jammy_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
| u24.x86_64 | PIGSTY 0.3.4 u24.x86_64.pg18 : postgresql-18-pg-stat-ch postgresql-18-pg-stat-ch_0.3.4-1PIGSTY~noble_amd64.deb
| PIGSTY 0.3.4 u24.x86_64.pg17 : postgresql-17-pg-stat-ch postgresql-17-pg-stat-ch_0.3.4-1PIGSTY~noble_amd64.deb
| PIGSTY 0.3.4 u24.x86_64.pg16 : postgresql-16-pg-stat-ch postgresql-16-pg-stat-ch_0.3.4-1PIGSTY~noble_amd64.deb
| PIGSTY MISS | PIGSTY MISS |
| u24.aarch64 | PIGSTY 0.3.4 u24.aarch64.pg18 : postgresql-18-pg-stat-ch postgresql-18-pg-stat-ch_0.3.4-1PIGSTY~noble_arm64.deb
| PIGSTY 0.3.4 u24.aarch64.pg17 : postgresql-17-pg-stat-ch postgresql-17-pg-stat-ch_0.3.4-1PIGSTY~noble_arm64.deb
| PIGSTY 0.3.4 u24.aarch64.pg16 : postgresql-16-pg-stat-ch postgresql-16-pg-stat-ch_0.3.4-1PIGSTY~noble_arm64.deb
| PIGSTY MISS | PIGSTY MISS |
Build
You can build the RPM / DEB packages for pg_stat_ch using pig build:
pig build pkg pg_stat_ch # build RPM / DEB packages
Install
You can install pg_stat_ch 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_stat_ch; # Install for current active PG version
pig ext install -y pg_stat_ch -v 18 # PG 18
pig ext install -y pg_stat_ch -v 17 # PG 17
pig ext install -y pg_stat_ch -v 16 # PG 16
dnf install -y pg_stat_ch_18 # PG 18
dnf install -y pg_stat_ch_17 # PG 17
dnf install -y pg_stat_ch_16 # PG 16
apt install -y postgresql-18-pg-stat-ch # PG 18
apt install -y postgresql-17-pg-stat-ch # PG 17
apt install -y postgresql-16-pg-stat-ch # PG 16
Preload:
shared_preload_libraries = 'pg_stat_ch';
Create Extension:
CREATE EXTENSION pg_stat_ch;
Usage
Syntax:
CREATE EXTENSION pg_stat_ch; SELECT pg_stat_ch_version(); SELECT * FROM pg_stat_ch_stats();
pg_stat_ch captures per-query execution telemetry in PostgreSQL and exports raw events to ClickHouse in real time. The upstream project contrasts this with pg_stat_statements: instead of aggregating inside PostgreSQL, it sends raw events to ClickHouse for downstream analysis.
Architecture
The README describes a single pipeline:
PostgreSQL hooks -> shared memory queue -> background worker -> ClickHouse
Design goals called out upstream include:
- no network I/O on the query path
- bounded memory via a fixed-size ring buffer
- raw event export instead of local aggregation
- graceful degradation when the queue overflows or ClickHouse is unavailable
Setup
The extension must be preloaded and configured with ClickHouse connection settings:
shared_preload_libraries = 'pg_stat_ch'
track_io_timing = on
pg_stat_ch.clickhouse_host = 'localhost'
pg_stat_ch.clickhouse_port = 9000
pg_stat_ch.clickhouse_database = 'pg_stat_ch'
pg_stat_ch.clickhouse_use_tls = on
pg_stat_ch.clickhouse_skip_tls_verify = off
After PostgreSQL restart and ClickHouse schema setup:
CREATE EXTENSION pg_stat_ch;
SQL API
The README documents these SQL functions:
pg_stat_ch_version()pg_stat_ch_stats()pg_stat_ch_reset()
pg_stat_ch_stats() exposes queue and exporter counters so you can verify that events are being captured and flushed.
What Gets Captured
The current README lists support for:
- query timing and row counts
- buffer usage and WAL usage
- CPU time
- DML, DDL, and utility statements
- SQLSTATE and error levels
- JIT instrumentation on PostgreSQL 15+
- parallel worker statistics on PostgreSQL 18+
- client context such as application name and client IP
The project currently states full support for PostgreSQL 16, 17, and 18.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.