各库的定位入口
各库的定位入口
# MongoDB:开启慢查询分析器(100ms 以上记录)
mongosh --eval "db.setProfilingLevel(1, { slowms: 100 })"
mongosh --eval "db.system.profile.find().sort({ millis: -1 }).limit(5).pretty()"
# Elasticsearch:慢查询日志阈值(索引级)
curl -X PUT "localhost:9200/my-index/_settings" -H 'Content-Type: application/json' \
-d '{"index.search.slowlog.threshold.query.warn": "5s", "index.search.slowlog.threshold.fetch.warn": "2s"}'
# ClickHouse:查询日志
clickhouse-client -q "SELECT query_duration_ms, read_rows, query FROM system.query_log WHERE type = 'QueryFinish' ORDER BY query_duration_ms DESC LIMIT 5"
# Redis:慢命令与延迟诊断
redis-cli SLOWLOG GET 10
redis-cli --latency-history执行计划示例
执行计划示例
// MongoDB:看扫描文档数与返回数之比
db.orders.find({ status: "open", city: "hz" }).explain("executionStats")
// 关键字段:totalDocsExamined / nReturned
-- ClickHouse:看读取行数与执行计划
-- EXPLAIN indexes = 1 SELECT ... FROM events WHERE ts >= now() - INTERVAL 1 DAY;判断标准是扫描放大倍数:扫描远大于返回通常缺索引或索引选择不佳;扫描正常但耗时长则看排序、聚合与网络返回体积。