I noticed that our Rocket.Chat database has become pretty big:
server ~ # du -sh /var/lib/mongodb
5,3G /var/lib/mongodb
The main reason for this seems to be the rocketchat_integration_history collection:
rocketchat.rocketchat_integration_history: 2.9 GB (3.0 GB)
rocketchat.rocketchat_uploads.chunks: 685.5 MB (752.9 MB)
rocketchat.rocketchat_message: 83.1 MB (118.2 MB)
rocketchat.rocketchat_oembed_cache: 45.0 MB (79.7 MB)
rocketchat.rocketchat__trash: 23.2 MB (79.8 MB)
rocketchat.rocketchat_statistics: 14.0 MB (21.5 MB)
> db.rocketchat_integration_history.stats()
{
"ns" : "rocketchat.rocketchat_integration_history",
"count" : 309355,
"size" : 3108092240,
"avgObjSize" : 10047,
"numExtents" : 21,
"storageSize" : 3189919696,
"lastExtentSize" : 536600560,
"paddingFactor" : 1,
"paddingFactorNote" : "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only.",
"userFlags" : 1,
"capped" : false,
"nindexes" : 2,
"totalIndexSize" : 31600240,
"indexSizes" : {
"_id_" : 16082192,
"_updatedAt_1" : 15518048
},
"ok" : 1
}
Apparently it stores every message that has ever passed through an integration and old entries aren't automatically purged :(
In our case this means every message ever, because we have a Redmine integration that looks up Redmine ticket IDs, and it's configured for the channels all_public_channels, all_private_groups, all_direct_messages.
I've looked in the configuration for any way on how to disable this history (we don't need it at all), but apparently there's no way.
db.rocketchat_integration_history collection only grows.db.rocketchat_integration_history collection should be automatically pruned to remove older entries.db.rocketchat_integration_history grows to enormous size.
In the meantime - is there any way to get rid of the history entries? Is it safe to just empty the whole collection like this?
db.rocketchat_integration_history.deleteMany({})
For now, yes you should be able to drop the database until we implement the options to control how the history works. Which will be soon since we are working on adding history support to incoming integrations.
For now, yes you should be able to drop the database until we implement the options to control how the history works.
So even db.rocketchat_integration_history.drop() would be safe? Wouldn't this remove the whole collection, and not only the containing documents? Does Rocket.Chat then automatically recreate the collection? I'm not very familiar with MongoDB, and I want to be sure that I don't accidentally kill our database :)
db.rocketchat_integration_history.remove({}) worked fine. I've put that into a cronjob:
server /etc/cron.daily # cat _rocketchat_keep_integration_history_empty
#!/bin/sh
# https://github.com/RocketChat/Rocket.Chat/issues/9617
mongo rocketchat --eval 'db.rocketchat_integration_history.remove({})' --quiet | grep -v '^WriteResult' || true
Most helpful comment
db.rocketchat_integration_history.remove({})worked fine. I've put that into a cronjob: