之前的几篇文章大致说了副本集的搭建、副本集的管理,现在说下MongoDB数据库的管理。数据库管理包括:备份、还原、导入、导出、服务器管理等。

查看服务器状态,查看命令行参数。db.serverStatus()、db.serverCmdLineOpts()

  1. zjy:PRIMARY> db.serverStatus()
  2. {
  3. "host" : "zhoujinyi",
  4. "version" : "3.0.4",
  5. "process" : "mongod",
  6. "pid" : NumberLong(),
  7. "uptime" : ,
  8. "uptimeMillis" : NumberLong(),
  9. "uptimeEstimate" : ,
  10. "localTime" : ISODate("2015-07-01T14:06:12.922Z"),
  11. "asserts" : {
  12. "regular" : ,
  13. "warning" : ,
  14. "msg" : ,
  15. "user" : ,
  16. "rollovers" :
  17. },
  18. "backgroundFlushing" : {
  19. "flushes" : ,
  20. "total_ms" : ,
  21. "average_ms" : 4.180722891566265,
  22. "last_ms" : ,
  23. "last_finished" : ISODate("2015-07-01T14:05:47.284Z")
  24. },
  25. "connections" : {
  26. "current" : ,
  27. "available" : ,
  28. "totalCreated" : NumberLong()
  29. },
  30. ...
  31. ...
  32. "network" : {
  33. "bytesIn" : ,
  34. "bytesOut" : ,
  35. "numRequests" :
  36. },
  37. "opcounters" : {
  38. "insert" : ,
  39. "query" : ,
  40. "update" : ,
  41. "delete" : ,
  42. "getmore" : ,
  43. "command" :
  44. },
  45. "opcountersRepl" : {
  46. "insert" : ,
  47. "query" : ,
  48. "update" : ,
  49. "delete" : ,
  50. "getmore" : ,
  51. "command" :
  52. },
  53. "repl" : {
  54. "setName" : "zjy",
  55. "setVersion" : ,
  56. "ismaster" : true,
  57. "secondary" : false,
  58. "hosts" : [
  59. "127.0.0.1:27017",
  60. "127.0.0.1:27018",
  61. "127.0.0.1:27019"
  62. ],
  63. "primary" : "127.0.0.1:27017",
  64. "me" : "127.0.0.1:27017",
  65. "electionId" : ObjectId("5592be327c7062c30c3bff24"),
  66. "rbid" :
  67. },
  68. "storageEngine" : {
  69. "name" : "mmapv1"
  70. },
  71. "writeBacksQueued" : false,
  72. "mem" : {
  73. "bits" : ,
  74. "resident" : ,
  75. "virtual" : ,
  76. "supported" : true,
  77. "mapped" : ,
  78. "mappedWithJournal" :
  79. },
  80. ...
  81. ...
  82. "ok" :
  83. }

通过上面看到MongoDB的版本、后台刷写情况、副本集情况、操作数量情况、进出网络情况、连接数情况和内存情况。

其中内存相关字段的含义是:单位是M
mapped:映射到内存的数据大小
visze:占用的虚拟内存大小
res:实际使用的内存大小
在上面的结果中,virtual是mapped的两倍,而mapped等于数据文件的大小,所以说vsize是数据文件的两倍,之所以会这样,是因为本例中,MongoDB开启了journal,需要在内存里多映射一次数据文件,如果关闭journal,则virtual和mapped大致相当。

也可以通过mongostat来查看:

  1. root@zhoujinyi:~# mongostat
  2. insert query update delete getmore command flushes mapped vsize res faults qr|qw ar|aw netIn netOut conn set repl time
  3. * * * * | .5G .5G 133.0M | | 262b 11k zjy PRI ::
  4. * * * * | .5G .5G 133.0M | | 215b 11k zjy PRI ::
  5. * * * * | .5G .5G 133.0M | | 215b 11k zjy PRI ::

faults:查询从磁盘读取数据,标志服务器未达到最佳,所需的数据并未完全保存找内存中

qr/qw:队列等待的数目。

ar/aw:活动客户端的数目。

conn:打开的连接数。

flushes:数据刷写到磁盘的数目。

vsize:使用虚拟内存大小。

