数据目录里一堆 collection-xxx.wt、index-xxx.wt 到底是什么?这篇从空的 dbpath 开始,建集合和索引,逐个看新增了哪些文件、怎么对应回集合名、小文件里写了什么、journal 和诊断数据目录的情况。
WiredTiger 50
WiredTiger.lock 21
WiredTiger.turtle 1,278
WiredTiger.wt 4,096
WiredTigerHS.wt 4,096
_mdb_catalog.wt 4,096
_tmp/ 96
collection-1f3c7da1-a1dd-4e2c-ae94-debfc6ea450f.wt 4,096
collection-3a08494b-88c2-4161-b21d-1fc6e1ae0415.wt 4,096
collection-5a9d537d-45f6-4ef9-9c32-229b90eb490a.wt 4,096
index-04c4aeae-f91b-4cef-98e7-ab2f96ce02c8.wt 4,096
index-071cf771-ffd1-4f6f-a088-2987df51a9a7.wt 4,096
index-2a4f5585-854d-4be9-9a5a-ff0571a7a380.wt 4,096
index-5461ee2c-09ac-4b3d-b491-5abddb7154c3.wt 4,096
journal/ 128
mongod.lock 6
sizeStorer.wt 4,096
storage.bson 114
test> db.getSiblingDB("admin").aggregate([{$listCatalog: {}}, {$project: {_id: 0, ns: 1, ident: 1}}, {$sort: {ns: 1}}])
[
{
ident: 'collection-5a9d537d-45f6-4ef9-9c32-229b90eb490a',
ns: 'admin.system.version'
},
{
ident: 'collection-1f3c7da1-a1dd-4e2c-ae94-debfc6ea450f',
ns: 'config.system.sessions'
},
{
ident: 'collection-3a08494b-88c2-4161-b21d-1fc6e1ae0415',
ns: 'local.startup_log'
}
]全新的 mongod 也有 WiredTiger 的元数据文件、目录与日志目录,还有 3 个系统集合各自的文件(admin.system.version、config.system.sessions、local.startup_log)。
collection-b2fc5b04-a259-4463-ad47-67facdf1c247.wt 364,544 index-d6f15f7d-a8e2-4e93-8f82-521f8101de0e.wt 217,088 index-dad9ea92-0169-4642-b98a-b1d767192cae.wt 258,048 index-e79c39cf-669c-40aa-b55a-5d02687ce16a.wt 110,592 internal-sideWrites-dad9ea92-0169-4642-b98a-b1d767192cae.wt 4,096 internal-sideWrites-e79c39cf-669c-40aa-b55a-5d02687ce16a.wt 4,096 collStats 里的 wiredTiger.uri = statistics:table:collection-b2fc5b04-a259-4463-ad47-67facdf1c247 索引 _id_ → statistics:table:index-d6f15f7d-a8e2-4e93-8f82-521f8101de0e 索引 age_1 → statistics:table:index-e79c39cf-669c-40aa-b55a-5d02687ce16a 索引 city_1_name_1 → statistics:table:index-dad9ea92-0169-4642-b98a-b1d767192cae
每个集合是一个 collection-<ident>.wt,每个索引是一个 index-<ident>.wt;建索引时还会出现 internal-sideWrites-*.wt。
test> db.getSiblingDB("admin").aggregate([{$listCatalog: {}}, {$match: {db: "test", name: "users"}}, {$project: {_id: 0, ns: 1, ident: 1, idxIdent: 1}}])
[
{
idxIdent: {
_id_: 'index-d6f15f7d-a8e2-4e93-8f82-521f8101de0e',
age_1: 'index-e79c39cf-669c-40aa-b55a-5d02687ce16a',
city_1_name_1: 'index-dad9ea92-0169-4642-b98a-b1d767192cae'
},
ident: 'collection-b2fc5b04-a259-4463-ad47-67facdf1c247',
ns: 'test.users'
}
]文件名里的 ident 不是顺序号。collStats 的 wiredTiger.uri 和聚合的 $listCatalog 都能把集合、索引和文件名对上。
WiredTiger 的内容:
WiredTiger
WiredTiger 12.0.0: (November 15, 2024)
mongod.lock 的内容: '96042'(mongod 进程号 96042)
WiredTiger.turtle 共 6 行,前面的几行:
WiredTiger version string
WiredTiger 12.0.0: (November 15, 2024)
WiredTiger version
major=12,minor=0,patch=0
file:WiredTiger.wt
access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,durable_timestamp=non
storage.bson 解码: {'storage': {'engine': 'wiredTiger', 'options': {'directoryPerDB': False, 'directoryForIndexes': False, 'groupCollections': False}}}WiredTiger 记版本串,mongod.lock 是进程号,WiredTiger.turtle 是元数据引导,storage.bson 记存储引擎与目录布局选项(这里都是默认值)。
WiredTigerLog.0000000001 104,857,600 WiredTigerPreplog.0000000001 104,857,600 WiredTigerLog.0000000001: 文件大小 104,857,600,实际占用磁盘 557,056(du 看到的) metrics.2026-10-12T01-18-45Z-00000 39,522
journal 日志文件预分配 100 MiB,但实际占用磁盘很小;diagnostic.data 存 FTDC 的 metrics 文件。
drop 之前 25 个条目,之后 19 个;消失的: ['collection-b2fc5b04-a259-4463-ad47-67facdf1c247.wt', 'index-d6f15f7d-a8e2-4e93-8f82-521f8101de0e.wt', 'index-dad9ea92-0169-4642-b98a-b1d767192cae.wt', 'index-e79c39cf-669c-40aa-b55a-5d02687ce16a.wt', 'internal-sideWrites-dad9ea92-0169-4642-b98a-b1d767192cae.wt', 'internal-sideWrites-e79c39cf-669c-40aa-b55a-5d02687ce16a.wt'] 新增的: []
drop 集合后它的数据文件、索引文件和 sideWrites 文件都被删除,全局文件保留。