pgbot
In-database observability for PostgreSQL.
One static binary connects read-only, reads Postgres's own statistics views,
and prints a findings-first health report — plus what changed since last time.
No agent, no external service, no write privilege anywhere in the path.
Quickstart ·
Install ·
Setup ·
Commands ·
CI ·
MCP ·
JSON contract ·
Troubleshooting ·
Provider notes
Status: beta. The --json contract is versioned (currently 1.6.0, JSON
Schema published in schema/) and breaking changes to it are
treated as breaking changes to the tool. The human-readable report is not
a stable interface — parse --json, not the terminal output.
Quickstart

curl -fsSL https://pgbot.dev/install | sh
pgbot inspect "postgres://pgbot_ro@host:5432/db"
Or set the connection once in the environment and drop the argument — handy for
CI and shells, and it keeps the password out of your history and ps:
export DATABASE_URL="postgres://pgbot_ro@host:5432/db"
pgbot inspect
pgbot reads the argument first, then $DATABASE_URL, then $PGBOT_DATABASE_URL,
then $PGSERVICE (if you keep your connections in a
connection service file,
just export PGSERVICE=mydb and drop the argument too).
(Shell note: export DATABASE_URL="…" — no $ on the left, no spaces around =.)
Everything pgbot takes from the environment fits in one block — the connection,
and (only if you want the optional ask/explain AI layer) one model key:
export DATABASE_URL="[REDACTED:DB Connection String]
# optional, for `pgbot ask` / `pgbot explain` — one of:
export OPENAI_API_KEY=sk-… # → OpenAI (gpt-5.6-terra by default)
export GEMINI_API_KEY=… # → Google Gemini (AI Studio key)
export ANTHROPIC_API_KEY=… # → Anthropic (claude-opus-5 by default)
export XAI_API_KEY=… # → xAI (grok-4.6 by default)
# …or any OpenAI-compatible endpoint, local ones included — see "explain — optional AI layer"
Everything else — inspect, queries, indexes, MCP, CI — is fully
deterministic and needs no key; nothing leaves your machine. Provider
pinning and model/endpoint overrides: the AI layer.
connected · db.example.com · postgres 17.4 · read-only · 6h20m window
cache hit [████████████████████] 99.4% ok
lock wait [████████████░░░░░░░░] 61.0% query 4f2a
rollbacks [██░░░░░░░░░░░░░░░░░░] 12.0% watch
idle idx [██████░░░░░░░░░░░░░░] 18.0 GiB review
checked · queries · vacuum · replication · checkpoints
· connections · settings · deadlocks
Database health: 82/100
CRITICAL
● transaction-id age 1.8B — 84% toward wraparound
WARNING
● orders queries 3.2× slower (8 → 26 ms mean)
● 3 unused indexes consume 18 GB
● connection usage reached 87%
Details: pgbot inspect --full · Machine-readable: --json
Ask it: pgbot ask "why is it slow?"