{
 "schema_version": 1,
 "generated": "2026-10-20",
 "id": "pgrundev-pgbot--spot-unused-and-missing-indexes",
 "repo": "pgrundev/pgbot",
 "repo_url": "https://github.com/pgrundev/pgbot",
 "repo_slug": "pgrundev-pgbot",
 "title": "Spot unused indexes and likely missing indexes",
 "page_title": "How to spot unused indexes and likely missing indexes with Pgbot",
 "summary": "Find zero-scan indexes and large tables with heavy sequential scans before dropping or adding anything.",
 "who": "A database engineer tuning schema and indexes who must avoid dropping an index that a replica still uses.",
 "problem": "Index drops and additions are risky when scan counts are misread, and manual checks across tables take time.",
 "outcome": "A 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.",
 "steps": [
  "Set the connection with `export DATABASE_URL=\"postgres://pgbot_ro@host:5432/db\"`.",
  "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.",
  "Run `pgbot tables` and look for large tables with many seq scans and few idx scans as index candidates.",
  "On PostgreSQL 16 or later with hypopg installed, run `pgbot advise` for planner-validated missing-index suggestions. (inferred, check the README)"
 ],
 "agent_prompt": "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.",
 "agents": [
  "any"
 ],
 "difficulty": "Intermediate",
 "time": "30 minutes",
 "basis": "readme",
 "caveat": "The advise command needs the hypopg extension and PostgreSQL 16 or later, and its planner checks run against the connected database only.",
 "category": "Software and DevOps",
 "tags": [
  "Software and DevOps"
 ],
 "lang": "go",
 "requirements": [
  "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"
 ],
 "risk": "none",
 "seen_in_the_wild": false,
 "mentioned_publicly": false,
 "risks": [],
 "best": false,
 "score": 0.8,
 "evidence": [],
 "url": "https://dedupedai.com/use-cases/pgrundev-pgbot/spot-unused-and-missing-indexes/",
 "md": "https://dedupedai.com/use-cases/pgrundev-pgbot/spot-unused-and-missing-indexes/index.md",
 "disclaimer": "Deduped lists open-source repositories that belong to other people. We do not own, maintain, audit, or vouch for any of them, and a repo appearing here is not an endorsement or a safety check. The use cases, steps, and prompts are written by AI and may be incomplete, outdated, or just wrong. Where a use case is marked \"Seen in the wild\", we link to public posts where someone described something similar, but we have not verified those posts and the use case itself is still our AI's own write-up. Use all of this at your own risk. Only run code, commands, or agents on systems and accounts you are authorized to use, and read the code and every command before you run it, especially anything that touches credentials, files, or the network. Nothing here is professional, security, legal, or financial advice. All trademarks and project names belong to their respective owners, and their use here does not imply affiliation. Content is provided as is, without warranties of any kind. Found a mistake, a safety problem, or something you want removed? Email hello@dedupedai.com and we will look at it promptly.",
 "api": "https://dedupedai.com/api/v1/usecases/pgrundev-pgbot--spot-unused-and-missing-indexes.json",
 "api_version": "v1"
}
