1. 修改 Sentry 程序根目录下 .env 配置
SENTRY_EVENT_RETENTION_DAYS=142. 数据软清理
进入 worker 容器:
docker exec -it sentry_onpremise_worker_1 /bin/bash保留多少天的数据,cleanup 使用 delete 命令删除postgresql数据,但对于 delete、update 等操作,只是将对应行标志为 DEAD,并没有真正释放磁盘空间:
sentry cleanup --days 143. PostgreSQL 数据清理
进入 PostgreSQL 容器:
docker exec -it sentry_onpremise_postgres_1 /bin/bash运行清理:
vacuumdb -U postgres -d postgres -v -f --analyze4. crontab 添加定时清理,根据公司数据量调整时间
0 16 * * 5 cd /App/sentry && { time docker-compose run --rm worker cleanup --days 14; } &> /tmp/sentry-cleanup.log
0 16 * * 6 { time docker exec -i $(docker ps --format "table {{.Names}}" | grep postgres) vacuumdb -U postgres -d postgres -v -f --analyze; } &> /tmp/sentry-vacuumdb.log5. 当第三步清理数据库一直耗时过长,无法完成,可以直接新建空表 nodestore_node ,然后再执行第三步清理
进入 PostgreSQL 容器:
docker exec -it sentry_onpremise_postgres_1 /bin/bash登录 PostgreSQL 数据库:
su - postgres
psql删除表前后可以先查看下该表占用的空间,一般 nodestore_node 数据表占用磁盘空间最大:
SELECT
    table_schema || '.' || table_name AS table_full_name,
    pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS size
FROM information_schema.tables
ORDER BY
pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC limit 10;新建备份表结合重命名方式,可以实现不影响 Sentry 服务正常运行时删除数据。此操作可能耗时较长,可以使用 tmux 或者 screen 工具后台执行:
ALTER TABLE nodestore_node RENAME TO nodestore_node_old;
CREATE TABLE nodestore_node (LIKE nodestore_node_old INCLUDING ALL);
ALTER TABLE nodestore_node_old DISABLE TRIGGER ALL;
DROP TABLE nodestore_node_old CASCADE;









