Sentry 服務磁盤佔滿 清除postgresql方法

Sentry服務運行一段時間後

磁盤會佔滿 86%javascript


so... 咱們ssh 到主機java

docker ps複製代碼


運行如下命令進入到sentry ,,1f916f730069參數就是左邊的idlinux

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.
複製代碼

運行如下命令開始刪除
web

sentry cleanup --days 7複製代碼

要刪很久。。。sql


再運行df -h 發現仍是很滿。這是由於cleanup的使用delete命令刪除postgresql數據,但postgrdsql對於delete, update等操做,只是將對應行標誌爲DEAD,並無真正釋放磁盤空間。docker


而後exit 退出當前docker數據庫

再運行如下命令進入 數據庫的dockerbash

docker exec -it 176e1501e871 /bin/bash複製代碼

進來後執行命令ssh

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天的。

保存!

相關文章
相關標籤/搜索