Home / Databases / MongoDB

DatabasesRunbookAdvanced

Sev1: MongoDB data disk full. mongod crashed or writes fail with No space left on device

The dbPath volume filled up, so mongod aborted or writes are failing. Restore capacity without deleting data files, bring the member back, reclaim space with compact or resync, and alert earlier.

Deepak Bhardwaj6 min read

Applies toMongoDB 6.0, 7.0 and 8.0 Community and Enterprise (WiredTiger), self-managed replica sets and sharded clusters on Linux VMs, EC2 or Azure VMs

Symptoms

  • mongod stopped, and the log shows No space left on device or a WiredTiger error followed by Fatal assertion and aborting after fassert() failure.
  • If the process is still up, writes fail and clients get errors or time out waiting for write concern.
  • On a replica set, if the primary's disk filled, an election follows. Secondaries often have the same data size, so the next primary can fill up minutes later.
  • df -h shows the dbPath volume at 100%.

1. Confirm scope and impact

Check every member, not only the one that alerted:

df -h /var/lib/mongo                   # dbPath; check storage.dbPath in /etc/mongod.conf
du -sh /var/lib/mongo/* 2>/dev/null | sort -h | tail -15
systemctl status mongod
grep -iE "no space|fassert|ENOSPC" /var/log/mongodb/mongod.log | tail -20

From a healthy member, check the replica set state:

rs.status().members.map(m => ({ name: m.name, state: m.stateStr, health: m.health, lagFrom: m.optimeDate }))
Situation Risk Priority
One secondary full, primary healthy Reduced redundancy Fix within the hour
Primary full, election succeeded, new primary has headroom Writes recovered Fix the old primary, and watch the new primary's disk
Majority of members full or down No primary, writes down Act now: extend disks first
Standalone mongod Full outage Act now

2. Make space without touching data files

Caution

Never delete or move files in the dbPath (collection-*.wt, index-*.wt, WiredTiger*, journal/, _mdb_catalog.wt) to free space. Removing even one file can make the instance unrecoverable without a resync or restore. Do not run mongod --repair because of a full disk. Repair is for corruption and needs free space of its own.

The safest fix is to extend the volume. You can do this online on most clouds.

# Azure: resize the managed disk (some disk types and VM sizes need the disk detached or the VM deallocated; check current support)
az disk update --resource-group rg-mongo --name mongo1-data --size-gb 1024

# AWS: modify the EBS volume, then wait until the modification reaches 'optimizing' or 'completed'
aws ec2 modify-volume --volume-id vol-0abc123 --size 1024
aws ec2 describe-volumes-modifications --volume-ids vol-0abc123

# Then grow the filesystem on the host
lsblk
sudo growpart /dev/nvme1n1 1            # only if the filesystem sits on a partition
sudo xfs_growfs /var/lib/mongo          # XFS (recommended for WiredTiger)
# sudo resize2fs /dev/nvme1n1p1         # ext4

If the volume uses LVM, add a disk and run lvextend -r.

While you wait for the resize, free space that is not data:

ls -lh /var/log/mongodb/                   # rotated logs on the same volume
sudo find /var/lib/mongo -maxdepth 1 -name "*.tmp" -ls   # look only; confirm before removing anything

From a live mongod you can rotate the log, then compress or move the old files:

db.adminCommand({ logRotate: 1 })

Look for unrelated large files too, such as dump files written to the same volume by mongodump --out, or a core dump.

3. Bring the member back

Once there is free space, start mongod. WiredTiger recovers from the last checkpoint and replays the journal:

sudo systemctl start mongod
tail -f /var/log/mongodb/mongod.log | grep -iE "recovery|WiredTiger|STARTUP|SECONDARY|PRIMARY"
rs.status().members.filter(m => m.self)[0].stateStr    // expect SECONDARY, then catching up
db.getReplicationInfo()                                   // check the oplog window covers the downtime

If the member was down longer than the oplog window, it reports RS102 too stale to catch up and needs an initial sync. See secondary too stale: oplog window.

4. Find out what used the space

db.adminCommand({ listDatabases: 1, nameOnly: false }).databases
  .sort((a, b) => b.sizeOnDisk - a.sizeOnDisk).slice(0, 10)
  .map(d => ({ db: d.name, gb: (d.sizeOnDisk / 1024 ** 3).toFixed(1) }))

use appdb
db.runCommand({ dbStats: 1, scale: 1024 * 1024 * 1024, freeStorage: 1 })

Per-collection size, including space that WiredTiger can reuse:

db.getCollectionNames().map(c => {
  const s = db.getCollection(c).stats({ scale: 1024 * 1024 });
  return { c, dataMB: s.size, storageMB: s.storageSize,
           reusableMB: s.wiredTiger?.["block-manager"]?.["file bytes available for reuse"] / 1048576,
           indexMB: s.totalIndexSize };
}).sort((a, b) => b.storageMB - a.storageMB).slice(0, 10)

Common causes:

  • A collection without a TTL index that is growing without limit, such as events, sessions or audit records.
  • A bulk load or migration that doubled a collection.
  • A large delete that freed space inside WiredTiger files but did not return it to the OS. reusableMB is high in that case.
  • A new index build on a large collection.

5. Reclaim space

After a large delete, the space is reused for new writes but the files do not shrink. To give the space back to the OS, either compact or resync, one member at a time.

// On a SECONDARY, connected directly to that member
db.runCommand({ compact: "events" })

compact can run for a long time and adds I/O on that member. Check the documentation for your version on how compact blocks operations, and run it outside peak hours. When the secondaries are done, step down the primary (rs.stepDown()) and compact it as a secondary.

The alternative is to resync one secondary at a time (stop it, empty its dbPath, start it). The initial sync writes compact files. Use this only when the rest of the replica set is healthy and has a majority, because during the sync you have one less copy of the data.

Warning

Do not start a resync or a compact on the remaining healthy members while another member is still recovering. You could lose the majority and the ability to elect a primary.

6. Verify recovery

  • All members show PRIMARY or SECONDARY with low replication lag.
  • df -h shows at least 20–30% free on every member's dbPath volume.
  • Application write errors are back to baseline. Retryable writes may have hidden some failures, so check the application logs for errors that were not retried.

Communicate

Report when writes failed or were degraded, whether a failover happened, and that no data files were removed. If any member needs an initial sync, give its expected completion time, because redundancy is reduced until it finishes.

Prevent it next time

  • Alert on dbPath free space at 25% and 15%, and on the growth rate (days until full), on every member.
  • Add TTL indexes to collections that hold expiring data: db.events.createIndex({ createdAt: 1 }, { expireAfterSeconds: 2592000 }).
  • Keep logs, dumps and backups on a separate volume from dbPath.
  • Plan for space from bulk deletes and index builds before you run them. They need free space before any space comes back.
  • Size all members of a replica set the same way, so that a failover does not move the problem to a smaller disk.