Open-source project
pgrundev/pgbot avatar
pgrundev/pgbot

pgbot reads Postgres statistics views and grades the result, and says which output is stable

Postgres intelligence for ai agents & apps

1,517 stars74 forksGoNOASSERTION

At a glance

What is it?
A single static binary that connects read-only, computes findings in Go from Postgres's own statistics views, and prints a scored health report. It also states plainly that the terminal report is not an interface to parse.
Who is it for?
pgbot earns a place in a terminal and in CI, and the reason is the part it refuses to fudge: findings are computed in Go from statistics views, the AI layer only narrates them, and the interface meant for scripts is versioned while the pretty output is explicitly unstable. Two checks before adopting it.
Can I use it commercially?
Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
Is it still maintained?
Yes. The repository last received commits 6 days ago.
What is it written in?
Mainly Go, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • pgrundev/pgbot1,517 β˜… Β· +394
Star history
Repository2026-09-112026-11-22
pgrundev/pgbot1.1k1.5k

394 Stars in the last 72 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

Read-only comes from the database role, not from a flag

The security claim is placed in the wrong half of most tools, which is to say it is placed in the database. The guarantee is a login role holding pg_monitor with no write grants, so a compromised binary still cannot write, because the database refuses it. On top of that the session is pinned: default_transaction_read_only, a statement timeout of fifteen seconds and a lock timeout of two seconds, plus an explicit read-only transaction. The project calls that defence in depth, which is the correct word for it.

The consequence for an operator is that the security property is not in the tool at all. There is no command-line switch that turns read-only on, and there is no configuration file. You create the role, you grant pg_monitor, you connect as that role, and the guarantee exists from the first packet. That also means pointing the binary at a superuser connection quietly throws the whole arrangement away, and nothing in the output will say so, because from the binary's point of view the queries succeeded. The report header does print the connection mode, so read-only versus not is visible at the top of the run, but it is a label rather than an enforcement.

The terminal report is not an API and the JSON contract is versioned at 1.5.0

The status note at the top of the page settles the interface question before anything else: the project is beta, the JSON contract is versioned and currently at 1.5.0 with a published JSON Schema, breaking changes to it are treated as breaking changes to the tool, and the human-readable report is not a stable interface. The instruction is to parse the JSON and not the terminal output.

That is a stronger position than most command line tools take, and it is visible in how the report is built. The default output is a graded read: a four-row gauge strip of cache hit, lock wait with the culprit query, rollbacks and idle index bytes, a checked line naming the subsystems that came back clean, a health score, then findings bucketed as critical, warning and note. An inspection with the full flag adds a subsystem status board with one row per subsystem in ok, warn or fail colours, plus section tables and per-finding caveats. The gauge bars and colours are presentation. The findings and the score are the contract, and only one of those two is versioned.

text
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

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%

Findings are computed in Go and the model only explains them

The AI story in this tool is unusually narrow, and the boundary is stated as a rule rather than a feature. Every finding is computed in Go from SQL. The optional AI layer explains findings, it never generates them, so a model cannot invent a critical that the collector did not measure. Two commands use it, ask and explain, and both need exactly one model key from the environment:

sh
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)

Anything else, including inspection, the queries section, indexes and the MCP server, needs no key at all, and the file is explicit that nothing leaves the machine on those paths. Any OpenAI-compatible endpoint works too, local ones included, so a team with a policy against hosted models can point at a local server. The four defaults are named per provider, which is the sort of detail that usually goes undocumented and is what determines what a plain question costs. The security surface that comes with this design is narrow but real: one environment variable grants the ability to send database findings to a third party, and the CA bundle in the container image exists precisely because that call needs working certificate roots.

Connection resolution has four levels and the fourth is a service file

How pgbot finds the database is documented as an ordered list, which is more than most tools give you. The argument is read first, then the environment variable DATABASE_URL, then PGBOT_DATABASE_URL, and finally PGSERVICE, which points at a libpq connection service file so that people who keep connections there can just export the service name and pass no argument at all. Two same-named variables in that order is a deliberate override mechanism, and it means a shell profile can silently win over a value a script meant to pass.

The quickstart shows both shapes:

sh
curl -fsSL https://pgbot.dev/install | sh
pgbot inspect "postgres://pgbot_ro@host:5432/db"
sh
export DATABASE_URL="postgres://pgbot_ro:…@host:5432/db?sslmode=require"
pgbot inspect

The stated reason for the environment form is that it keeps the password out of shell history and out of ps output, which is correct and is also why the sslmode parameter is shown in the second example. There is even a shell note in the file spelling out that the export has no dollar sign on the left and no spaces around the equals sign, aimed at the people who will otherwise get a command not found. For an agent calling this over MCP, the same precedence applies, so the credential a tool receives as an argument wins over anything in the environment it inherited.

The documented floor is PostgreSQL 14, the test matrix comment says 13

Version support is where the numbers disagree with each other. The requirements say PostgreSQL 14 to 18, with 16 to 18 fully supported and 14 to 15 best-effort, and the promise that collectors degrade rather than fail on older feature sets. The Makefile comment above the integration target says something different: a full collector matrix against PostgreSQL 13 to 18, which needs docker and a compose file. A reader comparing the two cannot tell whether 13 is tested, supported or simply untested, and the safe reading is the narrower one, 14 as the floor.

The rest of the dependency surface is honest about what is optional. pg_stat_statements is needed for the queries section and is optional, with the tool printing provider-specific install steps when it is missing rather than failing. The advise command needs the hypopg extension and PostgreSQL 16 or later, so it is unavailable on the versions that are already best-effort. Platforms cover Linux, macOS and Windows on both amd64 and arm64.

