首页 > 数据库 >Mongodb存储二进制文件GridFS空间复用测试

Mongodb存储二进制文件GridFS空间复用测试

时间:2023-03-10 10:31:43浏览次数:34  
标签:... Mon01 mongo Mongodb 复用 filename mongodb GridFS test


Oracle可以存储二进制文件,测试后发现lob字段再数据delete后表空间不能被复用,考虑将数据存储在mongodb中,mongodb存在GridFS,测试GridFS是否也存在相同的情况

mongofiles命令介绍

Possible commands include:
list - list all files; 'filename' is an optional prefix which listed filenames must begin with
search - search all files; 'filename' is a substring which listed filenames must contain
put - add a file with filename 'filename'
put_id - add a file with filename 'filename' and a given '_id'
get - get a file with filename 'filename'
get_id - get a file with the given '_id'
delete - delete all files with filename 'filename'
delete_id - delete a file with the given '_id'

mongodb数据库初始化后空间占用情况

[mongo@Mon01 mongodb]$ du -sh *
1.1G data
1.4M log
4.0K mongodb.pid
4.0K mongodb.yaml
4.0K secret

数据写入

写入两个文件test1大小1GB,test.log大小5GB

[mongo@Mon01 ~]$ mongofiles -u test -p test --authenticationDatabase test put test1
2022-08-11T14:56:51.882+0800 connected to: localhost
added file: test1
[mongo@Mon01 ~]$ mongofiles -u test -p test --authenticationDatabase test put test.log
2022-08-11T15:00:34.925+0800 connected to: localhost
added file: test.log

GridFS存储相关表

MongoRepl:SECONDARY> show tables;
fs.chunks
fs.files

主要存储数据的集合fs.chunks

MongoRepl:PRIMARY> db.fs.chunks.stats()
{
"ns" : "test.fs.chunks",
"size" : 3802809920,
"count" : 14560,
"avgObjSize" : 261182,
"storageSize" : 594558976,
"capped" : false,
"wiredTiger" : {
"metadata" : {
"formatVersion" : 1
},
"creationString" :
"type" : "file",
"uri" : "statistics:table:collection-0-1779480531914116713",
},
}

写入期间,观察文件大小变化

[mongo@Mon01 mongodb]$ du -sh *
2.2G data
1.6M log
4.0K mongodb.pid
4.0K mongodb.yaml
4.0K secret

观察集合fs.chunks数据文件大小变化

[mongo@Mon01 data]$ du -ch *
865M collection-0-1779480531914116713.wt
... ...
200M diagnostic.data
... ...
301M journal
... ...
230M WiredTigerLAS.wt
... ...
2.4G total

查看当前写入的文件

[mongo@Mon01 ~]$ mongofiles -u test -p test --authenticationDatabase test list
2022-08-11T15:09:52.043+0800 connected to: localhost
test1 1048576000
test.log 5776622690

数据删除

删除文件

[mongo@Mon01 ~]$ mongofiles -u test -p test --authenticationDatabase test delete test1
2022-08-11T15:11:21.229+0800 connected to: localhost
successfully deleted all instances of 'test1' from GridFS
[mongo@Mon01 ~]$ mongofiles -u test -p test --authenticationDatabase test delete test.log
2022-08-11T15:11:31.479+0800 connected to: localhost
successfully deleted all instances of 'test.log' from GridFS

删除文件后,观察文件大小变化,一段事件后空间会自动回收,集合对应数据文件变小

[mongo@Mon01 data]$ du -ch *
12K collection-0-1779480531914116713.wt
... ...
796M collection-8--2049863378525224046.wt
... ...
200M diagnostic.data
... ...
301M journal
... ...
432M WiredTigerLAS.wt
... ...
144K WiredTiger.wt
1.7G total

总结:

Mongodb存储二进制文件可以正常进行增删,数据删除后空间可自动回收。

Tips:

journal类似Oracle或MySQL的Redo
WiredTiger是Mongodb的存储引擎,值得研究


标签:...,Mon01,mongo,Mongodb,复用,filename,mongodb,GridFS,test
From: https://blog.51cto.com/u_14852239/6112561

相关文章

  • MongoDb服务搭建
    参考官网教程:https://www.mongodb.com/docs/v4.4/tutorial/install-mongodb-on-red-hat/1、配置yum仓库,安装[mongodb-org]name=MongoDBRepositorybaseur......
  • MongoDB的安装
    ......
  • mongodb进程down,无报错
    背景操作系统:CentOS7.5MongoDB:4.4.7现网有mongodb分片集群共3个节点(3个分片副本集,不包括config副本集),后续因业务增长需扩容3个新节点(新增3个分片副本集)。扩容的服务器......
  • 改变容器存储位置后启动mongo失败,报错Failed to unlink socket file tmpmongodb-27017
    一.改变容器存储位置默认存储位置是/var/lib/docker1.停止dockersystemctlstopdocker有时候会报错Warning:Stoppingdocker.service,butitcanstillbeactiva......
  • percona-server-mongodb-6.0源码安装
    ###################################请注意,预构建的二进制文件可在 mongodb.org上获得,这可能是最简单的入门方式,而不是从源代码构建。要构建MongoDB,您需要:能够编译......
  • MongoDB找出冗余和未被使用的索引
    找出冗余的索引varldb=db.adminCommand({listDatabases:1});for(i=0;i<ldb.databases.length;i++){if(ldb.databases[i].name!='admin'&&......
  • 【MongoDB】移除复制集成员
    1.使用rs.remove()(1)关闭mongodb实例先关闭要移除的mongodb实例db.shutdownServer()(2)连接到复制集的primary节点使用db.hello()查看复制集的信息>db.hello(){......
  • 巧用 CSS 变量,实现动画函数复用,制作高级感拉满的网格动画
    本文将介绍一种基于CSS变量技巧,通过合理使用CSS变量,实现CSS动画@keyframes的复用。CSS变量CSS变量大家应该都比较熟悉了,已经不能算是新知识了,快速过一遍。CSS......
  • MongoDB :第三章:MongoDB的数据类型与创建MongoDB数据库
    元数据数据库的信息是存储在集合中。它们使用了系统的命名空间:dbname.system.*在MongoDB数据库中名字空间.system.*是包含多种系统信息的特殊集合(Collection),如下:......
  • mongodb 数据库
      一、简介MongoDB是一款流行的开源文档型数据库,从它的命名来看,确实是有一定野心的。 MongoDB的原名一开始来自于英文单词"Humongous",中文含义是指"庞大",即命......