pg_stat_ch can export query telemetry as OpenTelemetry logs instead of inserting directly into ClickHouse. This lets you route data through your existing observability pipeline (Grafana, Datadog, Honeycomb, etc.) without running a separate ClickHouse instance.Documentation Index
Fetch the complete documentation index at: https://pg-stat-ch.clickhouse.com/llms.txt
Use this file to discover all available pages before exploring further.
Enable OpenTelemetry mode
Set these parameters inpostgresql.conf and restart PostgreSQL:
use_otel is enabled, the ClickHouse connection parameters are ignored. The background worker sends events to the OTel collector via gRPC.
How it works
The OTel exporter maps pg_stat_ch events to OpenTelemetry semantic conventions:- Logs: Each query execution becomes an OTel log record with attributes following the database semantic conventions (
db.name,db.user,db.operation.name,db.query.text).
Configuration
All OTel-specific parameters require a PostgreSQL restart.| Parameter | Default | Description |
|---|---|---|
pg_stat_ch.otel_endpoint | localhost:4317 | OTel collector gRPC endpoint (host:port) |
pg_stat_ch.otel_log_queue_size | 65536 | Compatibility no-op; pg_stat_ch’s shared-memory queue already buffers events |
pg_stat_ch.otel_log_batch_size | 8192 | Max records per OTLP log export call |
pg_stat_ch.otel_log_max_bytes | 3145728 (3 MiB) | Soft byte budget per OTLP log export call |
pg_stat_ch.otel_log_delay_ms | 100 | Per-export gRPC deadline |
pg_stat_ch.otel_metric_interval_ms | 5000 | Compatibility no-op retained for legacy configs |
Example: OTel Collector to ClickHouse
You can use the OpenTelemetry Collector as a middle layer between pg_stat_ch and ClickHouse. This is useful when you want to fan out data to multiple backends or apply transformations.Example: Grafana with Tempo/Loki
Route pg_stat_ch logs to Loki for Grafana dashboards:Verify data is flowing
Check export health the same way as with ClickHouse:send_failures is increasing, check:
- The OTel collector is running and reachable at the configured endpoint
- The collector’s gRPC receiver is listening on port 4317
- PostgreSQL logs for connection error details

