跳转到主要内容

pg_stat_ch

Export PostgreSQL query telemetry to ClickHouse

pg_stat_ch : Export PostgreSQL query telemetry to ClickHouse

Overview

ID Extension Package Version Category License Language
6020 pg_stat_ch pg_stat_ch 0.4.0 STAT Apache-2.0 C++
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sLd-- No Yes Yes Yes no no
Maintained release/package 0.4.0 installs SQL extension 0.4. PG16-18; requires preload. Local RPM builds cover both EL8 architectures with a private Bison 3.8.2 build tool. Local matrix on 2026-10-10 has RPM 0.4.0 and DEB 0.3.6; retain maintained DEB 0.4.0. Repository publication is checked separately.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 0.4.0 18 17 16 15 14 pg_stat_ch -
RPM PIGSTY 0.4.0 18 17 16 15 14 pg_stat_ch_$v -
DEB PIGSTY 0.4.0 18 17 16 15 14 postgresql-$v-pg-stat-ch -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64 PIGSTY 0.4.0 PIGSTY 0.4.0 PIGSTY 0.4.0 N/A N/A
el8.aarch64 PIGSTY 0.4.0 PIGSTY 0.4.0 PIGSTY 0.4.0 N/A N/A
el9.x86_64 PIGSTY 0.4.0 PIGSTY 0.4.0 PIGSTY 0.4.0 N/A N/A
el9.aarch64 PIGSTY 0.4.0 PIGSTY 0.4.0 PIGSTY 0.4.0 N/A N/A
el10.x86_64 PIGSTY 0.4.0 PIGSTY 0.4.0 PIGSTY 0.4.0 N/A N/A
el10.aarch64 PIGSTY 0.4.0 PIGSTY 0.4.0 PIGSTY 0.4.0 N/A N/A
d12.x86_64 PIGSTY 0.3.6 PIGSTY 0.3.6 PIGSTY 0.3.6 N/A N/A
d12.aarch64 PIGSTY 0.3.6 PIGSTY 0.3.6 PIGSTY 0.3.6 N/A N/A
d13.x86_64 PIGSTY 0.3.6 PIGSTY 0.3.6 PIGSTY 0.3.6 N/A N/A
d13.aarch64 PIGSTY 0.3.6 PIGSTY 0.3.6 PIGSTY 0.3.6 N/A N/A
u22.x86_64 PIGSTY 0.3.6 PIGSTY 0.3.6 PIGSTY 0.3.6 N/A N/A
u22.aarch64 PIGSTY 0.3.6 PIGSTY 0.3.6 PIGSTY 0.3.6 N/A N/A
u24.x86_64 PIGSTY 0.3.6 PIGSTY 0.3.6 PIGSTY 0.3.6 N/A N/A
u24.aarch64 PIGSTY 0.3.6 PIGSTY 0.3.6 PIGSTY 0.3.6 N/A N/A
u26.x86_64 PIGSTY 0.3.6 PIGSTY 0.3.6 PIGSTY 0.3.6 N/A N/A
u26.aarch64 PIGSTY 0.3.6 PIGSTY 0.3.6 PIGSTY 0.3.6 N/A N/A
Package Version OS ORG SIZE File URL
pg_stat_ch_18 0.4.0 el8.x86_64 pigsty 9.0 MiB pg_stat_ch_18-0.4.0-1PGSTY.el8.x86_64.rpm
pg_stat_ch_18 0.4.0 el8.aarch64 pigsty 7.8 MiB pg_stat_ch_18-0.4.0-1PGSTY.el8.aarch64.rpm
pg_stat_ch_18 0.4.0 el9.x86_64 pigsty 6.4 MiB pg_stat_ch_18-0.4.0-1PGSTY.el9.x86_64.rpm
pg_stat_ch_18 0.4.0 el9.aarch64 pigsty 6.0 MiB pg_stat_ch_18-0.4.0-1PGSTY.el9.aarch64.rpm
pg_stat_ch_18 0.4.0 el10.x86_64 pigsty 6.8 MiB pg_stat_ch_18-0.4.0-1PGSTY.el10.x86_64.rpm
pg_stat_ch_18 0.4.0 el10.aarch64 pigsty 6.1 MiB pg_stat_ch_18-0.4.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-stat-ch 0.3.6 d12.x86_64 pigsty 720.3 KiB postgresql-18-pg-stat-ch_0.3.6-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-stat-ch 0.3.6 d12.aarch64 pigsty 649.5 KiB postgresql-18-pg-stat-ch_0.3.6-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-stat-ch 0.3.6 d13.x86_64 pigsty 731.0 KiB postgresql-18-pg-stat-ch_0.3.6-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-stat-ch 0.3.6 d13.aarch64 pigsty 656.1 KiB postgresql-18-pg-stat-ch_0.3.6-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-stat-ch 0.3.6 u22.x86_64 pigsty 5.4 MiB postgresql-18-pg-stat-ch_0.3.6-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-stat-ch 0.3.6 u22.aarch64 pigsty 5.1 MiB postgresql-18-pg-stat-ch_0.3.6-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-stat-ch 0.3.6 u24.x86_64 pigsty 716.9 KiB postgresql-18-pg-stat-ch_0.3.6-1PIGSTY~noble_amd64.deb
postgresql-18-pg-stat-ch 0.3.6 u24.aarch64 pigsty 683.3 KiB postgresql-18-pg-stat-ch_0.3.6-1PIGSTY~noble_arm64.deb
postgresql-18-pg-stat-ch 0.3.6 u26.x86_64 pigsty 734.0 KiB postgresql-18-pg-stat-ch_0.3.6-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-stat-ch 0.3.6 u26.aarch64 pigsty 717.7 KiB postgresql-18-pg-stat-ch_0.3.6-1PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_stat_ch_17 0.4.0 el8.x86_64 pigsty 9.0 MiB pg_stat_ch_17-0.4.0-1PGSTY.el8.x86_64.rpm
pg_stat_ch_17 0.4.0 el8.aarch64 pigsty 7.8 MiB pg_stat_ch_17-0.4.0-1PGSTY.el8.aarch64.rpm
pg_stat_ch_17 0.4.0 el9.x86_64 pigsty 6.4 MiB pg_stat_ch_17-0.4.0-1PGSTY.el9.x86_64.rpm
pg_stat_ch_17 0.4.0 el9.aarch64 pigsty 6.0 MiB pg_stat_ch_17-0.4.0-1PGSTY.el9.aarch64.rpm
pg_stat_ch_17 0.4.0 el10.x86_64 pigsty 6.8 MiB pg_stat_ch_17-0.4.0-1PGSTY.el10.x86_64.rpm
pg_stat_ch_17 0.4.0 el10.aarch64 pigsty 6.1 MiB pg_stat_ch_17-0.4.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-stat-ch 0.3.6 d12.x86_64 pigsty 719.4 KiB postgresql-17-pg-stat-ch_0.3.6-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-stat-ch 0.3.6 d12.aarch64 pigsty 648.1 KiB postgresql-17-pg-stat-ch_0.3.6-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-stat-ch 0.3.6 d13.x86_64 pigsty 730.8 KiB postgresql-17-pg-stat-ch_0.3.6-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-stat-ch 0.3.6 d13.aarch64 pigsty 655.8 KiB postgresql-17-pg-stat-ch_0.3.6-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-stat-ch 0.3.6 u22.x86_64 pigsty 5.4 MiB postgresql-17-pg-stat-ch_0.3.6-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-stat-ch 0.3.6 u22.aarch64 pigsty 5.1 MiB postgresql-17-pg-stat-ch_0.3.6-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-stat-ch 0.3.6 u24.x86_64 pigsty 716.7 KiB postgresql-17-pg-stat-ch_0.3.6-1PIGSTY~noble_amd64.deb
postgresql-17-pg-stat-ch 0.3.6 u24.aarch64 pigsty 683.1 KiB postgresql-17-pg-stat-ch_0.3.6-1PIGSTY~noble_arm64.deb
postgresql-17-pg-stat-ch 0.3.6 u26.x86_64 pigsty 735.5 KiB postgresql-17-pg-stat-ch_0.3.6-1PIGSTY~resolute_amd64.deb
postgresql-17-pg-stat-ch 0.3.6 u26.aarch64 pigsty 719.1 KiB postgresql-17-pg-stat-ch_0.3.6-1PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
pg_stat_ch_16 0.4.0 el8.x86_64 pigsty 9.0 MiB pg_stat_ch_16-0.4.0-1PGSTY.el8.x86_64.rpm
pg_stat_ch_16 0.4.0 el8.aarch64 pigsty 7.8 MiB pg_stat_ch_16-0.4.0-1PGSTY.el8.aarch64.rpm
pg_stat_ch_16 0.4.0 el9.x86_64 pigsty 6.4 MiB pg_stat_ch_16-0.4.0-1PGSTY.el9.x86_64.rpm
pg_stat_ch_16 0.4.0 el9.aarch64 pigsty 6.0 MiB pg_stat_ch_16-0.4.0-1PGSTY.el9.aarch64.rpm
pg_stat_ch_16 0.4.0 el10.x86_64 pigsty 6.8 MiB pg_stat_ch_16-0.4.0-1PGSTY.el10.x86_64.rpm
pg_stat_ch_16 0.4.0 el10.aarch64 pigsty 6.1 MiB pg_stat_ch_16-0.4.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-stat-ch 0.3.6 d12.x86_64 pigsty 719.6 KiB postgresql-16-pg-stat-ch_0.3.6-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-stat-ch 0.3.6 d12.aarch64 pigsty 649.4 KiB postgresql-16-pg-stat-ch_0.3.6-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-stat-ch 0.3.6 d13.x86_64 pigsty 729.5 KiB postgresql-16-pg-stat-ch_0.3.6-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-stat-ch 0.3.6 d13.aarch64 pigsty 656.6 KiB postgresql-16-pg-stat-ch_0.3.6-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-stat-ch 0.3.6 u22.x86_64 pigsty 5.4 MiB postgresql-16-pg-stat-ch_0.3.6-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-stat-ch 0.3.6 u22.aarch64 pigsty 5.1 MiB postgresql-16-pg-stat-ch_0.3.6-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-stat-ch 0.3.6 u24.x86_64 pigsty 716.4 KiB postgresql-16-pg-stat-ch_0.3.6-1PIGSTY~noble_amd64.deb
postgresql-16-pg-stat-ch 0.3.6 u24.aarch64 pigsty 681.9 KiB postgresql-16-pg-stat-ch_0.3.6-1PIGSTY~noble_arm64.deb
postgresql-16-pg-stat-ch 0.3.6 u26.x86_64 pigsty 733.9 KiB postgresql-16-pg-stat-ch_0.3.6-1PIGSTY~resolute_amd64.deb
postgresql-16-pg-stat-ch 0.3.6 u26.aarch64 pigsty 717.6 KiB postgresql-16-pg-stat-ch_0.3.6-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pg_stat_ch;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pg_stat_ch;		# install via package name, for the active PG version

