[Monogdb] MongoDB log system, monogdbmongodb
I remember a friend who was checking mongodb logs a few days ago may not be able to locate the problem. Today, the system will talk about mongodb's log system. Mongodb has four types of logs. These are system logs, Journal logs, oplog Master/Slave logs, and slow query logs. These logs record different convenient traces of the Mongodb database. The following describes the four types of logs:
1. System Logs
System logs are important in Mongdb data. They record mongodb start and stop operations and any exceptions that occur when the server is running. It is also very easy to configure system logs, you can add the logpath parameter when running mongod to set it;
For example, mongod-logpath = '/data/db/log/server. log'-logappend.
2. Journal logs
Jouranl logs provide additional reliability assurance for mongodb through pre-written redo logs. When this function is enabled, data updates are first written into the Journal log, regularly submitted in a centralized manner (currently submitted every ms), and then formally performed changes in the data. It is very easy to start the Journal function of the database. You only need to specify the journal parameter after mongod;
Enabling method: mongod-journal
3. Oplog Master/Slave logs
The high-availability replication policy of Mongodb is called Replica Sets. during ReplicaSet replication, one server acts as the master server, and one or more act as slave servers. The master service writes updates to a local collection, this collection record the update operations that occur on the master server. And distribute these operations to the slave server. This log is a Capped Collection. Use the following command to configure
Required D-oplogSize = 1024 unit: M
4. Slow query logs
The slow query records the operation statements whose execution time exceeds the set time threshold. Slow log query is very helpful for statements that discover performance problems. We recommend that you enable this function and analyze the log Content frequently.
To configure this function, you only need to set the profile parameter when mongod starts. For example, if you want to record all operations that exceed 5s, you can use the following statement:
Mongod -- profile = 1 -- slowms = 5