DEDUPED Hot AI repos. Real use cases. What people build. Get the Monday 5

How to spot unused indexes and likely missing indexes with Pgbot

Find zero-scan indexes and large tables with heavy sequential scans before dropping or adding anything.

Short answer: Set the connection with export DATABASE_URL="postgres://pgbot_ro@host:5432/db"; then run pgbot indexes to list zero-scan indexes with sizes; read the caveat on the output: scan counts are per node, so check replicas before you drop anything. All steps.

Who it is forA database engineer tuning schema and indexes who must avoid dropping an index that a replica still uses.

The problemIndex drops and additions are risky when scan counts are misread, and manual checks across tables take time.

The outcomeA list of zero-scan indexes with sizes, a list of large tables with heavy sequential scans, and a caveat about which indexes not to drop.

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

  1. Set the connection with export DATABASE_URL="postgres://pgbot_ro@host:5432/db".
  2. Run pgbot indexes to list zero-scan indexes with sizes.
  3. Read the caveat on the output: scan counts are per node, so check replicas before you drop anything.
  4. Run pgbot tables and look for large tables with many seq scans and few idx scans as index candidates.
  5. On PostgreSQL 16 or later with hypopg installed, run pgbot advise for planner-validated missing-index suggestions. (inferred, check the README)

Prompt for your agent

Use the pgbot tool from the pgrundev/pgbot repository to run `pgbot indexes --json` and `pgbot tables --json` against <target-db-url>. List the zero-scan indexes with their sizes and the large tables with heavy sequential scans. Verify that you do not recommend dropping any index while replication is active without stating the per-node scan caveat.

Caveat. The advise command needs the hypopg extension and PostgreSQL 16 or later, and its planner checks run against the connected database only.

Use this in your AI agent

Ask your agent

Using the Deduped MCP, get the setup steps for pgrundev/pgbot and "Spot unused indexes and likely missing indexes"

Add Deduped to Claude Code once

claude mcp add --transport http deduped https://dedupedai.com/mcp

Cursor, ChatGPT, others

Share: X LinkedIn Hacker News Email Copy link

Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer