All skills
clickhouse avatar

/clickhouse-managed-postgres-rca

@544384f official
by clickhouseclickhouse/agent-skills543 stars
39

MUST USE when investigating performance issues on a ClickHouse-managed Postgres instance. Provides an evidence-based RCA workflow that scrapes the Prometheus endpoint for system signal, pulls per-digest evidence from the Slow Query Patterns API, and recommends (does not apply) a fix.

Use this Skill: https://skilld.dev/gh/clickhouse/agent-skills/clickhouse-managed-postgres-rca

This session only. Nothing lands on disk.

rulesprometheus-scrape.md

≈901 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Prometheus scrape

How

Use the path resolved during OpenAPI discovery (postgresInstancePrometheusGet). HTTP Basic with the user's ClickHouse Cloud API key/secret.

curl -s -u "$CH_CLOUD_KEY:$CH_CLOUD_SECRET" \
  "https://api.clickhouse.cloud/<resolved path>" > /tmp/pg-prom.txt

The response is Prometheus exposition format text (lines like PostgresServer_X{...} <value>).

Default: one scrape, gauges only

The skill's default Prom step is a single scrape that extracts current values from gauges. No wait, no second scrape. The Slow Query Patterns API gives the per-pattern rate-of-change data — see slow-query-patterns-fields.md — so the only role left for Prom is system-level context.

Gauges to read on the single scrape:

  • PostgresServer_CacheHitRatio — current ratio. Below ~95% on a workload that should fit in cache = cache thrash.
  • PostgresServer_ActiveConnections — current count (often split by state label: active / idle / idle in transaction). Climbing toward a known pool ceiling = client fan-out or stuck queries.
  • PostgresServer_MemoryUsedPercent — current. Helps qualify cache hit ratio (low memory usage but bad hit ratio = the workload is bigger than RAM).
  • PostgresServer_FilesystemUsedPercent — current. High = storage pressure, separate concern from query latency.

Opt-in: rate-of-change from two scrapes

Only do a second scrape when Step 4 triage hints at write congestion or you need a signal that's nowhere else:

  • PostgresServer_Deadlocks_Total — non-zero delta means lock-cycle deadlocks: Postgres detected a circular lock wait and aborted one transaction to break it. This is not the same as a serialization conflict (SQLSTATE 40001 under SERIALIZABLE / REPEATABLE READ) — different mechanism, different fix (consistent lock ordering vs. retry/isolation review). See sub-patterns A and C in heuristic-write-congestion.md. Not surfaced in Slow Query Patterns.
  • PostgresServer_TransactionsRolledBack_Total vs _Committed_Total — rollback rate; also not directly in Slow Query Patterns.
  • PostgresServer_DiskWrites_Total — global write pressure (useful for sub-pattern B / WAL congestion in heuristic-write-congestion.md).

When doing the second scrape, the upstream collector refreshes exposed values roughly once per minute (verified empirically, May 2026 — not stated in the docs). A gap shorter than ~60s returns identical counter values. Use ≥90s, 120s is the safe default. If your delta on every counter is zero despite live traffic, suspect that you scraped within one refresh window.

curl -s -u "$CH_CLOUD_KEY:$CH_CLOUD_SECRET" \
  "https://api.clickhouse.cloud/<resolved path>" > /tmp/pg-prom-1.txt
sleep 120
curl -s -u "$CH_CLOUD_KEY:$CH_CLOUD_SECRET" \
  "https://api.clickhouse.cloud/<resolved path>" > /tmp/pg-prom-2.txt

Document the gap you used so a reader can sanity-check.

What this surface does NOT show

No per-query metrics. No scan-type counters. No autovacuum/analyze timestamps. No load averages. The per-query story lives in Slow Query Patterns.

Field name caveat

Metric names listed above match the user-facing docs at https://clickhouse.com/docs/cloud/managed-postgres/monitoring/metrics. Confirm exact casing in the actual scrape output on first use; the API is Beta and names may shift.

Source: SKILL.md on GitHub

1 alert3mo3 checks · Risk SAFE
  • Gen Agent Trust Hub3mo

    This skill provides a structured diagnostic workflow for ClickHouse-managed Postgres instances. It fetches system metrics and query patterns from official ClickHouse Cloud APIs to identify performance bottlenecks like full scans or hot loops. It includes a strong 'recommend-only' guardrail, ensuring no modifications are made to the database.

  • Socket3mo

    No alerts

  • Snyk3mo

    Risk: HIGH · 3 issues

Signed by skilld at 544384f. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 4 months ago
metadata
{
  "author": "ClickHouse Inc",
  "version": "0.1.0"
}
  • Performance
  • clickhouse
  • postgres
  • rca
  • troubleshooting
  • prometheus
  • slow-query
  • managed-database

README badge

README badge for clickhouse/agent-skills/clickhouse-managed-postgres-rca

Investigates performance issues on ClickHouse-managed Postgres instances by scraping Prometheus metrics and querying the Slow Query Patterns API to identify the root cause. Follows a six-step RCA workflow that reasons from system signals and query digests to recommend (but not apply) fixes like addressing full table scans, N+1 loops, or write congestion.

Generated from the current SKILL.md.

Does this skill work with self-hosted Postgres or only ClickHouse Cloud?
Only ClickHouse Cloud managed Postgres instances. The skill requires the ClickHouse Cloud API endpoints for Prometheus metrics and the Slow Query Patterns API.
What credentials do I need to use this skill?
A ClickHouse Cloud API key and secret pair for HTTP Basic auth, plus the organization ID and service ID for the Postgres instance you're investigating.
Can this skill apply fixes automatically?
No. The skill diagnoses the issue and recommends a fix, but the human must apply it. The skill never runs DDL or backend termination commands.
Does this skill provide query plans or EXPLAIN output?
No. It reasons from Prometheus system metrics and slow query pattern statistics, not from query plans. You will not get per-table scan counts or autovacuum timestamps.
How long does the RCA workflow take?
Approximately 1 second. Steps 2 and 3 (Prometheus scrape and slow query patterns) run in parallel, reducing wall time from ~2s sequential to ~1s.

Generated from the current SKILL.md. These answers refresh after source changes.