MongoDB整理筆記の管理Sharding

來源:互聯網
上載者:User

標籤:

    1、列出所有的Shard Server

> db.runCommand({ listshards: 1 }) --列出所有的Shard Server{"shards" : [{"_id" : "shard0000","host" : "localhost:20000"},{"_id" : "shard0001","host" : "localhost:20001"}],"ok" : 1}
View Code

    2、查看Sharding資訊

> printShardingStatus() --查看Sharding 資訊--- Sharding Status ---sharding version: { "_id" : 1, "version" : 3 }shards:{ "_id" : "shard0000", "host" : "localhost:20000" }{ "_id" : "shard0001", "host" : "localhost:20001" }databases:{ "_id" : "admin", "partitioned" : false, "primary" : "config" }{ "_id" : "test", "partitioned" : true, "primary" : "shard0000" }test.users chunks:shard0000 1{ "_id" : { $minKey : 1 } } -->> { "_id" : { $maxKey : 1 } } on :shard0000 { "t" : 1000, "i" : 0 }>
View Code

    3、判斷是否是Sharding

> db.runCommand({ isdbgrid:1 }){ "isdbgrid" : 1, "hostname" : "localhost", "ok" : 1 }>

    4、對現有的集合進行分區(執行個體)

    剛才我們是對錶test.users 進行分區了,下面我們將對庫中現有的未分區的表test.users_2 進行分區處理。

    表最初狀態如下,可以看出他沒有被分區過:

> db.users_2.stats(){"ns" : "test.users_2","sharded" : false,"primary" : "shard0000","ns" : "test.users_2","count" : 500000,"size" : 48000016,"avgObjSize" : 96.000032,"storageSize" : 61875968,"numExtents" : 11,"nindexes" : 1,"lastExtentSize" : 15001856,"paddingFactor" : 1,"flags" : 1,"totalIndexSize" : 20807680,"indexSizes" : {"_id_" : 20807680},"ok" : 1}
View Code

    對其進行分區處理:

> use adminswitched to db admin> db.runCommand({ shardcollection: "test.users_2", key: { _id:1 }}){ "collectionsharded" : "test.users_2", "ok" : 1 }

    再次查看分區後的表的狀態,可以看到它已經被我們分區了

> use testswitched to db test> db.users_2.stats(){"sharded" : true,"ns" : "test.users_2","count" : 505462,……"shards" : {"shard0000" : {"ns" : "test.users_2",……"ok" : 1},"shard0001" : {"ns" : "test.users_2",……"ok" : 1}},"ok" : 1}>
View Code

MongoDB整理筆記の管理Sharding

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.