Who it is forA developer or DBA who knows the app is slow and needs to see which SQL statements take the most database time.
The problemA cheap query run a million times can cost more than an expensive query run twice, and the two are hard to compare by hand.
The outcomeA ranked list of statements with total time, share of total time, call count, and mean time, ready to hand to a tuning pass.
What you need first
- A PostgreSQL server version 14 to 18 that you can reach over the network
- A login role with the pg_monitor role and no write grants (pgbot init generates the setup SQL)
- The pgbot binary, installed with the curl install script or npx @pgbot/cli
- Optional: pg_stat_statements for the queries section, and hypopg on PostgreSQL 16+ for advise
Steps
- Confirm the pg_stat_statements extension is installed on the target, since Pgbot prints install steps if it is missing.
- Set the connection with
export DATABASE_URL="postgres://pgbot_ro@host:5432/db". - Run
pgbot queriesto rank statements by total execution time. - Run
pgbot queries --by-callsto rank by call count and compare the two lists. (inferred, check the README) - Run
pgbot ask "why is it slow?"for a plain-language reading of the same findings, if you have a model key set.
Prompt for your agent
Use the pgbot tool from the pgrundev/pgbot repository to run `pgbot queries --json` against <target-db-url>. Return the top five statements by total time with their share and call count. Verify that the response has enabled true and available true before you report an empty list as a real empty workload.
Caveat. Query statistics only exist when pg_stat_statements is enabled, and Pgbot reports an extension it cannot read as unavailable rather than as an empty workload.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for pgrundev/pgbot and "Find the queries that eat the most database time"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer