当前位置:网站首页>Clickhouse disables automatic clearing of tables / columns, that is, disables TTL

Clickhouse disables automatic clearing of tables / columns, that is, disables TTL

2022-06-25 20:04:00 The ninth tree

1、 Problem solving

Found in the morning clickhouse There is no data in the table , After some screening , Found to be TTL( Life cycle ) The pot .

It may be installation clickhouse It was configured carelessly , But a search is all about revision TTL The time of the , That is, when the data in the table is automatically deleted , But you don't want to delete data automatically .

Found clues in official documents :
 Insert picture description here
Just run this under the desired table

#  Discontinue use TTL
SYSTEM STOP TTL MERGES
#  Turn on TTL
SYSTEM START TTL MERGES

2、 test

according to clickhouse Secondary data TTL Test code in :

Create a containing TTL by 30 Second data table , That is, the data in the table 30 Seconds automatically delete !

CREATE TABLE stu
(
    id Int32 ,
    name String ,
    create_time DateTime

)
ENGINE = MergeTree
PARTITION BY toYYYYMM(create_time)
ORDER BY id    TTL create_time + INTERVAL 30 second

insert data :

insert into  stu values
(100,'tom',now()),
(101,'jack',now()),
(102,'mary',now()),
(103,'lili','2021-08-18 07:12:34');

adopt datagrip The software observes the tables created , And inserted data
 Insert picture description here
wait for 30 Second, you will find that the data will be deleted , Explain the TTL It's on , If you want to disable , that :

#  Discontinue use TTL
SYSTEM STOP TTL MERGES

 Insert picture description here

It will not be cleared automatically after waiting for 30 seconds .

complete

原网站

版权声明
本文为[The ninth tree]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190509181212.html