Agent Skillspgrundev/pgbot › postgres-diagnostics

postgres-diagnostics

GitHub

用于诊断PostgreSQL数据库性能、健康状态及优化建议的只读技能。通过pgbot工具分析慢查询、索引、真空等指标,生成优先级明确的优化计划,严禁执行写入操作或猜测数据。

skills/postgres-diagnostics/SKILL.md pgrundev/pgbot

Trigger Scenarios

数据库响应缓慢 询问如何优化或调整配置 检查数据库健康状况 评估索引有效性 排查磁盘空间占用

Install

npx skills add pgrundev/pgbot --skill postgres-diagnostics -g -y
More Options

Use without installing

npx skills use pgrundev/pgbot@postgres-diagnostics

指定 Agent (Claude Code)

npx skills add pgrundev/pgbot --skill postgres-diagnostics -a claude-code -g -y

安装 repo 全部 skill

npx skills add pgrundev/pgbot --all -g -y

预览 repo 内 skill

npx skills add pgrundev/pgbot --list

SKILL.md

Frontmatter
{
    "name": "postgres-diagnostics",
    "description": "Use when someone reports a slow, bloated, or unhealthy PostgreSQL database, or asks what to optimize, drop, vacuum, index, or tune. Runs read-only pgbot diagnostics and turns them into a prioritized, caveat-aware plan. Do not use for writing SQL, migrations, or app logic."
}

PostgreSQL diagnostics with pgbot

pgbot is a read-only Postgres diagnostic tool. Its findings are computed deterministically (in Go, not by a model) and it never writes to the database. Treat pgbot's output as the source of truth. Your job is to run the right command, then interpret, prioritize, and recommend — never to invent diagnoses or act on the database.

When to use this skill

  • "why is my database slow", "what should I optimize", "is my DB healthy?"
  • "which indexes can I drop", "what's using all the disk", "is autovacuum keeping up?"
  • "what query is eating the database", "should I re-tune anything?"
  • Any Postgres performance / health / bloat / index / vacuum / config question.

How to run it

If the pgbot MCP server is connected, call its tools: inspect (start here), top_queries, vacuum_health, unused_indexes. They return stable JSON.

Otherwise run the CLI. It needs a connection string for a read-capable role (ideally one with pg_monitor). Pick the command that matches the question:

Question Command
Open-ended / "is it healthy" pgbot inspect "$DSN" (health score + worst-first findings)
Full detail pgbot inspect "$DSN" --full
"What's eating the database?" pgbot queries "$DSN" (top by total time; --by-calls to re-rank)
"What's using disk / biggest tables?" pgbot tables "$DSN" (size + seq-vs-index scan = missing-index radar)
"Is autovacuum keeping up?" pgbot vacuum "$DSN"
"Which indexes can I drop?" pgbot indexes "$DSN"
"Should I re-tune config?" pgbot tune "$DSN"
Machine-readable for parsing pgbot inspect "$DSN" --json

Add --timeout 60s for large or remote databases.

Rules — non-negotiable

  1. Findings are facts. Do not invent a number, table, index, or query id beyond what pgbot reports. If pgbot didn't measure it, say what pgbot would need to collect to find out.
  2. Carry every caveat into the recommendation. Example: "unused index" scan counts are per-node — on a primary, a replica may still use an index that looks unused. pgbot flags this; never recommend dropping an index without its caveat. (pgbot's tables/indexes and the JSON make replication state visible — check it.)
  3. Never execute the user's query to diagnose it. No EXPLAIN ANALYZE, no running the statement "just to time it." Suggest only safe, non-executing steps (EXPLAIN without ANALYZE is fine; it doesn't run the query).
  4. Prioritize by impact, not by count. Risk (time-to-incident: wraparound, a WAL-pinning replication slot, a filling disk) comes first. Then the biggest latency/storage win. A 9 GiB unused-index reclaim may matter less than one query eating 60% of DB time — say which to do first and why.
  5. Never write to the database. pgbot is read-only; you recommend, you don't act. Hand the user the exact DROP INDEX CONCURRENTLY / ALTER / VACUUM statement to run themselves.
  6. Hedge low confidence. A finding below 0.5 confidence is a possibility ("may", "possibly"), not an assertion.

Output shape

  1. One-line health verdict.
  2. Worst-first, at most ~3 issues. For each: the problem with pgbot's number → a likely cause only if the data (deltas/events) supports one → a safe, concrete recommended step, with its caveat inline.
  3. Briefly name what's healthy, so the user knows what was checked.

Reading the signals

  • tables: a large table with heavy seq scans and few idx scans is a likely missing-index candidate — cross-check it against queries (a top query filtering that table confirms it).
  • queries: share is % of total DB execution time. A single query above ~30% is the real hot path; index-dropping won't touch it.
  • vacuum: due? yes with a stale/never last-autovacuum means autovacuum is falling behind — the early signal for bloat and, downstream, wraparound.
  • replication-slot findings: an inactive slot retaining WAL fills the disk; treat it as time-to-incident, not cosmetic.

Safety and privacy

pgbot only ever reads. Nothing leaves the machine except pgbot explain / pgbot ask, which send the PII-free findings (normalized query text, no literals) to an LLM and say so first. Use a role with pg_monitor; never paste a production superuser credential where it can leak.

Version History

  • 0b7a374 Current 2026-08-19 11:33

Metadata

Files
0
Version
0b7a374
Hash
6c7fd145
Indexed
2026-08-19 11:33

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-20 01:40
浙ICP备14020137号-1 $방문자$