pig install pg_stat_ch -v 18;   # install for PG 18
pig install pg_stat_ch -v 17;   # install for PG 17
pig install pg_stat_ch -v 16;   # install for PG 16

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_stat_ch';

Create this extension with:

CREATE EXTENSION pg_stat_ch;

Usage

Sources: README, release 0.3.6

pg_stat_ch captures per-query PostgreSQL execution telemetry and exports raw events to ClickHouse through a shared-memory queue and background worker. The upstream project positions it as a raw-event alternative to pg_stat_statements, with aggregation and dashboards handled in ClickHouse instead of PostgreSQL.

CREATE EXTENSION pg_stat_ch;

Required Setup

pg_stat_ch must be preloaded and pointed at a ClickHouse database:

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

The README says PostgreSQL 16, 17, and 18 are fully supported; the latest release is 0.3.6 from April 15, 2026.

SQL API

  • pg_stat_ch_version() returns the extension version.
  • pg_stat_ch_stats() exposes queue and exporter counters.
  • pg_stat_ch_reset() clears queue counters.
  • pg_stat_ch_flush() triggers an immediate export flush.
SELECT pg_stat_ch_version();
SELECT * FROM pg_stat_ch_stats();
SELECT pg_stat_ch_flush();

Important GUCs

  • pg_stat_ch.enabled toggles collection.
  • pg_stat_ch.queue_capacity and pg_stat_ch.string_area_size size the shared-memory buffers.
  • pg_stat_ch.flush_interval_ms and pg_stat_ch.batch_max control exporter cadence and batch size.
  • pg_stat_ch.log_min_elevel controls which errors are captured.

What Gets Captured

  • Query timing, row counts, buffer usage, WAL usage, and CPU time.
  • DML, DDL, and utility statements.
  • SQLSTATE and error levels.
  • JIT metrics on PostgreSQL 15+.
  • Parallel worker stats on PostgreSQL 18+.
  • Application name, client IP, and query text up to the upstream truncation limit.

Release 0.3.6 replaces the normalize cache with a queryId-keyed LRU cache and replaces the OpenTelemetry SDK with a direct-protobuf exporter plus sampling support. Existing SQL usage remains centered on the event tables, summary views, and reset/version helper functions above.

Caveats

  • The design intentionally drops events on queue overflow instead of blocking the foreground query path.
  • ClickHouse schema creation is a required part of setup; upstream quickstart scripts preload it automatically, but manual deployments must load the schema separately.
  • Pigsty’s current RPM refresh for pg_stat_ch is PostgreSQL 16-18 on EL9/EL10 only; Debian/Ubuntu packages remain PostgreSQL 16-18 on the active targets.