MongoDB mongod.lock file and Oplog file

Source: Internet
Author: User

At the start of MongoDB, a Mongod.lock file is generated in the data directory. If the Mongod.lock file is cleared during normal exit, to exit abnormally, the boot will be disabled on the next boot, thus preserving a clean copy of the data. Someone might have thought of deleting this file,

Please don't do that. If you do this, we do not know whether the data file will be corrupted, if the Mongod.lock file prevents Mongod from starting, repair the data file instead of simply deleting the file. The mongod.lock file Here is the process number that started the Mongod .

This refers to the "normal exit", which is described in detail below:

MongoDB provides several commands for shutting down the service, specifically the following:


One use crtl+c off

[Email protected] data]$ Mongod--dbpath=/database/mongodb/data/--logpath=/var/applog/mongo_log/mongo.log-- Logappend--port=27017--journal > Start_mongo.log 2>&1
Cursor: type crtl+c close

Note: If you start the MongoDB service as a foreground, the use of the "crtl+c" service will be turned off, which will wait for
The currently in progress operation is completed, so it is still a clean shutdown mode.

Two using the database command to close
--2.1 Open Service

[Email protected] data]$ mongod-f/database/mongodb/data/mongodb_27017.conf
Forked process:18155
All output going to:/var/applog/mongo_log/mongo.log
Child process started successfully, parent exiting


--2.2 Landing Database

[Email protected] data]$ MONGO
MongoDB Shell version:2.2.1
Connecting To:test

--2.3 Close MongoDB Service

> Use admin;
Switched to DB admin

> db.shutdownserver ();
Wed Nov 06:07:33 Dbclientcursor::init call () failed
Wed Nov 06:07:33 Query failed:admin. $cmd {shutdown:1.0} to:127.0.0.1:27017
Server should is down ...
Wed Nov 06:07:33 trying reconnect to 127.0.0.1:27017
Wed Nov 06:07:33 Reconnect 127.0.0.1:27017 failed couldnt connect to server 127.0.0.1:27017

Three use the Mongod command to close

[Email protected] data]$ mongod --shutdown --dbpath/database/mongodb/data/
Killing process with pid:17747

Note: The shutdown option of the Mongod command can cleanly shut down the MongoDB service.

Four using the KILL command
--4.1 viewing MONGO related processes

[Email protected] data]$ Ps-ef | grep MONGO
Root 17573 14213 0 05:10 pts/1 00:00:00 Su-mongo
MONGO 17574 17573 0 05:10 pts/1 00:00:00-bash
MONGO 18288 1 0 06:12? 00:00:00 mongod-f/database/mongodb/data/mongodb_27017.conf
MONGO 18300 17574 6 06:13 pts/1 00:00:00 ps-ef
MONGO 18301 17574 0 06:13 pts/1 00:00:00 grep MONGO


--4.2 Kill MONGO Service process

[[email protected] data]$ kill 18288

[Email protected] data]$ Ps-ef | grep Pmon
MONGO 18304 17574 0 06:13 pts/1 00:00:00 grep pmon

Note: You can use the KILL command of the operating system to send a SIGINT or SIGTERM signal to the mongod process.
That is, "Kill-2 pid," or "kill-15 pid".

It is not recommended to use "kill-9 pid" because if MongoDB is running without logging on (--journal),
may result in data loss.

In the MONGO library, the Oplog is data storage and data master-slave synchronization, and in the local library locally, $ show collections, there is a oplog.rs collection, explaining the following fields:


{ts: ..., op: ..., ns: ..., o: ... o2: ...}

The above is a oplog information, the replication mechanism is to use this information to synchronize data between nodes and maintain data consistency, wherein:

The timestamp of the ts:8 byte, represented by a 4-byte UNIX timestamp + 4-byte self-increment count.
This value is important, and when the new primary is elected (such as Master down), the secondary of the largest TS is chosen as the new primary.
The operation type of the op:1 byte, for example I means that insert,d represents delete.
NS: The namespace where the operation is located.
O: The document that corresponds to the operation, that is, the contents of the current operation (such as the fields and values to be updated when the update operation)
O2: The Where condition when performing an update operation only if it is limited to update


Where op can be one of the following scenarios:

"I": Insert
"U": Update
"D": Delete
"C": db cmd
"DB": Declares the current database (where NS is set to = + database name + '. ')
"N": no op, empty operation, which is periodically executed to ensure timeliness

MongoDB mongod.lock file and Oplog file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.