Error
Error Code:
14031
MongoDB Error 14031: Out of Disk Space
Description
This critical MongoDB error indicates that the database server has run out of available disk space on its host system. It prevents MongoDB from writing new data, creating temporary files, or performing essential operations. This can lead to database unresponsiveness, write failures, or even server crashes.
Error Message
Out Of Disk Space
Known Causes
4 known causesHost System Disk Full
The physical disk partition where MongoDB stores its data, logs, or operating system files has reached its maximum capacity.
Excessive Data Growth
MongoDB's data files (e.g., `_data`, `_index`) have expanded beyond the available disk capacity due to large amounts of stored data or extensive indexing.
Unmanaged Log Files
MongoDB or system log files have accumulated without proper rotation or management, gradually filling up the disk space over time.
Temporary File Accumulation
Temporary files generated by MongoDB operations or the operating system have not been cleaned up, contributing to disk space exhaustion.
Solutions
4 solutions available1. Free Up Disk Space on the Server easy
Remove unnecessary files from the server hosting MongoDB.
1
Identify large files or directories on the server that are not essential. This could include old log files, temporary files, or unused backups.
sudo du -sh /path/to/directory/* | sort -rh | head -n 10
2
Delete or move these identified files to a different storage location.
sudo rm /path/to/unnecessary_file.log
3
If using cloud storage, consider deleting old snapshots or unattached volumes.
N/A (Specific to cloud provider's console/CLI)
2. Archive or Purge Old MongoDB Data medium
Remove historical data from MongoDB collections that is no longer needed.
1
Identify collections that are growing rapidly and contain historical data. Use the `db.collection.stats()` command to check collection sizes.
db.collection.stats()
2
If the data is not actively used, consider archiving it to a separate database, file, or data lake. For data that can be permanently deleted, use the `deleteMany()` operation.
db.collection.deleteMany({ timestamp: { $lt: ISODate('2023-01-01T00:00:00Z') } });
3
After deleting a significant amount of data, it's good practice to run `db.collection.reIndex()` on the affected collection to reclaim disk space. Note that this can be an I/O intensive operation.
db.collection.reIndex()
3. Configure MongoDB's WiredTiger Storage Engine for Compression medium
Enable compression to reduce the disk footprint of your MongoDB data.
1
Ensure you are using the WiredTiger storage engine (default for modern MongoDB versions). Check your `storage.engine` configuration.
N/A (Check mongod.conf or use `db.serverStatus().storageEngine.name`)
2
Modify your MongoDB configuration file (`mongod.conf`) to enable WiredTiger compression. The most common compression algorithms are `snappy` (good balance of speed and compression) and `zstd` (higher compression ratio but potentially more CPU intensive).
storage:
engine: wiredTiger
wiredTiger:
collectionConfig:
compression: snappy
indexConfig:
prefixCompression: true
3
Restart the MongoDB server for the configuration changes to take effect. This will trigger a re-compression of existing data over time.
sudo systemctl restart mongod
4. Increase Disk Capacity for the MongoDB Data Directory medium
Add more storage to the server or the volume where MongoDB stores its data.
1
Determine the current disk usage of your MongoDB data directory. Typically, this is defined by the `dbPath` in your MongoDB configuration file.
sudo du -sh /var/lib/mongodb
2
If running on a virtual machine or cloud instance, increase the size of the attached storage volume or add a new volume and mount it to a directory that can be used by MongoDB.
N/A (Specific to cloud provider or virtualization platform)
3
If using a physical server, add more hard drives or expand existing partitions. Ensure the filesystem is mounted and accessible.
N/A (OS-level disk management)
4
If you added a new drive, you may need to migrate your `dbPath` to the new larger volume and update your MongoDB configuration. This will likely involve stopping MongoDB, moving the data, and restarting.
sudo mv /var/lib/mongodb /mnt/new_drive/mongodb
# Update mongod.conf to point dbPath to /mnt/new_drive/mongodb
sudo systemctl restart mongod