{
 "schema": "aiblocks-page/1",
 "id": "agency-engineering-database-optimizer",
 "type": "agent",
 "name": "Database performance analyst",
 "summary": "Get a ranked list of slow database queries, missing indexes and risky schema choices, with safe fixes you can test on a copy first.",
 "headline": "Database performance analyst",
 "subhead": "Paste your slow queries with their query plans, plus your tables and indexes. It finds what is slowing the database, ranks fixes by impact, and writes each change with a safe way to apply it and a way to undo it.",
 "job": {
  "id": "build-software",
  "name": "Build and ship software"
 },
 "level": "intermediate",
 "thinking": "high",
 "tested": true,
 "updated": "2026-11-03",
 "first_published": "2026-10-26",
 "inputs": [
  {
   "type": "question",
   "required": true,
   "label": "Question",
   "what": "the problem, decision or piece of work you want help with, and what a good outcome looks like"
  },
  {
   "type": "codebase",
   "required": false,
   "label": "Codebase",
   "what": "a project's code, in a folder or repo the AI can open"
  },
  {
   "type": "code_change",
   "required": false,
   "label": "Code change",
   "what": "a change to the code, with what it fixes and how it was checked"
  },
  {
   "type": "data_model",
   "required": false,
   "label": "Data model",
   "what": "a database design: the tables or collections, their fields and keys, and how they link"
  }
 ],
 "outputs": [
  {
   "type": "audit_report",
   "required": true,
   "label": "Audit report",
   "what": "findings with evidence, severity, missing inputs and next actions"
  },
  {
   "type": "plan",
   "required": true,
   "label": "Plan",
   "what": "a dated plan: what to do, in what order, with a decision rule for each step"
  }
 ],
 "you_give": [
  "Your database engine and version, such as PostgreSQL 15 or MySQL 8.",
  "The slow queries, with the output of EXPLAIN ANALYZE for each.",
  "Your table definitions and existing indexes.",
  "Rough row counts for the biggest tables.",
  "How the app calls the database, such as an ORM or raw SQL (optional).",
  "Which queries matter most to your users (optional)."
 ],
 "you_get": [
  "Findings ranked by impact, each tied to evidence in your query plan.",
  "Exact index and query changes, with the reason for each.",
  "Fixes for repeated one-per-row queries, shown as one combined query.",
  "A safe way to apply each change on a live database, and a way to undo it.",
  "A list of checks to run on a copy of your data, with the numbers to compare.",
  "Notes on connection pooling and slow-query monitoring."
 ],
 "use_when": [
  "A page or report is slow and you suspect the database.",
  "Your app makes one query per row in a loop, and the list page crawls.",
  "You are about to add an index or change a table on a live database and want it checked first.",
  "You are designing tables for a new feature and want indexes planned from the start."
 ],
 "skip_when": [
  "You have one slow query and want it rewritten. Use the Slow query fixer.",
  "You want queries written from plain words. Use the Plain-words SQL writer.",
  "Your concern is backups, failover or uptime. Use the Database recovery planner.",
  "You run GaussDB. Use the GaussDB query and schema reviewer.",
  "You plan to run changes on a live database with no copy to test on. Ask a database administrator."
 ],
 "output_sample": {
  "input": [
   "Your database engine and version",
   "Slow queries with the full EXPLAIN ANALYZE output",
   "Table definitions, existing indexes and rough row counts",
   "Which queries matter most to users (optional)"
  ],
  "prerequisites": [
   "An AI you can paste a long brief into, such as Claude, ChatGPT or Gemini",
   "A copy of your database to test on, because the agent proposes changes and runs none"
  ],
  "output": [
   {
    "name": "Setup and evidence used",
    "contains": "Your engine and version, the plans it read and any evidence still missing."
   },
   {
    "name": "Findings",
    "contains": "Problems ranked by impact, each with the line in the plan that shows it and the fix."
   },
   {
    "name": "Proposed changes",
    "contains": "The exact index or query change for each finding, with the reason and its cost."
   },
   {
    "name": "Apply and undo",
    "contains": "A safe way to apply each change on a live database and the step to undo it."
   },
   {
    "name": "Checks on a copy",
    "contains": "The queries to rerun, what to measure before and after and the rule for a pass."
   },
   {
    "name": "Connections and monitoring",
    "contains": "Pooling notes and slow-query logging, with what to watch after the change."
   }
  ]
 },
 "output_shape": "SETUP AND EVIDENCE USED\n  <engine and version> | <queries and plans supplied> | <missing evidence>\n\nFINDINGS (ranked by impact)\n  <rank> | <problem> | <evidence in the plan> | <fix>\n\nPROPOSED CHANGES\n  <index or query change> | <exact SQL or rewrite> | <why> | <cost, such as extra write work>\n\nAPPLY AND UNDO\n  <change> | <safe way to apply on a live database> | <undo step>\n\nCHECKS ON A COPY\n  <query> | <measure before> | <measure after> | <pass rule>\n\nCONNECTIONS AND MONITORING\n  <pooling note> | <slow-query logging> | <what to watch>\n\nOPEN QUESTIONS AND CHECKS STILL NEEDED\n  <item> | <how to settle it>",
 "how_to_use": [
  "Download the pack from this page and add it to your AI as a skill. Or paste SKILL.md into a new chat, then paste references/source-agent.md after it.",
  "Run EXPLAIN ANALYZE on each slow query and copy the whole output. For a query that writes data, run it in a transaction and roll back, or ask the agent for plain EXPLAIN steps.",
  "Paste the queries, plans, table definitions, indexes and row counts. Name your engine and version.",
  "Your AI asks once for anything missing. Without a plan it gives only general advice and says so.",
  "Try each fix on a copy of your database. Run EXPLAIN ANALYZE again and compare with the first output.",
  "Apply changes to the live database yourself, one at a time, in a quiet period, using the undo step if needed."
 ],
 "checks": [
  "The result addresses your actual task and cites the evidence used.",
  "Examples, role-play experience and targets are kept separate from verified results.",
  "Claims of tests, memory, tool access or completed actions match what actually happened."
 ],
 "next": [
  {
   "name": "Database schema designer",
   "url": "https://useaiblocks.com/skills/database-schema-designer",
   "why": "Build it"
  },
  {
   "name": "Oracle to Postgres migration test planner",
   "url": "https://useaiblocks.com/skills/copilot-planning-oracle-to-postgres-migration-integration-testing",
   "why": "Build it"
  },
  {
   "name": "API spec writer",
   "url": "https://useaiblocks.com/skills/api-spec-writer",
   "why": "Build it"
  }
 ],
 "source": {
  "by": "Michael Sitarzewski and Agency Agents contributors",
  "repo": "msitarzewski/agency-agents",
  "url": "https://github.com/msitarzewski/agency-agents/blob/b37b5bb33b78f2c1d6567d98e25ca818e3259219/engineering/engineering-database-optimizer.md",
  "licence": "MIT",
  "original_name": "Database Optimizer",
  "commit": "b37b5bb33b78f2c1d6567d98e25ca818e3259219"
 },
 "credits": [
  {
   "title": "Database Optimizer",
   "by": "Michael Sitarzewski and Agency Agents contributors",
   "url": "https://github.com/msitarzewski/agency-agents/blob/b37b5bb33b78f2c1d6567d98e25ca818e3259219/engineering/engineering-database-optimizer.md",
   "used": "Original agent profile, preserved in references/source-agent.md; AI Blocks adds setup and review instructions."
  }
 ],
 "files": [
  "LICENSE",
  "references/source-agent.md",
  "SETUP.md",
  "source.json"
 ],
 "links": {
  "page": "https://useaiblocks.com/agents/agency-engineering-database-optimizer",
  "markdown": "https://useaiblocks.com/agents/agency-engineering-database-optimizer.md",
  "json": "https://useaiblocks.com/agents/agency-engineering-database-optimizer.json",
  "instructions": "https://useaiblocks.com/skills/agency-engineering-database-optimizer/SKILL.md",
  "download": "https://useaiblocks.com/skills/agency-engineering-database-optimizer.zip",
  "api_item": "https://useaiblocks.com/api/v1/items/agency-engineering-database-optimizer",
  "api_document": "https://useaiblocks.com/api/v1/documents/agent/agency-engineering-database-optimizer",
  "mcp": "https://useaiblocks.com/mcp"
 }
}
