mongorestore fails with "out of memory"

Posted October 6, 2015 10.6k views

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:

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

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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.