当前位置:网站首页>【ClickHouse】 日志清理方法(query_log、query_thread_log)
【ClickHouse】 日志清理方法(query_log、query_thread_log)
2022-08-09 13:20:00 【qq_duhai】
一、背景
ClickHouse中的query_log、query_thread_log、trace_log等日志表,在开启之后,如果一段时间没有清理,这些日志表会占用大量的存储空间,query_log是最常用的查询日志,它记录了ClickHouse服务中所有已经执行的查询记录,下图为query_log表中的部分内容。ClickHouse默认不清理日志,这里需要自己配置。
二、解决方案
查了些资料发现,大家基本都是通过设置相应日志表的TTL来清理,如
ALTER TABLE system.query_log on cluster cluster_name MODIFY TTL event_date + INTERVAL 15 DAY
保存一个月的数据
ALTER TABLE query_log MODIFY TTL event_date + toIntervalMonth(1);
ALTER TABLE query_thread_log MODIFY TTL event_date + toIntervalMonth(1);
保存15天的数据
ALTER TABLE query_log MODIFY TTL event_date + toIntervalDay(15);
ALTER TABLE query_thread_log MODIFY TTL event_date + toIntervalDay(15);
这样处理虽然也可以,但是不太安全也不太方便
官方资料建议:直接在配置文件中设置
query_log 配置参数
使用下列参数进行日志配置(配置文件位置 /etc/clickhouse-server/config.xml)
- database – 数据库名
- table – 日志存放的系统表名
- partition_by — 系统表分区键,如果定义了 engine 则不能使用
- engine -系统表 表引擎,如果定义了 partition_by 则不能使用
- flush_interval_milliseconds – 将数据从内存的缓冲区刷新到表的时间间隔。
<query_log>
<database>system</database>
<table>query_log</table>
<engine>Engine = MergeTree PARTITION BY event_date ORDER BY event_time TTL event_date + INTERVAL 30 day</engine>
<flush_interval_milliseconds>7500</flush_interval_milliseconds>
</query_log>
边栏推荐
- RobotFramework 之 库与关键字
- Operating system migration practice deploying MySQL database on openEuler
- TCP三次握手和四次挥手及拥塞控制
- pyhook3简单应用(1)--实现截图保存功能
- 易语言获取cookie
- Q_06_02 类型模型
- The sword refers to Offer 56 - II. Number of occurrences of a number in an array II (bit operation)
- An Offer 21. Adjust the array in order to make odd in even the front (loop invariant)
- Where to go to IOE-EBS
- 笔试题记录~~
猜你喜欢
随机推荐
蓝桥历届真题-门牌制作
Jetpack Compose——remember、mutableStateOf、rememberSaveable
2个有序数组排序
PO、DO、TO、VO、DO、DTO、DAO、POJO都是什么?
puzzle(016.5)逻辑电路
从房产中介到程序员--80后张江男
Q_06_02 类型模型
pyautogui的简单操作(1)
RobotFramework 之 条件判断
音视频录入的pts和dts问题
三种ThreadLocal,玩转线程变量保存与传递
RobotFramework 之 Evaluate
RTP打包发送H.264
openharmony容器组件之GridContainer
常用函数
RobotFramework 之 Setup和Teardown
对百度的内容进行修改
tkiner-canvas显示图片
RobotFramework 之 RF变量与标准库关键字使用
蓝桥历届真题-蛇形填数