代码改变世界

mongodb索引大小查看

  abce  阅读(138)  评论(0编辑  收藏  举报

查看数据库中索引总大小

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
> db.stats()
{
        "db" : "abce",
        "collections" : 258,
        "views" : 0,
        "objects" : 3869336,
        "avgObjSize" : 23033.87034752216,
        "dataSize" : 89125783755,
        "storageSize" : 49488015360,
        "indexes" : 489,
        "indexSize" : 132325376,
        "totalSize" : 49620340736,
        "scaleFactor" : 1,
        "fsUsedSize" : 113261400064,
        "fsTotalSize" : 214643507200,
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1690778757, 1),
                "signature" : {
                        "hash" : BinData(0,"ncIYGefuLs7KvMS1Acb99Ya3qF0="),
                        "keyId" : NumberLong("7232354472649818114")
                }
        },
        "operationTime" : Timestamp(1690778757, 1)
}


查看单个集合的索引大小:

1
>  db.getCollection("集合名").totalIndexSize();


查看每个集合的索引大小:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
> db.getCollectionNames().map(name => ({totalIndexSize: db.getCollection(name).stats().totalIndexSize, name: name})).sort((a, b) => a.totalIndexSize - b.totalIndexSize).forEach(printjson)
{ "totalIndexSize" : 8192, "name" : "asset_day.v1" }
{ "totalIndexSize" : 8192, "name" : "asset_day.v1.__in__" }
{ "totalIndexSize" : 8192, "name" : "p_day.v1" }
{ "totalIndexSize" : 8192, "name" : "p_day.v1.__in__" }
{ "totalIndexSize" : 8192, "name" : "swap_asset_day.v1" }
...
{ "totalIndexSize" : 786432, "name" : "index.com_daily" }
{ "totalIndexSize" : 794624, "name" : "style_tvalue.v1" }
{ "totalIndexSize" : 1634304, "name" : "ret_day.v1" }
{ "totalIndexSize" : 1740800, "name" : "nav_day.v1" }
{ "totalIndexSize" : 2670592, "name" : "lag_ret" }
{ "totalIndexSize" : 17883136, "name" : "pos" }
{ "totalIndexSize" : 17956864, "name" : "ret" }
{ "totalIndexSize" : 17956864, "name" : "pre_wt" }
{ "totalIndexSize" : 18001920, "name" : "otr" }
{ "totalIndexSize" : 18055168, "name" : "ostatus" }
{ "totalIndexSize" : 18120704, "name" : "owt" }
>

 

查看指定集合中索引的详细信息

1
2
3
4
5
6
7
8
> db.<集合名>.stats().indexSizes
{
        "_id_" : 230862848,
        "groupId_1_userId_1" : 49971200,
        "createTime_1" : 180301824,
        "orderId_1" : 278528,
        "userId_1" : 50155520
}

 

查看指定索引的大小

1
> db.collection.stats({indexDetails: true}).indexSizes.index_name

 

相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2016-07-31 python中的yield
点击右上角即可分享
微信分享提示