1

Is it possible to separate MongoDB files location so the indexes are on another file system?

In the example below, I have database with 1.5TB of data + indexes of 330GB. I have a very fast storage that is not large enough to hold the entire data. I assume that if I move there the indexes I can get better performance.

Is there a way to do so?

# ls -l /data/mongodb --block-size=G
total 1962G
-rw-------. 1 root root    1G May 27 20:17 collection-0--8049282980716619517.wt
-rw-------. 1 root root    1G May 27 20:17 collection-2--8049282980716619517.wt
-rw-------. 1 root root    1G May 27 20:17 collection-4--8049282980716619517.wt
-rw-------. 1 root root 1627G May 27 20:17 collection-7--8049282980716619517.wt
drwx------. 2 root root    1G May 27 20:14 diagnostic.data
-rw-------. 1 root root    1G May 27 20:17 index-1--8049282980716619517.wt
-rw-------. 1 root root    1G May 27 20:17 index-3--8049282980716619517.wt
-rw-------. 1 root root    1G May 27 20:17 index-5--8049282980716619517.wt
-rw-------. 1 root root    1G May 27 20:17 index-6--8049282980716619517.wt
-rw-------. 1 root root   15G May 27 20:14 index-8--8049282980716619517.wt
-rw-------. 1 root root  320G May 27 20:17 index-9--8049282980716619517.wt
drwx------. 2 root root    1G May 27 13:54 journal
-rw-------. 1 root root    1G May 27 20:17 _mdb_catalog.wt
-rw-------. 1 root root    0G May 27 20:17 mongod.lock
-rw-------. 1 root root    1G May 27 20:17 sizeStorer.wt
-rw-------. 1 root root    1G May 23 12:50 storage.bson
-rw-------. 1 root root    1G May 23 12:50 WiredTiger
-rw-------. 1 root root    1G May 27 20:17 WiredTigerLAS.wt
-rw-------. 1 root root    1G May 23 12:50 WiredTiger.lock
-rw-------. 1 root root    1G May 27 20:17 WiredTiger.turtle
-rw-------. 1 root root    1G May 27 20:17 WiredTiger.wt
#
1

To be clear, this feature is only available when using the WiredTiger storage engine.

To use, invoke mongod like so:

mongod --dbpath /tmp --storageEngine wiredTiger --wiredTigerDirectoryForIndexes

In your dbpath, you will see a directory called indexes where indexes will be stored.

Also update yaml as

storage:
  engine: wiredTiger
wiredTiger:
  engineConfig:
  directoryForIndexes: true

Kindly note to try this in test environment once. Please ask if any further help is required.

Source: https://jira.mongodb.org/browse/SERVER-965

  • Thanks. Do I need to rebuild the indexes or can I simply copy the index-* files the the new index directory? – Yuval May 28 at 9:40
  • Using the instructions by Priyanka Kariya I was able to create a new database with index directory. Is there any way to separate the index for an existing database ? – Yuval May 28 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.