db-ops-sop
Skill360 starsChanged 7 months agoApache-2.0View on GitHub
Database operations runbook — backup, recovery, performance tuning, troubleshooting. Use for SQLite / MySQL / PostgreSQL ops questions, slow-query diagnosis, or outage response.
In this repositoryOne other file it gives its agents.
- code-reviewSkill
The file
Files
数据库运维 SOP
适用场景
当用户咨询数据库备份、恢复、性能优化、故障排查等运维相关问题时,参考本指南进行回答。
一、数据库备份
1.1 全量备份
# SQLite 备份(直接复制文件)
cp /path/to/database.db /path/to/backup/database_$(date +%Y%m%d).db
# MySQL 全量备份
mysqldump -u root -p --all-databases > full_backup_$(date +%Y%m%d).sql
# PostgreSQL 全量备份
pg_dump -U postgres -F c dbname > backup_$(date +%Y%m%d).dump1.2 增量备份
- MySQL: 使用 binlog 进行增量备份
- PostgreSQL: 使用 WAL 归档进行增量备份
- 建议每日全量 + 每小时增量
1.3 备份策略建议
| 频率 | 类型 | 保留时间 |
| 每日 | 全量备份 | 30 天 |
| 每小时 | 增量备份 | 7 天 |
| 每周 | 异地备份 | 90 天 |
二、数据库恢复
2.1 恢复步骤
- 停止应用服务
- 确认备份文件完整性
- 执行恢复命令
- 验证数据一致性
- 重启应用服务
2.2 恢复命令
# SQLite 恢复
cp /path/to/backup/database_20240101.db /path/to/database.db
# MySQL 恢复
mysql -u root -p < full_backup_20240101.sql
# PostgreSQL 恢复
pg_restore -U postgres -d dbname backup_20240101.dump三、性能优化
3.1 慢查询排查
- 开启慢查询日志
- 分析 TOP 10 慢查询
- 使用 EXPLAIN 分析执行计划
- 添加必要索引
- 优化 SQL 语句
3.2 常见优化手段
- 索引优化: 为高频查询字段添加索引,避免全表扫描
- 查询优化: 避免 SELECT *,减少子查询,使用 JOIN 替代
- 连接池: 使用连接池管理数据库连接,避免频繁创建/销毁
- 读写分离: 大流量场景下主库写、从库读
- 缓存: 热点数据使用 Redis 缓存
四、故障排查清单
- 检查数据库服务是否运行
- 检查磁盘空间是否充足
- 检查连接数是否达到上限
- 检查慢查询是否阻塞
- 检查主从同步状态
- 检查锁等待情况
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

