Skip to content

Sentry 磁盘空间清理

保留日志

Sentry 在运行时候会产生大量的日志, 日志存在 PG 数据库中所以需要先从 pg 数据库中删除, 项目中考虑保留 90 天的日志

docker-compose run --rm worker cleanup --days 30

在 postgre 数据库删除后依然占用磁盘空间

postgre 占用磁盘问题

getsentry/self-hosted/issues/783

postgre 删除数据后,并没有释放磁盘空间,可以使用以下命令来进行释放

vacuumdb -U postgres -d postgres -v -f --analyze

手动清理

  • 保留30天的数据
delete from nodestore_node where "timestamp" < NOW() - '30 days'::interval;
  • 释放磁盘空间
vacuumdb -U postgres -d postgres -v -f --analyze

定时清理 postgre 垃圾数据

命令如下 :

docker exec $(docker ps --format "table {{.Names}}"|grep postgres) vacuumdb -U postgres -d postgres -v -f --analyze;

crontab配置

每隔3天的9点执行一次清理

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

0 9 */3 * * docker exec -i $(docker ps --format "table {{.Names}}"|grep postgres) vacuumdb -U postgres -d postgres -v -f --analyze &> /webdata/logs/docker-vacuumdb.log