mapped:隐射的内存大小,约等于数据目录大小。

查看命令行参数:

  1. zjy:PRIMARY> db.serverCmdLineOpts()
  2. {
  3. "argv" : [
  4. "mongod",
  5. "-f",
  6. "/etc/mongodb/mongodb_27017.conf"
  7. ],
  8. "parsed" : {
  9. "config" : "/etc/mongodb/mongodb_27017.conf",
  10. "diaglog" : ,
  11. "net" : {
  12. "maxIncomingConnections" : ,
  13. "port" : ,
  14. "unixDomainSocket" : {
  15. "pathPrefix" : "/tmp"
  16. }
  17. },
  18. "processManagement" : {
  19. "fork" : true,
  20. "pidFilePath" : "/var/run/mongo_27017.pid"
  21. },
  22. "replication" : {
  23. "replSet" : "zjy/127.0.0.1:27018"
  24. },
  25. "storage" : {
  26. "dbPath" : "/usr/local/mongo1/",
  27. "mmapv1" : {
  28. "nsSize" :
  29. }
  30. },
  31. "systemLog" : {
  32. "destination" : "file",
  33. "logAppend" : true,
  34. "path" : "/var/log/mongodb/mongodb1.log"
  35. }
  36. },
  37. "ok" :
  38. }

查看数据库/表状态,db.stats()/db.coll.stats() |  M为单位:db.stats(1024*1024)/db.coll.stats(1024*1024)

  1. zjy:PRIMARY> db.stats()
  2. {
  3. "db" : "test",
  4. "collections" : ,
  5. "objects" : ,
  6. "avgObjSize" : 417.1111111111111,
  7. "dataSize" : , #数据文件大小。
  8. "storageSize" : , #存储空间大小:datasize+集合两端预留的未使用空间。
  9. "numExtents" : ,
  10. "indexes" : ,
  11. "indexSize" : ,
  12. "fileSize" : , #物理文件大小:包括预分配
  13. "nsSizeMB" : ,
  14. "extentFreeList" : {
  15. "num" : ,
  16. "totalSize" :
  17. },
  18. "dataFileVersion" : {
  19. "major" : ,
  20. "minor" :
  21. },
  22. "ok" :
  23. }

通过上面看到数据库的名称,集合(表)数量,索引数量、大小,数据文件大小,存储空间大小和物理文件大小。