The integration approach behind those numbers is a compose file with a database per major version, and the matrix target does not run anything itself. It brings the services up and then echoes instructions to point a test variable at each one in turn, so the matrix is a manual loop rather than a single command that proves the range.

The container has no shell, and its certificate bundle exists for one command

The image is four instructions long and explains itself in comments. goreleaser builds the static binary with cgo disabled, and the Dockerfile only wraps it:

dockerfile
FROM gcr.io/distroless/static:nonroot
COPY pgbot /usr/bin/pgbot
USER nonroot:nonroot
ENTRYPOINT ["/usr/bin/pgbot"]

The distroless base ships a CA root bundle, and the comment says why: the HTTPS call made by the explain command fails with an opaque x509 error under sslmode=verify-full without roots. That is the single non-obvious line in the file, and it links the AI layer to the packaging. The base also provides a nonroot user and has neither a shell nor a package manager, which is the point of choosing it.

Because there is no run step, the per-architecture images build under buildx without QEMU emulation, so arm64 does not need an emulated builder. The local build makes the same cgo decision in the Makefile with a version stamped in through linker flags. Packaging is not only containers: the tree carries an install script, a goreleaser configuration, an npm directory, a Nix package and flake files, and the quickstart pipes the hosted install script straight into a shell.

From the third run on it reports what changed instead of what is

A snapshot of current values is a dashboard in disguise, and this tool tries not to be one. Every run writes a local baseline, and from the third run onward the report is about deltas: a query that got slower, a table that started sequential-scanning, an index that stopped being used. That is the difference between a tool you read once and a tool you run on a schedule, and it is why the findings in the sample output are phrased as movement, orders queries became slower in the last six hours, rather than as levels.

The baseline is local, which also means it is per machine and per user unless you arrange otherwise. Nothing in the file says where it is written, how to point it somewhere else, or how to delete it, so a CI runner that gets a fresh container each time will never reach the third-run behaviour. The dependency list carries a pure-Go SQLite driver, and the binary is compiled with cgo disabled, so whatever holds the baseline needs no cgo and no Postgres extension. On the agent-facing side, the same findings are reachable over the Model Context Protocol, with a skill and a Claude Code plugin on top, and the tree also holds a GitHub action definition and a published schema directory.

It names the tools it does not replace, and calls itself a snapshot

The comparison section is unusually direct. pgbot is a point-in-time diagnostic that you run, not a monitoring platform that you operate. If you want dashboards, alerting, long retention and multi-host rollups, the file says to run pganalyze, Percona PMM or pgwatch, and states plainly that pgbot does not replace them. It gives three reasons to reach for it instead: an answer in ten seconds without deploying anything, triaging a database you do not own, and giving an agent structured Postgres findings it can reason over.

Those three map onto the real use cases listed earlier, which are investigation of CI failures, answering questions with internal tools, summarising threads, recurring checks and digests, multi-step operational workflows, access to a real repo and test environment, and standardising agent behaviour across a team. Recurring checks are the case where the baseline earns its keep and where a monitoring platform would be the wrong shape.

One inconsistency in the packaging is worth flagging for anyone assessing it formally. The repository describes itself as Postgres intelligence for AI agents and apps, while the headline on the page says there is no agent anywhere in the path. Both are defensible, since the MCP surface exists for agents while the runtime has none, and a license file sits at the root while the declared license field is left unasserted, so the terms are not stated unambiguously by the repository itself.

Editorial conclusion

pgbot earns a place in a terminal and in CI, and the reason is the part it refuses to fudge: findings are computed in Go from statistics views, the AI layer only narrates them, and the interface meant for scripts is versioned while the pretty output is explicitly unstable. Two checks before adopting it. The first is version support, since the documented range starts at PostgreSQL 14 while the test matrix comment reaches back to 13, and anything below 16 is called best-effort. The second is the role: the read-only guarantee lives in a pg_monitor login role with no write grants, so it holds only if you create that role rather than pointing the binary at a superuser. If you need dashboards, alerting or long retention, the project itself points at other tools.

Frequently asked questions

What does pgbot need in order to connect to a database?

A login role holding pg_monitor with no write grants, and PostgreSQL 14 to 18 with 16 to 18 fully supported. The connection is taken from the argument first, then DATABASE_URL, then PGBOT_DATABASE_URL, then PGSERVICE. pg_stat_statements is optional and only affects the queries section.

Does pgbot need an AI API key to work?

Not for inspection, queries, indexes, the MCP server or CI, which are deterministic and keep everything on the machine. Only the ask and explain commands need a key, and any OpenAI-compatible endpoint works, local ones included, with the provider defaults named per vendor.

Can pgbot replace a Postgres monitoring platform?

No, and the project says so itself. It is a point-in-time diagnostic you run, while dashboards, alerting, long retention and multi-host rollups are what pganalyze, Percona PMM and pgwatch are for. It also records a local baseline on every run so later runs report what changed.

Is the pgbot terminal output safe to parse?

No. The status note says the human-readable report is not a stable interface and that scripts and agents should parse the JSON instead. That contract is versioned, currently at 1.5.0, with a published schema, and breaking changes to it are treated as breaking changes to the tool.

How do you install pgbot and what platforms are covered?

The quickstart pipes the hosted install script into a shell, and the repository also ships an install script, goreleaser configuration, a Docker image, an npm directory and Nix packaging. Linux, macOS and Windows are covered on both amd64 and arm64.

Official sources

  1. Issues
  2. pgrundev/pgbot on GitHub
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/pgrundev-pgbot.svg)](https://hysenlabs.com/projects/pgrundev-pgbot)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/pgrundev-pgbot.svg)](https://hysenlabs.com/projects/pgrundev-pgbot)

Was this useful?