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.
Quick start with Docker
From the repository root:docker/quickstart/ for stack details.
To stop the stack:
Production setup
For production, apply the schema directly to your ClickHouse instance:docker/init/00-schema.sql) is the single source of truth. It creates:
- The
pg_stat_chdatabase - The
events_rawtable with all columns - Four materialized views for common analytics
Configure PostgreSQL to connect
Set the ClickHouse connection parameters inpostgresql.conf:
Verify data flow
After connecting, check that events are being exported:exported_events should increase as queries run. If send_failures is non-zero, check last_error_text for the error message.
Schema overview
Theevents_raw table stores one row per query execution with 50+ columns covering timing, buffer usage, WAL, CPU, JIT, errors, and client context.
For the complete column reference, see events schema.
Four materialized views provide pre-aggregated analytics:
| View | Purpose | Retention |
|---|---|---|
events_recent_1h | Real-time debugging | 1-hour TTL |
query_stats_5m | Query performance dashboards (p95/p99) | Unbounded |
db_app_user_1m | Load by application/user | Unbounded |
errors_recent | Error investigation | 7-day TTL |
-State/-Merge aggregation pattern, see materialized views.
Data retention
Theevents_raw table has no TTL by default. To limit storage, add a TTL:
events_recent_1h, errors_recent) clean up automatically. For the unbounded views (query_stats_5m, db_app_user_1m), add TTLs based on your retention needs:
ClickHouse sizing
pg_stat_ch events compress well in ClickHouse. Rough estimates:| QPS | Events/day | Raw size/day | Compressed/day |
|---|---|---|---|
| 100 | 8.6M | ~39 GB | ~2-4 GB |
| 1,000 | 86M | ~390 GB | ~20-40 GB |
| 10,000 | 864M | ~3.9 TB | ~200-400 GB |

