mongorestore fails with "out of memory"

October 6, 2015 2k views
MongoDB Deployment

I need to import my db from the old hosting. Iv'e already exported it from the old hosting using mongodump and now trying the following:

mongorestore -h -d bassfunk_moscow dump/bassfunk_moscow/

it stops with the fatal error: runtime: out of memory

Here is all the log: http://pastebin.com/7YHaxwp3

What should be my next steps? I'm lost here. The DB dump is not that big - about 50mb.

uname -a
Linux bassfunk 3.13.0-57-generic #95-Ubuntu SMP Fri Jun 19 09:28:15 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
1 Answer

This message would indicate that the mongo process itself attempted to allocate more memory but there was none (or not enough) left for the operating system to allocate it. If you are on a 512MB or 1GB droplet I would recommend creating a swap file on your droplet. With a swap file, if your droplet runs out of physical memory it will use the file to swap out memory data to the disk, preventing this type of issue.

While this will prevent the process from crashing (or at least ensure it takes a lot more to get to that point), having a lot of memory swapped out to disk will slow things down as it is much slower for the OS to query the data in a swap file than to do so from RAM. For this reason, I would also recommend running free -m once you have completed your import and your services are running normally in order to ensure that you have enough memory available for normal operation.

by Justin Ellingwood
Swap space can be used as an "overflow" area for your system when you run out of RAM. The operating system can store data that would normally be kept in RAM on the hard drive in a specially formatted file. In this guide, we'll demonstrate how to create and use one of these files in Ubuntu 14.04.
  • Thank you, it helps! How can I stop the swap once i've done? Just deleting the folder in the root?

    • The last step in that tutorial has you add the swap file to /etc/fstab. If you only plan to use it on a temporary basis, skip this step. Once you are done you can run:

      swapoff /swapfile

      and then delete /swapfile

  • Very helpful, thanks!

Have another answer? Share your knowledge.