三:查看当前Query执行情况:db.currentOP():

  1. zjy:PRIMARY> db.currentOP()
  2. {
  3. "inprog" : [
  4. {
  5. "desc" : "conn4732", #可与日志信息联系起来
  6. "threadId" : "0x33903c0",
  7. "connectionId" : , #连接ID
  8. "opid" : , #操作标识,可以用这个ID来终止该操作:db.killOP(opid)
  9. "active" : true, #表示线程是否在运行
  10. "secs_running" : , #执行的时间
  11. "microsecs_running" : NumberLong(),
  12. "op" : "getmore", #操作类型:插入、删除、更新、查询
  13. "ns" : "local.oplog.rs", #操作的集合
  14. "query" : {
  15. "ts" : {
  16. "$gte" : Timestamp(, )
  17. }
  18. },
  19. "client" : "127.0.0.1:52101",
  20. "numYields" : , #表示该操作交出锁,而使其他操作得以运行。
  21. "locks" : { #锁信息
  22.  
  23. },
  24. "waitingForLock" : false,
  25. "lockStats" : {
  26. "Global" : {
  27. "acquireCount" : {
  28. "r" : NumberLong()
  29. }
  30. },
  31. "MMAPV1Journal" : {
  32. "acquireCount" : {
  33. "r" : NumberLong()
  34. }
  35. },
  36. "Database" : {
  37. "acquireCount" : {
  38. "r" : NumberLong()
  39. }
  40. },
  41. "oplog" : {
  42. "acquireCount" : {
  43. "R" : NumberLong()
  44. }
  45. }
  46. }
  47. }
    ...
    ...

通过上面看到当前执行的进程,类似MySQL的show processlist。可以添加过滤条件:

  1. zjy:PRIMARY> db.currentOP({"ns":"test"})

监控MongoDB各个状态mongotop、mongostat

  1. root@zhoujinyi:~# mongotop #查看那个几个最繁忙
  2. ns total read write --01T11::-:
  3. abc 0ms 0ms 0ms
  4. abc.AOE 0ms 0ms 0ms
  5. abc.aoe 0ms 0ms 0ms
  6. abc.system.indexes 0ms 0ms 0ms
  7. abc.system.js 0ms 0ms 0ms
  8. abc.system.namespaces 0ms 0ms 0ms
  9. abc.test 0ms 0ms 0ms
  10. admin.system.indexes 0ms 0ms 0ms
  11. admin.system.namespaces 0ms 0ms 0ms
  12. admin.system.roles
  1. root@zhoujinyi:~# mongostat
  2. insert query update delete getmore command flushes mapped vsize res faults qr|qw ar|aw netIn netOut conn set repl time
  3. * * * * | .5G .5G 133.0M | | 215b 11k zjy PRI ::
  4. * * * * | .5G .5G 133.0M | | 215b 11k zjy PRI ::
  5. * * * * | .5G .5G 133.0M | | 215b 11k zjy PRI ::
  6. * * * * | .5G .5G 133.0M | | 262b 11k zjy PRI ::

上面insert、query、update、delete、getmore、command 每种对应操作的发生次数。其中faults表示访问失败数,数据从内存交换出去,放到swap。值越小越好,最好不要大于100。

  1. flushes:表示刷写到磁盘的次数。
  2. mapped:表示映射到内存的数量,约等于数据目录大小。
  3. vsize:表示正在使用的虚拟内存大小,通常为数据目录的2倍。(一次用于映射,一次用于日志系统)
  4. res:表示正在使用的内存大小。
  5. qr|qw:表示读写操作队列大小,即有多少读写操作被阻塞,等待进行处理。
  6. ar|aw:表示活动客户端的数量,即正在进行读写操作的客户端。
  7. netId:表示通过网络传输进来的字节数。
  8. netout表示通过网络传输出的字节数。
  9. Conn:表示服务器打开的连接数。
  10. time:表示统计的时间。

其中mongostat加上--discover 可以查看到副本集和分片集群的所有成员状态

日志分割,db.adminCommand({"logRotate":1})

  1. zjy:PRIMARY> db.adminCommand({"logRotate":})
  2. { "ok" : }

类似MySQL的flush log。

数据库备份、还原,mongodump、mongorestore、mongoimport、mongoexport

mongodump --help   :参数

  1. Export MongoDB data to BSON files.
  2.  
  3. Options:
  4. --help produce help message
  5. -v [ --verbose ] be more verbose (include multiple times
  6. for more verbosity e.g. -vvvvv)
  7. --quiet silence all non error diagnostic
  8. messages
  9. --version print the program's version and exit
  10. -h [ --host ] arg mongo host to connect to ( <set
  11. name>/s1,s2 for sets)
  12. --port arg server port. Can also use --host
  13. hostname:port
  14. --ipv6 enable IPv6 support (disabled by
  15. default)
  16. -u [ --username ] arg username
  17. -p [ --password ] arg password
  18. --authenticationDatabase arg user source (defaults to dbname)
  19. --authenticationMechanism arg (=MONGODB-CR)
  20. authentication mechanism
  21. --gssapiServiceName arg (=mongodb) Service name to use when authenticating
  22. using GSSAPI/Kerberos
  23. --gssapiHostName arg Remote host name to use for purpose of
  24. GSSAPI/Kerberos authentication
  25. --dbpath arg directly access mongod database files
  26. in the given path, instead of
  27. connecting to a mongod server - needs
  28. to lock the data directory, so cannot
  29. be used if a mongod is currently
  30. accessing the same path
  31. --directoryperdb each db is in a separate directory
  32. (relevant only if dbpath specified)
  33. --journal enable journaling (relevant only if
  34. dbpath specified)
  35. -d [ --db ] arg database to use
  36. -c [ --collection ] arg collection to use (some commands)
  37. -o [ --out ] arg (=dump) output directory or "-" for stdout
  38. -q [ --query ] arg json query
  39. --oplog Use oplog for point-in-time
  40. snapshotting
  41. --repair try to recover a crashed database
  42. --forceTableScan force a table scan (do not use
  43. $snapshot)
  44. --dumpDbUsersAndRoles Dump user and role definitions for the
  45. given database

各种备份方式:

  1. 无账号、密码
  2. mongodump -o backup #备份所有数据库到backup目录下,每个数据库一个文件,除local数据库外。
  3.  
  4. mongodump -d abc -o backup #备份abc数据库到backup目录下。
  5.  
  6. mongodump -d abc -c ddd -o backup #备份abc数据库下的ddd集合。
  7.  
  8. #有账号、密码
  9. mongodump -udba -pdba -d abc -c ddd -o backup #备份abc数据库下的ddd集合。
  10. mongodump --host=127.0.0.1 --port= -udba -p --db=abc --collection=ddd -o backup

这里需要注意的是:在认证备份中,比如在abc数据库中,需要其有dba这个账号才可以执行备份,要是abc数据库里没有账号,那么需要在admin上认证,再执行需要加:authenticationDatabase 参数:指定保存用户凭证的数据库,没有指定则去-d指定的数据库认证。最好还是设置专本备份的账号。

  1. mongodump -udba -pdba -d abc --authenticationDatabase admin -o backup #在admin数据库下认证之后再去备份abc数据库。

mongorestore --help :参数

  1. Import BSON files into MongoDB.
  2.  
  3. usage: mongorestore [options] [directory or filename to restore from]
  4. Options:
  5. --help produce help message
  6. -v [ --verbose ] be more verbose (include multiple times
  7. for more verbosity e.g. -vvvvv)
  8. --quiet silence all non error diagnostic
  9. messages
  10. --version print the program's version and exit
  11. -h [ --host ] arg mongo host to connect to ( <set
  12. name>/s1,s2 for sets)
  13. --port arg server port. Can also use --host
  14. hostname:port
  15. --ipv6 enable IPv6 support (disabled by
  16. default)
  17. -u [ --username ] arg username
  18. -p [ --password ] arg password
  19. --authenticationDatabase arg user source (defaults to dbname)
  20. --authenticationMechanism arg (=MONGODB-CR)
  21. authentication mechanism
  22. --gssapiServiceName arg (=mongodb) Service name to use when authenticating
  23. using GSSAPI/Kerberos
  24. --gssapiHostName arg Remote host name to use for purpose of
  25. GSSAPI/Kerberos authentication
  26. --dbpath arg directly access mongod database files
  27. in the given path, instead of
  28. connecting to a mongod server - needs
  29. to lock the data directory, so cannot
  30. be used if a mongod is currently
  31. accessing the same path
  32. --directoryperdb each db is in a separate directory
  33. (relevant only if dbpath specified)
  34. --journal enable journaling (relevant only if
  35. dbpath specified)
  36. -d [ --db ] arg database to use
  37. -c [ --collection ] arg collection to use (some commands)
  38. --objcheck validate object before inserting
  39. (default)
  40. --noobjcheck don't validate object before inserting
  41. --filter arg filter to apply before inserting
  42. --drop drop each collection before import
  43. --oplogReplay replay oplog for point-in-time restore
  44. --oplogLimit arg include oplog entries before the
  45. provided Timestamp (seconds[:ordinal])
  46. during the oplog replay; the ordinal
  47. value is optional
  48. --keepIndexVersion don't upgrade indexes to newest version
  49. --noOptionsRestore don't restore collection options
  50. --noIndexRestore don't restore indexes
  51. --restoreDbUsersAndRoles Restore user and role definitions for
  52. the given database
  53. --w arg (=) minimum number of replicas per write

各种还原方式:

  1. mongorestore -udba -pdba -d abc backup/abc #还原abc数据库。
  2.  
  3. mongorestore -udba -pdba -d abc --drop backup/abc #还原之前先删除原来数据库(集合)。
  4.  
  5. mongorestore -udba -pdba -d abc -c ddd --drop backup/abc/ddd.bson #还原abc库中的ddd集合。
  6.  
  7. mongorestore --host=127.0.0.1 --port= -udba -pdba -d abc -c test --drop backup/abc/test.bson #还原abc库中的test集合。
  8.  
  9. mongorestore --host=127.0.0.1 --port= -udba -pdba -d abc -c ooo --drop backup/abc/test.bson #还原abc库中的test集合到ooo集合。

mongoexport --help :参数

  1. Export MongoDB data to CSV, TSV or JSON files.
  2.  
  3. Options:
  4. --help produce help message
  5. -v [ --verbose ] be more verbose (include multiple times
  6. for more verbosity e.g. -vvvvv)
  7. --quiet silence all non error diagnostic
  8. messages
  9. --version print the program's version and exit
  10. -h [ --host ] arg mongo host to connect to ( <set
  11. name>/s1,s2 for sets)
  12. --port arg server port. Can also use --host
  13. hostname:port
  14. --ipv6 enable IPv6 support (disabled by
  15. default)
  16. -u [ --username ] arg username
  17. -p [ --password ] arg password
  18. --authenticationDatabase arg user source (defaults to dbname)
  19. --authenticationMechanism arg (=MONGODB-CR)
  20. authentication mechanism
  21. --gssapiServiceName arg (=mongodb) Service name to use when authenticating
  22. using GSSAPI/Kerberos
  23. --gssapiHostName arg Remote host name to use for purpose of
  24. GSSAPI/Kerberos authentication
  25. --dbpath arg directly access mongod database files
  26. in the given path, instead of
  27. connecting to a mongod server - needs
  28. to lock the data directory, so cannot
  29. be used if a mongod is currently
  30. accessing the same path
  31. --directoryperdb each db is in a separate directory
  32. (relevant only if dbpath specified)
  33. --journal enable journaling (relevant only if
  34. dbpath specified)
  35. -d [ --db ] arg database to use
  36. -c [ --collection ] arg collection to use (some commands)
  37. -f [ --fields ] arg comma separated list of field names
  38. e.g. -f name,age
  39. --fieldFile arg file with field names - per line
  40. -q [ --query ] arg query filter, as a JSON string, e.g.,
  41. '{x:{$gt:1}}'
  42. --csv export to csv instead of json
  43. -o [ --out ] arg output file; if not specified, stdout
  44. is used
  45. --jsonArray output to a json array rather than one
  46. object per line
  47. -k [ --slaveOk ] arg (=) use secondaries for export if
  48. available, default true
  49. --forceTableScan force a table scan (do not use
  50. $snapshot)
  51. --skip arg (=) documents to skip, default
  52. --limit arg (=) limit the numbers of documents
  53. returned, default all
  54. --sort arg sort order, as a JSON string, e.g.,
  55. '{x:1}'
  1. mongoexport -udba -pdba -dabc -cddd --authenticationDatabase admin -o backup/ddd.txt #导出txt文本
  2.  
  3. mongoexport -udba -pdba -dabc -cddd -f sno,sname --authenticationDatabase admin -o backup/ddd.txt #指定字段导出txt文本
  4.  
  5. mongoexport -udba -pdba -dabc -cddd -f sno,sname --csv --authenticationDatabase admin -o backup/ddd.csv #导出成csv格式的需要指定字段-f

  6. mongoexport -udba -pdba -dabc -cddd -q '{"sno":{"$gte":5}}' -f sno,sname --csv --authenticationDatabase admin -o backup/ddd.csv #按照-q里的条件导出

mongoimport --help :参数

  1. Import CSV, TSV or JSON data into MongoDB.
  2.  
  3. When importing JSON documents, each document must be a separate line of the input file.
  4.  
  5. Example:
  6. mongoimport --host myhost --db my_cms --collection docs < mydocfile.json
  7.  
  8. Options:
  9. --help produce help message
  10. -v [ --verbose ] be more verbose (include multiple times
  11. for more verbosity e.g. -vvvvv)
  12. --quiet silence all non error diagnostic
  13. messages
  14. --version print the program's version and exit
  15. -h [ --host ] arg mongo host to connect to ( <set
  16. name>/s1,s2 for sets)
  17. --port arg server port. Can also use --host
  18. hostname:port
  19. --ipv6 enable IPv6 support (disabled by
  20. default)
  21. -u [ --username ] arg username
  22. -p [ --password ] arg password
  23. --authenticationDatabase arg user source (defaults to dbname)
  24. --authenticationMechanism arg (=MONGODB-CR)
  25. authentication mechanism
  26. --gssapiServiceName arg (=mongodb) Service name to use when authenticating
  27. using GSSAPI/Kerberos
  28. --gssapiHostName arg Remote host name to use for purpose of
  29. GSSAPI/Kerberos authentication
  30. --dbpath arg directly access mongod database files
  31. in the given path, instead of
  32. connecting to a mongod server - needs
  33. to lock the data directory, so cannot
  34. be used if a mongod is currently
  35. accessing the same path
  36. --directoryperdb each db is in a separate directory
  37. (relevant only if dbpath specified)
  38. --journal enable journaling (relevant only if
  39. dbpath specified)
  40. -d [ --db ] arg database to use
  41. -c [ --collection ] arg collection to use (some commands)
  42. -f [ --fields ] arg comma separated list of field names
  43. e.g. -f name,age
  44. --fieldFile arg file with field names - per line
  45. --ignoreBlanks if given, empty fields in csv and tsv
  46. will be ignored
  47. --type arg type of file to import. default: json
  48. (json,csv,tsv)
  49. --file arg file to import from; if not specified
  50. stdin is used
  51. --drop drop collection first
  52. --headerline first line in input file is a header
  53. (CSV and TSV only)
  54. --upsert insert or update objects that already
  55. exist
  56. --upsertFields arg comma-separated fields for the query
  57. part of the upsert. You should make
  58. sure this is indexed
  59. --stopOnError stop importing at first error rather
  60. than continuing
  61. --jsonArray load a json array, not one item per
  62. line. Currently limited to 16MB.
  1. mongoimport -udba -pdba -dabc -ciii --authenticationDatabase admin < backup/ddd.txt #导入到iii集合
  2.  
  3. mongoimport -udba -pdba -dabc -ceee --type=csv --headerline --authenticationDatabase admin < backup/ddd.csv #csv导入,需要指定headerline
  4.  
  5. mongoimport -udba -pdba -dabc -ceee --type=csv --headerline --ignoreBlanks --drop --authenticationDatabase admin < backup/ddd.csv #不导入空字段,指定ignoreBlanks。

压缩数据文件compact

  1. zjy:PRIMARY> db.runCommand({compact:"cdt1"}) #整理并重组数据文件中指定集合的数据结构,不会释放磁盘空间。
  2. { "ok" : }

八:修复索引、验证集合,reindex,validate

  1. zjy:PRIMARY> db.cdt1.reIndex() #修复索引
  2. {
  3. "nIndexesWas" : ,
  4. "nIndexes" : ,
  5. "indexes" : [
  6. {
  7. "key" : {
  8. "_id" :
  9. },
  10. "name" : "_id_",
  11. "ns" : "cde.cdt1"
  12. },
  13. {
  14. "unique" : true,
  15. "key" : {
  16. "b" : ,
  17. "date" :
  18. },
  19. "name" : "b_1_date_1",
  20. "ns" : "cde.cdt1"
  21. }
  22. ],
  23. "ok" :
  24. }
  1. zjy:PRIMARY> db.abc.validate() #验证集合是否有问题,验证集合内容
  2. {
  3. "ns" : "test.abc",
  4. "datasize" : ,
  5. "nrecords" : ,
  6. "lastExtentSize" : ,
  7. "firstExtent" : "0:5000 ns:test.abc",
  8. "lastExtent" : "0:5000 ns:test.abc",
  9. "extentCount" : ,
  10. "firstExtentDetails" : {
  11. "loc" : "0:5000",
  12. "xnext" : "null",
  13. "xprev" : "null",
  14. "nsdiag" : "test.abc",
  15. "size" : ,
  16. "firstRecord" : "0:50b0",
  17. "lastRecord" : "0:5330"
  18. },
  19. "deletedCount" : , #删除的文档数量
  20. "deletedSize" : , #删除的文档大小
  21. "nIndexes" : ,
  22. "keysPerIndex" : {
  23. "test.abc.$_id_" :
  24. },
  25. "valid" : true,
  26. "errors" : [ ],
  27. "warning" : "Some checks omitted for speed. use {full:true} option to do more thorough scan.", #使用true,可以看详细信息:db.abc.validate(true)
  28. "ok" :
  29. }
  1.  

九:日志Journal相关,通过db.serverstatus()查看,相关介绍:文章1文章2

  1. zjy:PRIMARY> db.serverStatus().dur
  2. {
  3. "commits" : , #在journalCommitInterval时间内提交的操作数
  4. "journaledMB" : 0.032768, #在journalCommitInterval时间内写到journal文件中的数据量
  5. "writeToDataFilesMB" : 0.00509, #在journalCommitInterval时间内从journal刷新到磁盘的数据量
  6. "compression" : 6.017998163452709,#表示客户端提交写入到journal的数据的压缩比率,注意,写入到journal的数据并不是全部的数据。( journaled_size_of_data / uncompressed_size_of_data )
  7. "commitsInWriteLock" : , #在有写锁的情况下提交的数量,这表示写的压力很大
  8. "earlyCommits" : , #表示在journalCommitInterval之前的时间,mongod请求提交的次数。用这个参数确定journalCommitInterval是不是设置的过长。 
  9. "timeMs" : {
  10. "dt" : ,
  11. "prepLogBuffer" : , #从privateView映射到Logbuffer的时间
  12. "writeToJournal" : , #从logbuffer刷新到journalfile 的时间
  13. "writeToDataFiles" : , #从journalbuffer映射到MMF,然后从MMF刷新到磁盘的时间,文件系统和磁盘会影响写入性能
  14. "remapPrivateView" : 0 #重新映射数据到PrivateView的时间,越小性能越好
  15. },
  16. "journalCommitIntervalMs" :
  17. }

十:刷写并锁 db.fsyncLock(),db.fsyncUnlock()

  1. drug:PRIMARY>db.fsyncLock() #刷写到磁盘,并锁住数据库。此时数据库只能读,不能写。保证了数据的一致性,在此可以进行复制文件或则快照备份
  2. {
  3. "info" : "now locked against writes, use db.fsyncUnlock() to unlock",
  4. "seeAlso" : "http://dochub.mongodb.org/core/fsynccommand",
  5. "ok" :
  6. }
  7. drug:PRIMARY> db.currentOP() #查看锁情况
  8. {
  9. "inprog" : [
  10. ...
  11. ...
  12. ],
  13. "fsyncLock" : true,
  14. "info" : "use db.fsyncUnlock() to terminate the fsync write/snapshot lock"
  15. }
  16. drug:PRIMARY> db.fsyncUnlock() #解锁
  17. { "ok" : , "info" : "unlock completed" }

十一:

MongoDB 数据库管理(不定时更新)的更多相关文章

  1. iOS 属性修饰符记录 --不定时更新

    重新审视了一下OC在属性修饰符,特意记录一下来.以后不定时更新 > retain:只有在非ARC下才会有效,所有如果在ARC下使用了retain修饰也白搭 如以下的data属性用retain修饰 ...

  2. MongoDB 文档的更新操作

    在MongoDB中,更新单个doc的操作是原子性的.默认情况下,如果一个update操作更新多个doc,那么对每个doc的更新是原子性的,但是对整个update 操作而言,不是原子性的,可能存在前面的 ...

  3. linux下svn定时更新项目

    方法一.用shell脚本定时更新项目   1.进入网站的根目录,假设项目位置放在/var/www/test cd /var/www/test   2.建立脚本文件update.sh,分两步进行.首先利 ...

  4. 三、MongoDB的创建、更新和删除

    一.MongoDB的下载.安装与部署 二.MongoDB的基础知识简介 三.MongoDB的创建.更新和删除 概要 下面开始学习MongoDB最重要也是最基础的部分:C(创建)R(查询)U(更新)D( ...

  5. ASP.NET中设置一个定时器来定时更新 转

    asp.net 定时器 比较少用,  中国红木网这是一个相当实用的功能,有了RSS博客镜像,就不需要在多处同时发布博客日志了.比如你同时在新浪上有自己的博客,又同时有自己的个人博客站点,那么你只需要在 ...

  6. MongoDB数组修改器更新数据(转)

    MongoDB数组修改器更新数据    这里,我们将了解一下数组修改器.数组,是我们经常看到和使用到的且非常有用的数据结构:它不仅可以通过索进行引用,还可以作为集合来使用.数组修改器,顾名思义,它是用 ...

  7. Vivado_MicroBlaze_问题及解决方法_汇总(不定时更新)

    Vivado_MicroBlaze_问题及解决方法_汇总(不定时更新) 标签: Vivado 2015-07-03 14:35 4453人阅读 评论(0) 收藏 举报  分类: 硬件(14)  版权声 ...

  8. Java日志组件logback使用:加载非类路径下的配置文件并设置定时更新

    Java日志组件logback使用:加载非类路径下的配置文件并设置定时更新 摘自: https://blog.csdn.net/johnson_moon/article/details/7887449 ...

  9. [Android Traffic] 调整定时更新的频率(C2DM与退避算法)

    转载自: http://blog.csdn.net/kesenhoo/article/details/7395253 Minimizing the Effect of Regular Updates[ ...

  10. Java专业技能面试问题(不定时更新)

    刚看到园友五月的仓颉<面试感悟----一名3年工作经验的程序员应该具备的技能>感觉很不错,不论是为面试跳槽准备,还是打算深化精进自己的技术都可以参考一下.面向工资编程多少也有点道理,虽然技 ...

随机推荐

  1. 简谈switch case

    工作中从buff里截取了一个字符串,然后和配置文件中的字符串名字对比 ,如果一样,处理,不一样,elseif 再判断,再处理! switch(){case : case :...... }先说语法,再 ...

  2. echo '.SUFFIXES: .cpp' >> ${OUTPUT_FILE}

    当前makefile或shell内支持文件后缀的类型列表,意思是文件支持.cpp结尾的类型,并且将他,输出到OUTPUT_FILE函数. 见网上有人说: “makefile中 .SUFFIXES: . ...

  3. 手把手教你如何把java代码,打包成jar文件以及转换为exe可执行文件

    1.背景: 学习java时,教材中关于如题问题,只有一小节说明,而且要自己写麻烦的配置文件,最终结果却只能转换为jar文件.实在是心有不爽.此篇博客教你如何方便快捷地把java代码,打包成jar文件以 ...

  4. Linux内核循环链表经典分析和移植

    为什么说这个链表做的经典呢,哥哥我从Linux内核里边儿扣出来的,要么怎么说内核不是一般人能写的,这代码太TM优美了! 这里有一篇参考文章:http://isis.poly.edu/kulesh/st ...

  5. Java实验1-文件IO

    目标:掌握Java类的创建,Java  I/O操作,Java集合类的使用等 内容: 王老师非常喜欢读书,为了便于查阅,他每次买书回家后就在笔记本上登记每本书的详细信息(书名.作者.出版社.出版日期.价 ...

  6. .NET中的工作目录一览!

    定义:       当前工作目录——进行某项操作的目的目录,会随着OpenFileDialog.SaveFileDialog等对象所确定的目录而改变. 当前执行目录——该进程从中启动的目录,即文件自身 ...

  7. 快速切换IP的批处理!

    内容如下: @echo off color 1A Title [SMART专用 IP设置V1.0] cls echo. echo SMART专用 IP设置V1.0 %date%%time% echo. ...

  8. 第九天 iOS音频技术

    1. AQRecorder mRecordFormat.mFormatID = inFormatID; if (inFormatID == kAudioFormatLinearPCM) { // if ...

  9. Android开发学习笔记--一个有界面A+B的计算器

    做了一个A+B的APP,虽然很简单,但是作为初学者还是弄了几个小时才弄好,什么东西都要看书或者百度,但最后成功了,还是很开心的,收货蛮大的.现在把过程写一下: 首先给出效果图: 一开始布局一直有问题, ...

  10. iOS开发——UI进阶篇(八)pickerView简单使用,通过storyboard加载控制器,注册界面,通过xib创建控制器,控制器的view创建,导航控制器的基本使用

    一.pickerView简单使用 1.UIPickerViewDataSource 这两个方法必须实现 // 返回有多少列 - (NSInteger)numberOfComponentsInPicke ...