I received a message saying the are issue in our Node.js app running on Azure: Can’t take a write lock while out of disk space. The issue is clear enough: our MongoDB data disk is run out. I will outlined steps how we can resize MongoDB data disk. Well, it’s not actually that hard. Simplified steps are :
- Prepare bigger data disk
- Copy all old MongoDB data from old disk to new one
- Update MongoDB config
- Restart MongoDB service
Start with preparing bigger disk space. On Azure, follow this tutorial on How to Attach a Data Disk to a Linux Virtual Machine
Then create MongoDB data folder and make sure to change ownership of the folder to mongod or you will have write access issue.
Copy all old data to new folder
-v if you want to see the copying progree, or if you forget to do that use this command
When copy completed, open MongoDb config file (usually in
/etc/mongod.conf) and update the dbpath to the new data folder.
Restart the service
While the resizing MongoDB data disk is quite simple, disk run out issue should not be happening during production server deployment. One possible approach to minimize the risk is to create reporting daemon (or use third party service) to monitor server stats.