Skip to content

Commit ee063bb

Browse files
committed
DOCS-4674: Tweak data directory size FAQ
1 parent 3e4bb2a commit ee063bb

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

source/faq/storage.txt

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -170,63 +170,63 @@ The data files in your data directory, which is the :file:`/data/db`
170170
directory in default configurations, might be larger than the data set
171171
inserted into the database. Consider the following possible causes:
172172

173-
- Preallocated data files.
174-
175-
In the data directory, MongoDB preallocates data files to a
176-
particular size, in part to prevent file system
177-
fragmentation. MongoDB names the first data file ``<databasename>.0``,
178-
the next ``<databasename>.1``, etc. The first file :program:`mongod`
179-
allocates is 64 megabytes, the next 128 megabytes, and so on, up to
180-
2 gigabytes, at which point all subsequent files are 2
181-
gigabytes. The data files include files with allocated space but
182-
that hold no data. :program:`mongod` may allocate a 1 gigabyte data
183-
file that may be 90% empty. For most larger databases, unused
184-
allocated space is small compared to the database.
185-
186-
- The :term:`oplog`.
187-
188-
If this :program:`mongod` is a member of a replica set, the data
189-
directory includes the :term:`oplog.rs <oplog>` file, which is a
190-
preallocated :term:`capped collection` in the ``local``
191-
database. The default allocation is approximately 5% of disk space
192-
on 64-bit installations, see :ref:`Oplog Sizing
193-
<replica-set-oplog-sizing>` for more information. In most cases, you
194-
should not need to resize the oplog. However, if you do, see
195-
:doc:`/tutorial/change-oplog-size`.
196-
197-
- The :term:`journal`.
198-
199-
The data directory contains the journal files, which store write
200-
operations on disk prior to MongoDB applying them to databases. See
201-
:doc:`/core/journaling`.
202-
203-
- Empty records.
204-
205-
MongoDB maintains lists of empty records in data files when
206-
deleting documents and collections. MongoDB can reuse this space,
207-
but will never return this space to the operating system.
208-
209-
To de-fragment allocated storage, use :dbcommand:`compact`, which
210-
de-fragments allocated space. By de-fragmenting storage, MongoDB
211-
can effectively use the allocated space. :dbcommand:`compact`
212-
requires up to 2 gigabytes of extra disk space to run. Do not
213-
use :dbcommand:`compact` if you are critically low on disk space.
214-
215-
.. important:: :dbcommand:`compact` only removes fragmentation
216-
from MongoDB data files and does not return any disk space to
217-
the operating system.
218-
219-
To reclaim deleted space, use :dbcommand:`repairDatabase`, which
220-
rebuilds the database which de-fragments the storage and may release
221-
space to the operating system. :dbcommand:`repairDatabase` requires
222-
up to 2 gigabytes of extra disk space to run. Do not use
223-
:dbcommand:`repairDatabase` if you are critically low on disk space.
224-
225-
.. warning::
226-
:dbcommand:`repairDatabase` requires enough free disk space to
227-
hold both the old and new database files while the repair is
228-
running. Be aware that :dbcommand:`repairDatabase` will block
229-
all other operations and may take a long time to complete.
173+
Preallocated data files
174+
~~~~~~~~~~~~~~~~~~~~~~~
175+
176+
MongoDB preallocates its data files to avoid filesystem fragmentation, and
177+
because of this, the size of these files do not necessarily reflect the size of
178+
your data.
179+
180+
The :setting:`storage.mmapv1.smallFiles` option will reduce the
181+
size of these files, which may be useful if you have many small databases on
182+
disk.
183+
184+
The ``oplog``
185+
~~~~~~~~~~~~~
186+
187+
If this :program:`mongod` is a member of a replica set, the data
188+
directory includes the :term:`oplog.rs <oplog>` file, which is a
189+
preallocated :term:`capped collection` in the ``local``
190+
database.
191+
192+
The default allocation is approximately 5% of disk space
193+
on 64-bit installations. In most cases, you should not need to resize the oplog.
194+
See :ref:`Oplog Sizing <replica-set-oplog-sizing>` for more information.
195+
196+
The ``journal``
197+
~~~~~~~~~~~~~~~
198+
199+
The data directory contains the journal files, which store write
200+
operations on disk before MongoDB applies them to databases. See
201+
:doc:`/core/journaling`.
202+
203+
Empty records
204+
~~~~~~~~~~~~~
205+
206+
MongoDB maintains lists of empty records in data files as it deletes
207+
documents and collections. MongoDB can reuse this space,
208+
but will not, by default, return this space to the operating system.
209+
210+
To de-fragment allocated storage, use :dbcommand:`compact`. By de-fragmenting
211+
storage, MongoDB can more effectively use the allocated space.
212+
:dbcommand:`compact` requires up to 2 gigabytes of extra disk space to run. Do
213+
not use :dbcommand:`compact` if you are critically low on disk space.
214+
215+
:dbcommand:`compact` only removes fragmentation from MongoDB data files within
216+
a collection, and does not return any disk space to the operating system.
217+
218+
If you must reclaim disk space, you can use :dbcommand:`repairDatabase`. This
219+
command rebuilds the database, de-fragmenting the associated storage in the
220+
process. This may release space to the operating system.
221+
:dbcommand:`repairDatabase` requires up to 2 gigabytes of extra disk space to
222+
run. Do not use :dbcommand:`repairDatabase` if you are critically low on disk
223+
space.
224+
225+
.. warning::
226+
:dbcommand:`repairDatabase` requires enough free disk space to
227+
hold both the old and new database files while the repair is
228+
running. Be aware that :dbcommand:`repairDatabase` will block
229+
all other operations and may take a long time to complete.
230230

231231
.. _faq-working-set:
232232

0 commit comments

Comments
 (0)