@@ -10,208 +10,68 @@ Change the Size of the Oplog
1010 :depth: 1
1111 :class: singlecol
1212
13- The :term:`oplog` exists internally as a :term:`capped collection`, so
14- you cannot modify its size in the course of normal operations. In most
15- cases the :ref:`default oplog size <replica-set-oplog-sizing>` is an
16- acceptable size; however, in some situations you may need a larger or
17- smaller oplog. For example, you might need to change the oplog size
18- if your applications perform large numbers of multi-updates or
19- deletes in short periods of time.
13+ .. versionadded:: 3.6
2014
21- This tutorial describes how to resize the oplog when using the MMAPv1
22- storage engine. If you are using WiredTiger, see
23- :doc:`/reference/command/replSetResizeOplog` to dynamically change the oplog size.
15+ This procedure changes the size of the oplog on each member of a
16+ replica set using the :dbcommand:`replSetResizeOplog` command, starting
17+ with the :term:`secondary` members before proceeding to the
18+ :term:`primary`.
2419
25- For a detailed explanation of oplog sizing, see :ref:`replica-set-oplog-sizing`.
26- For details of how oplog size affects :term:`delayed members <delayed
27- member>` and affects :term:`replication lag`, see
28- :ref:`replica-set-delayed-members`.
20+ .. important::
2921
30- Overview
31- --------
22+ You can only run :dbcommand:`replSetResizeOplog` on
23+ replica set member's running with the
24+ :ref:`Wired Tiger storage engine <storage-wiredtiger>`.
3225
33- To change the size of the oplog, you must perform maintenance on each
34- member of the replica set in turn. The procedure requires: stopping
35- the :program:`mongod` instance and starting as a standalone instance,
36- modifying the oplog size, and restarting the member.
26+ Perform these steps on each :term:`secondary` replica set member
27+ *first*. Once you have changed the oplog size for all secondary
28+ members, perform these steps on the :term:`primary`.
3729
38- .. important:: Always start rolling replica set maintenance with the
39- secondaries, and finish with the maintenance on primary member.
30+ A. Connect to the replica set member
31+ ------------------------------------
4032
41- Procedure
42- ---------
33+ Connect to the replica set member using the :program:`mongo` shell:
4334
44- - Restart the member in standalone mode.
35+ .. code-block:: shell
4536
46- .. tip:: Always use :method:`rs.stepDown()` to force the primary to
47- become a secondary, before stopping the server. This facilitates
48- a more efficient election process.
37+ mongo --host <hostname>:<port>
4938
50- - Recreate the oplog with the new size and with an old oplog entry as
51- a seed.
39+ .. note::
5240
53- - Restart the :program:`mongod` instance as a member of the replica
54- set.
41+ If the replica set enforces :ref:`authentication <authentication>`,
42+ you must authenticate as a user with privileges to modify the
43+ ``local`` database, such as the :authrole:`clusterManager` or
44+ :authrole:`clusterAdmin` role.
5545
56- Restart a Secondary in Standalone Mode on a Different Port
57- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46+ B. (Optional) Verify the current size of the oplog
47+ --------------------------------------------------
5848
59- Shut down the :program:`mongod` instance for one of the non-primary
60- members of your replica set. For example, to shut down, use the
61- :method:`db.shutdownServer()` method:
49+ To view the current size of the oplog, switch to the ``local``
50+ database and run :method:`db.collection.stats()` against the
51+ ``oplog.rs`` collection. :method:`~db.collection.stats()` displays the
52+ oplog size as :data:`~collStats.maxSize`.
6253
63- .. code-block:: sh
64-
65- use admin
66- db.shutdownServer()
67-
68- Restart this :program:`mongod` as a standalone instance
69- running on a different port and *without*
70- the :option:`--replSet <mongod --replSet>` parameter. Use a command
71- similar to the following:
72-
73- .. include:: /includes/warning-bind-ip-security-considerations.rst
74-
75- .. code-block:: sh
76-
77- mongod --port 37017 --dbpath /srv/mongodb --bind_ip localhost,<ip address of the mongod host>
78-
79- Create a Backup of the Oplog (Optional)
80- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81-
82- Optionally, backup the existing oplog on the standalone instance, as
83- in the following example:
84-
85- .. code-block:: sh
86-
87- mongodump --db local --collection 'oplog.rs' --port 37017
88-
89- Recreate the Oplog with a New Size and a Seed Entry
90- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91-
92- Save the last entry from the oplog. For example, connect to the instance
93- using the :program:`mongo` shell, and enter the following command to
94- switch to the ``local`` database:
54+ The following operation displays the oplog size using the
55+ :method:`db.collection.stats()` command and
56+ :data:`~collStats.maxSize`:
9557
9658.. code-block:: javascript
9759
9860 use local
61+ db.oplog.rs.stats().maxSize
9962
100- In :program:`mongo` shell scripts you can use the following operation
101- to set the ``db`` object:
102-
103- .. code-block:: javascript
104-
105- db = db.getSiblingDB('local')
106-
107- Ensure that the ``temp`` temporary collection is empty by dropping the
108- collection:
63+ The ``maxSize`` field displays the collection size in bytes.
10964
110- .. code-block:: javascript
111-
112- db.temp.drop()
113-
114- Retrieve the latest oplog entry by sorting on reverse :term:`natural order`.
115- Modify the entry to set ``op`` to "n" (representing a no-op) and clear the
116- ``o`` and ``o2`` fields. Then insert the modified oplog entry into a temporary
117- collection.
118-
119- .. _last-oplog-entry:
65+ C. Change the oplog size of the replica set member
66+ --------------------------------------------------
12067
121- .. code-block:: javascript
122-
123- var oplogEntry = db.oplog.rs.find().sort({$natural: -1}).limit(1).next();
124- oplogEntry.op = 'n'; // Change the entry to a no-op.
125- oplogEntry.o = {}; // Remove any update modifiers that would prevent saving the oplog entry to a normal collection.
126- oplogEntry.o2 = {};
127- db.temp.insert(oplogEntry);
68+ To change the size, run the :dbcommand:`replSetResizeOplog` passing
69+ the desired size in megabytes as the ``size`` parameter. The
70+ specified size must be greater than ``990``, or 990 megabytes.
12871
129- To see this oplog entry, use the following operation:
72+ The following operation changes the oplog size of the replica set
73+ member to 16 gigabytes, or 16000 megabytes.
13074
13175.. code-block:: javascript
13276
133- db.temp.find()
134-
135- Remove the Existing Oplog Collection
136- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
137-
138- Drop the old ``oplog.rs`` collection in the ``local`` database. Use
139- the following command:
140-
141- .. code-block:: javascript
142-
143- db = db.getSiblingDB('local')
144- db.oplog.rs.drop()
145-
146- This returns ``true`` in the shell.
147-
148- Create a New Oplog
149- ~~~~~~~~~~~~~~~~~~
150-
151- Use the :dbcommand:`create` command to create a new oplog of a
152- different size. Specify the ``size`` argument in bytes. A value of
153- ``2 * 1024 * 1024 * 1024`` will create a new oplog that's 2 gigabytes:
154-
155- .. code-block:: javascript
156-
157- db.runCommand( { create: "oplog.rs", capped: true, size: (2 * 1024 * 1024 * 1024) } )
158-
159- Upon success, this command returns the following status:
160-
161- .. code-block:: javascript
162-
163- { "ok" : 1 }
164-
165- Insert the Last Entry of the Old Oplog into the New Oplog
166- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167-
168- Insert the previously inserted latest entry from the old oplog into the new
169- oplog. For example:
170-
171- .. code-block:: javascript
172-
173- db.oplog.rs.insert( db.temp.findOne() )
174-
175- To confirm the entry is in the new oplog, use the following operation:
176-
177- .. code-block:: javascript
178-
179- db.oplog.rs.find()
180-
181- Restart the Member
182- ~~~~~~~~~~~~~~~~~~
183-
184- Stop the server. For example, from the :program:`mongo` shell, you can
185- issue the following:
186-
187- .. code-block:: javascript
188-
189- use admin
190- db.shutdownServer()
191-
192- Restart the :program:`mongod` as a member of the replica set on its
193- usual port. From the system prompt (**not** the :program:`mongo`
194- shell):
195-
196- .. code-block:: sh
197-
198- mongod --replSet rs0 --dbpath /srv/mongodb --bind_ip localhost,<ip address of the mongod host>
199-
200- .. include:: /includes/warning-bind-ip-security-considerations.rst
201-
202- The replica set member will recover and "catch up" before it is
203- eligible for election to primary.
204-
205- Repeat Process for all Members that may become Primary
206- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
207-
208- Repeat this procedure for all members you want to change the size of
209- the oplog. Repeat the procedure for the primary as part of the
210- following step.
211-
212- Change the Size of the Oplog on the Primary
213- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214-
215- To finish the rolling maintenance operation, step down the primary with the
216- :method:`rs.stepDown()` method and repeat the oplog resizing procedure
217- above.
77+ db.adminCommand({replSetResizeOplog: 1, size: 16000})
0 commit comments