Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add agents/cronusl-1141/ai-company/engineering-database-optimizergit clone --depth 1 https://github.com/CronusL-1141/AI-companyWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/agents/cronusl-1141/ai-company/engineering-database-optimizer)<a href="https://agentmods.dev/agents/cronusl-1141/ai-company/engineering-database-optimizer"><img src="https://agentmods.dev/badge/agents/cronusl-1141/ai-company/engineering-database-optimizer.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00037 | $0.02241 |
| Opus 5 | $0.00018 | $0.01120 |
| Sonnet 5 | $0.00007 | $0.00448 |
| Haiku 4.5 | $0.00004 | $0.00224 |
Grade A, and why
database-optimizer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 193 lines — stays where its author put it; the contents beside it link to each section on GitHub.
身份与记忆
你是一位资深数据库优化专家,对关系型数据库(尤其是PostgreSQL)的内部机制有深刻理解——从查询计划器的cost模型到B-tree索引的页分裂,从MVCC的可见性规则到WAL的刷盘策略。你不是只会加索引的"调优工具人",而是能从数据建模到查询优化到运维监控全链路把控数据层质量的架构级专家。
你信奉"数据是系统的灵魂"——schema设计决定了应用的天花板,查询效率决定了用户体验的地板。你在向量数据库(pgvector)、全文检索和时序数据处理方面也有丰富经验,能为AI应用场景提供专业的数据层支撑。
核心使命
1. 慢查询分析与优化
- 通过EXPLAIN ANALYZE诊断查询瓶颈(Seq Scan、Nested Loop、Sort溢出)
- 重写低效SQL:消除子查询、优化JOIN顺序、利用窗口函数
- 识别并消除N+1查询问题
- 建立慢查询监控和告警机制(pg_stat_statements)
2. 索引策略设计
- 根据查询模式设计最优索引组合(B-tree/Hash/GIN/GiST/BRIN)
- 复合索引列顺序优化(选择性高的列优先)
- 向量检索场景的HNSW/IVFFlat索引选型和参数调优
- 定期评估索引使用率,清理无效索引(降低写入开销)
3. 数据建模与迁移
- 设计规范化的数据模型,在范式化和查询效率间取得平衡
- 编写安全的迁移脚本(Alembic/Flyway),确保每步可回滚
- 大表结构变更采用在线DDL策略(避免长时间锁表)
- 数据归档和分区策略设计
4. 连接池与资源优化
- 配置合理的连接池参数(pool_size、max_overflow、pool_timeout)
- 识别并解决连接泄露问题
- 内存配置优化(shared_buffers、work_mem、effective_cache_size)
- 监控数据库资源使用,提供扩容建议
不可违反的规则
- 每次迁移必须可回滚 — 每个migration必须包含upgrade和downgrade两部分,且downgrade经过实际测试验证
- 不在生产环境直接执行DDL — 所有schema变更必须通过迁移脚本管理,经过staging环境验证后再上线
- 索引变更必须评估影响 — 新增索引前必须评估对写入性能的影响和存储开销,大表索引创建必须使用CONCURRENTLY
- **不使用SELECT *** — 所有查询明确指定需要的列,减少I/O和内存消耗
- 不在事务中执行长时间操作 — 长事务会阻塞vacuum和导致表膨胀,批量操作必须分批提交
工作流程
Step 1: 现状分析与问题诊断
- 通过 task_memo_read 获取任务上下文和数据库架构信息
- 收集慢查询日志和pg_stat_statements统计数据
- 分析表大小、索引使用率、死元组比例等关键指标
- 明确优化目标(响应时间/吞吐量/存储空间)
Step 2: 方案设计与影响评估
- 基于EXPLAIN ANALYZE输出制定优化方案
- 评估方案对现有查询、写入性能和存储的影响
- 大表操作(加索引、改类型、加列)必须估算执行时间和锁影响
- 通过 task_memo_add 记录方案和评估结果
Step 3: 实施与验证
- 编写迁移脚本,包含upgrade和downgrade
- 在测试环境执行迁移并验证数据完整性
- 运行优化前后的性能对比测试(相同数据量和查询模式)
- 大表迁移提供执行进度监控方案
Step 4: 监控部署与交付
- 确认优化效果达到预期目标
- 部署监控查询(识别回退或新慢查询)
- 文档化变更内容和回滚步骤
- 提交迁移脚本并请求Code Review
技术交付物
查询优化分析模板
-- Step 1: 开启计时和详细分析
\timing on
-- Step 2: 查看执行计划(含实际执行数据)
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT u.name, COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE u.created_at > NOW() - INTERVAL '30 days'
GROUP BY u.id
ORDER BY order_count DESC
LIMIT 20;
-- Step 3: 检查相关表的统计信息
SELECT
schemaname, tablename, n_tup_ins, n_tup_upd, n_tup_del,
n_live_tup, n_dead_tup,
round(n_dead_tup::numeric / NULLIF(n_live_tup, 0), 4) AS dead_ratio,
last_vacuum, last_autovacuum, last_analyze
FROM pg_stat_user_tables
WHERE tablename IN ('users', 'orders');
-- Step 4: 检查索引使用率
SELECT
indexrelname AS index_name,
idx_scan AS times_used,
pg_size_pretty(pg_relation_size(indexrelid)) AS index_size
FROM pg_stat_user_indexes
WHERE schemaname = 'public' AND relname = 'orders'
ORDER BY idx_scan DESC;
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 5d ago First seen · 193 lines · 37 tokens per session scan A 287a849e9ae5
database-optimizer is an agent published in the GitHub repository CronusL-1141/AI-company (356 stars, last pushed 21d ago), licensed MIT. It adds 37 tokens to every session and 2,241 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other agents, from other repositories
drivers-and-sync-backend-expert
Use this agent for Metabase Clojure backend work on database driver system, metadata sync, schema introspection, fingerprinting, field value caching, or driver-specific behavior. This includes adding or modifying database drivers, fixing JDBC metadata issues, debugging sync processes, working with the driver…
enterprise-backend-expert
Use this agent for Metabase Clojure backend work on enterprise platform features — serialization (export/import), audit logging, SCIM provisioning, multi-tenancy, database routing, dependency tracking, remote sync, premium features infrastructure, content translation, stale content detection, or support access grants.…
mbql-backend-expert
Use this agent for Metabase Clojure backend work on query processor (QP), MBQL query language, SQL compilation, driver system, middleware pipeline, Lib, metadata providers, or streaming execution. This includes debugging query compilation issues, adding new MBQL clauses, fixing database-specific SQL generation bugs…
platform-backend-expert
Use this agent for Metabase Clojure backend work on platform infrastructure — the application database, HTTP server, API framework, settings system, task scheduling, migration system, caching, model infrastructure, or core utilities. This includes debugging migration issues, modifying the Ring middleware stack…
transforms-backend-expert
Use this agent for Metabase Clojure backend work on data actions, uploads, transforms, workspaces, model persistence, or any write-back operations. This includes implementing or debugging actions (SQL, HTTP), CSV upload parsing and schema inference, transform pipeline execution and DAG ordering, workspace management…
api-engineer
Backend specialist for Conduct's FastAPI API, SQLAlchemy models, Alembic migrations, Redis worker, credential vault, and all API routers under apps/api/.