Sentry 服务磁盘占满 清除postgresql方法

Sentry服务运行一段时间后

磁盘会占满 86%


so... 我们ssh 到主机

docker ps复制代码


运行以下命令进入到sentry ,,1f916f730069参数就是左边的id

docker exec -it 1f916f730069 /bin/bash


复制代码

sentry的cleanup工具操作帮助为

root@9acfe6561812:/# sentry cleanup --help
Usage: sentry cleanup [OPTIONS]

  Delete a portion of trailing data based on creation date.

  All data that is older than `--days` will be deleted.  The default for this is 30 days.  In
  the default setting all projects will be truncated but if you have a specific project you want
  to limit this to this can be done with the `--project` flag which accepts a project ID or a
  string with the form `org/project` where both are slugs.

Options:
  --days INTEGER         Numbers of days to truncate on.  [default: 30]
  --project TEXT         Limit truncation to only entries from project.
  --concurrency INTEGER  The number of concurrent workers to run.  [default: 1]
  -q, --silent           Run quietly. No output on success.
  -m, --model TEXT
  --help                 Show this message and exit.
复制代码

运行以下命令开始删除

sentry cleanup --days 7复制代码

要删好久。。。


再运行df -h 发现还是很满。这是因为cleanup的使用delete命令删除postgresql数据,但postgrdsql对于delete, update等操作,只是将对应行标志为DEAD,并没有真正释放磁盘空间。


然后exit 退出当前docker

再运行以下命令进入 数据库的docker

docker exec -it 176e1501e871 /bin/bash复制代码

进来后执行命令

vacuumdb -U postgres -d postgres -v -f --analyze
复制代码

删完后。。


成功搞定!

最后 人工改自动!

我们使用 crontab 在linux实现定时任务

crontab -e复制代码

在里面输入:

0 0 * * *  docker exec -it onpremise_web_1 sentry cleanup --days 7  && docker exec -it onpremise_postgres_1 vacuumdb -U postgres -d postgres -v -f --analyze复制代码

这句话的意思是每天清理,超过7天的。

保存!


分类:
前端
标签: