title: "Mongodb每个数据库一个目录"
date: 2021-02-16T12:42:08+08:00
draft: true
tags: ['mongodb']
author: "dadigang"
author_cn: "大地缸"
personal: "http://www.real007.cn"
关于作者
Mongodb: Directory Per DB
启动MongoDB的时候,通常会使用--dbpath来指定存放mongodb数据文件的目录,但是--dbpath不能够带多个目录,所以当一台机器上总的磁盘空间很大但是每个分区空间都无法满足要求的时候,在不考虑加磁盘或者sharding模式外的办法,目前就只用使用--directoryperdb这个参数为每个db设定其归属目录,但是需要注意的是当我们只有一个db,而它需要占用很多空间的时候,这个参数也没有办法了!
--directoryperdb的使用场景就是我们有不同的物理磁盘,每个db的大小能够很好的放在相应的磁盘上的时候,可以通过这种配置方式提高访问磁盘的速度。
本文来自mongodb官方文档: http://www.mongodb.org/display/DOCS/Directory+Per+DB
Overview
MongoDB supports a "directory per DB" option.
By default data files for MongoDB are all created in a single directory. This directory is defined by the --dbpath variable.
The "directory per DB" option (--directoryperdb) allows for a separate directory for the files of each database.
Uses
The most common use for this option is to enable data to be stored on different physical disks. This is generally accomplished by creating a symbolic link to the appropriate underlying hardware.
Example
The following sample demonstrates the difference in directory structures. The db/ directory is run without "directory per DB", the db2/directory is run with "directory per DB".
db:
total 417M
-rw------- 1 mongo mongo 64M 2011-04-05 12:50 foo.0
-rw------- 1 mongo mongo 128M 2011-04-05 12:50 foo.1
-rw------- 1 mongo mongo 16M 2011-04-05 12:50 foo.ns
-rw------- 1 mongo mongo 64M 2011-04-05 12:48 test.0
-rw------- 1 mongo mongo 128M 2011-04-05 12:48 test.1
-rw------- 1 mongo mongo 16M 2011-04-05 12:48 test.ns
-rwxr-xr-x 1 mongo mongo 5 2011-04-05 12:47 mongod.lock
db2:
total 16K
drwxr-xr-x 2 mongo mongo 4.0K 2011-04-05 12:50 foo
-rwxr-xr-x 1 mongo mongo 5 2011-04-05 12:47 mongod.lock
drwxr-xr-x 2 mongo mongo 4.0K 2011-04-05 12:48 test
db2/foo:
total 209M
-rw------- 1 mongo mongo 64M 2011-04-05 12:50 foo.0
-rw------- 1 mongo mongo 128M 2011-04-05 12:50 foo.1
-rw------- 1 mongo mongo 16M 2011-04-05 12:50 foo.ns
db2/test:
total 209M
-rw------- 1 mongo mongo 128M 2011-04-05 12:48 test.1
网友评论