zoukankan      html  css  js  c++  java
  • Mongodb开启慢查询

    开启慢查询Profiling

    Profiling级别说明

    0:关闭,不收集任何数据。
    1:收集慢查询数据,默认是100毫秒。
    2:收集所有数据

    1、通过修改配置文件开启Profiling

      修改启动mongo.conf,插入以下代码

    #开启慢查询,200毫秒的记录
    profile = 1
    slowms = 200

    2、在启动mongodb服务以后,通过mongoshell来进行临时性打开启,只要关闭了mongodb服务,下次开启就不会启动,还得再开一次

    (1)、在mongodb有权限的情况下,通过命令登录,如果没有权限可以不用写--username后面的内容

    mongo --host 127.0.0.1:27017 --username 你的用户名 --password 你的密码 --authenticationDatabase admin

            (2)、跳转到要开启慢查询监控的数据库

    use test

            (3)、设置Profiling

    复制代码
    1:通过mongo shell:
    #查看状态:级别和时间
    drug:PRIMARY> db.getProfilingStatus()   
    { "was" : 1, "slowms" : 100 }
    #查看级别
    drug:PRIMARY> db.getProfilingLevel()    
    1
    #设置级别
    drug:PRIMARY> db.setProfilingLevel(2)
    { "was" : 1, "slowms" : 100, "ok" : 1 }
    #设置级别和时间
    drug:PRIMARY> db.setProfilingLevel(1,200)
    { "was" : 2, "slowms" : 100, "ok" : 1 }
    复制代码

    (4)、修改“慢查询日志”的大小

    复制代码
    #关闭Profiling
    drug:PRIMARY> db.setProfilingLevel(0)
    { "was" : 0, "slowms" : 200, "ok" : 1 }
    #删除system.profile集合
    drug:PRIMARY> db.system.profile.drop()
    true
    #创建一个新的system.profile集合
    drug:PRIMARY> db.createCollection( "system.profile", { capped: true, size:4000000 } )
    { "ok" : 1 }
    #重新开启Profiling
    drug:PRIMARY> db.setProfilingLevel(1)
    { "was" : 0, "slowms" : 200, "ok" : 1 }
    复制代码

    注意:要改变Secondary的system.profile的大小,你必须停止Secondary,运行它作为一个独立的,然后再执行上述步骤。完成后,重新启动加入副本集。

  • 相关阅读:
    SIT/UAT测试
    Oracle密码过期设置和修改密码问题
    1、查询速度慢的原因很多,常见如下几种:
    dbs:apple-notes
    值不能为 null 或为空。参数名: linkText
    Visual Stadio 2015创建WebApplication应用和运行赏析
    HTTP 错误 500.19
    Introduction to ASP.NET Web Programming Using the Razor Syntax (C#)
    vs2015-Azure Mobile Service
    6.1.1 验证注解的使用
  • 原文地址:https://www.cnblogs.com/liangblog/p/14265673.html
Copyright © 2011-2022 走看看