slow query log in MongoDB
1. turn on the query log .
(1) Dynamic Open , can be selective to the specified DB turn on slow query log , However, the slow query log is manually opened after the server restarts.
Db.setprofilinglevel (1,300)
The Setprofilinglevel has two parameters , the first parameter represents the slow query log switch ( The value that can be used is 0,1,2
0: The slow query log is turned off , 1: indicates that the slow query log is turned on , 2: indicates that all queries in the database are logged.
The second parameter is a slow query threshold , in milliseconds , and by default , the threshold is 100ms.
(2). in the configuration file, open , Be permanently in effect. Valid for all data DB
Add two parameters to the MONGO configuration file to permanently open the slow query.
Profile: indicates a slow query log switch .
SLOWMS: Slow query log threshold.
corresponds to the two parameters in the Setprofilinglevel.
2. View server slow query log status
Db.getprofilingstatus ()
Rs0:secondary> Db.getprofilingstatus ();
{"was": 1, "SLOWMS": 100}
Db.getprofilinglevel ()
Rs0:secondary> Db.getprofilinglevel ()
1
3. view the full query log.
In general , a collection (system.profile) is generated below each DB when the slow query log is turned on .
This collection records all query records for the current database query time exceeding the threshold.
Rs0:primary> db.system.profile.find ({ns:/^gow/}). Limit (1)
{"OP": "Update",
"NS": "Gow.broadcasts",
"Query": {"_id": ObjectId ("54b73af6bab3047b5593c456")},
"Updateobj": {"_id": ObjectId ("54b73af6bab3047b5593c456"), "content": " each new stone "},
"nscanned": 0,
"Nscannedobjects": 0,
"Nmatched": 1,
"Nmodified": 0,
"Upsert": true,
"Keyupdates": 0,
"Numyield": 0,
"Lockstats": {"Timelockedmicros": {"R": Numberlong (0), "W": Numberlong (10)}},
"Millis": 157,
"Execstats": {},
"TS": Isodate ("2015-01-26t19:05:00.118z"),
"Client": "10.136.3.117",
"AllUsers": [{"User": "Root", "db": "admin"}], "User": "[email protected]"}
Key value Explanation:
OP: The type of operation.
NS: Collection of objects performing actions
Millis: Operation takes time, milliseconds
Client: The customer service side that performs the operation.
AllUsers: mongodb account to perform the operation
TS: timestamp ( The time the operation occurred )
This article is from the "SQL Server MySQL" blog, so be sure to keep this source http://dwchaoyue.blog.51cto.com/2826417/1614281
MongoDB Slow Query