Kivi

没有什么远大理想,只是永远都不会满足而已


  • 首页

  • 关于

  • 标签

  • 归档

mongodb常用命令整理

发表于 2017-05-22 更新于 2017-07-02 分类于 mongodb 阅读次数:
本文字数: 1.5k 阅读时长 ≈ 1 分钟

慢查询相关

慢查询

1
2
3
4
5
6
7
db.currentOp().inprog.forEach(
function(op) {
if(op.secs_running > 5) printjson(op);
}
)

db.killOp(opid) // kill op

返回参数详解

wiredtiger相关

查看mongodb cache size(bytes)

1
db.runCommand( { serverStatus: 1 } ).wiredTiger.cache["bytes currently in the cache"]

查看mongodb内存占用(MB)

mongo shell

1
db.runCommand( { serverStatus: 1, workingSet: 1 } ).mem.resident

linux shell(最后一列是实际物理内存占用)

1
ps -e -o 'pid,comm,rsz'

查看系统缺页信息

1
ps -eo min_flt,maj_flt,pid,%cpu,%mem,pagein,args  --sort=min_flt | grep mongo

数据chunk相关

查看chunk大小

1
2
3
4
5
6
7
8
var ns = "test.test"
var key = {account:1}

db.getSiblingDB("config").chunks.find({ns : ns}).forEach(function(chunk) {
var ds = db.getSiblingDB(ns.split(".")[0]).runCommand({datasize:chunk.ns,keyPattern:key,min:chunk.min,max:chunk.max});
print("Chunk: "+chunk._id +" has a size of "+ds.size+", and includes "+ds.numObjects+" objects (took "+ds.millis+"ms)")
}
)

查询并切分大chunk

1
2
3
4
5
6
7
8
9
10
11
12
13

sh.stopBalancer()

use config
db.chunks.find({"ns": "test.user", jumbo: true})

sh.splitAt("db.collection", { account: "shardkey" })

sh.splitFind("db.collection", { account: "shardkey" })

sh.moveChunk("db.collection", { shardkey:"shardkey所在的块" }, "需要移动的目标分片ID")

sh.startBalancer()

Balancer

1
2
3
4
5
6
7
use config
db.settings.update(
{ _id: "balancer" },
{ $set: { activeWindow : { start: "23:00", stop: "6:00" } } },
{ upsert: true }

)

数据库迁移

js + shell

迁移脚本

# mongodb
mongodb固定大小表
mongos cursor 的使用
  • 文章目录
  • 站点概览
kivi

kivi

nodejs | server
58 日志
17 分类
32 标签
RSS
  1. 1. 慢查询相关
    1. 1.1. 慢查询
  2. 2. wiredtiger相关
    1. 2.1. 查看mongodb cache size(bytes)
    2. 2.2. 查看mongodb内存占用(MB)
      1. 2.2.1. mongo shell
      2. 2.2.2. linux shell(最后一列是实际物理内存占用)
      3. 2.2.3. 查看系统缺页信息
  3. 3. 数据chunk相关
    1. 3.1. 查看chunk大小
    2. 3.2. 查询并切分大chunk
  4. 4. Balancer
  5. 5. 数据库迁移
    1. 5.1. js + shell
© 2019 kivi | 173k | 2:37
由 Hexo 强力驱动 v3.9.0
|
主题 – NexT.Pisces v7.3.0
|