admin管理员组文章数量:1532656
文章目录
- 1. 修改 Sentry 程序根目录下 `.env` 配置
- 2. 数据软清理
- 3. PostgreSQL 数据清理
- 4. `crontab` 添加定时清理
- 5. 当第2或第3步一直耗时过长,无法完成,可以直接新建空表 `nodestore_node` ,然后删除旧表
1. 修改 Sentry 程序根目录下 .env
配置
SENTRY_EVENT_RETENTION_DAYS=7
2. 数据软清理
进入 worker 容器:
docker exec -it sentry_onpremise_worker_1 /bin/bash
保留多少天的数据,cleanup 使用 delete 命令删除postgresql数据,但对于 delete、update 等操作,只是将对应行标志为 DEAD,并没有真正释放磁盘空间:
sentry cleanup --days 7
3. PostgreSQL 数据清理
进入 PostgreSQL 容器:
docker exec -it sentry_onpremise_postgres_1 /bin/bash
运行清理:
vacuumdb -U postgres -d postgres -v -f --analyze
4. crontab
添加定时清理
0 16 * * 5 cd /App/sentry && { time docker-compose run --rm worker cleanup --days 7; } &> /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.log
5. 当第2或第3步一直耗时过长,无法完成,可以直接新建空表 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;
版权声明:本文标题:Sentry 清理数据 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1726092065a1055075.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论