欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

clickhouse數(shù)據(jù)庫刪除數(shù)據(jù)的五種方式

 更新時間:2024年03月05日 10:27:18   作者:小馬穿云  
clickhouse數(shù)據(jù)庫清理數(shù)據(jù)的方式很多,每種方式都各有自己的優(yōu)缺點,請根據(jù)實際需要采用適合自己的方式,本文將逐一給大家介紹,并通過代碼示例講解的非常詳細,需要的朋友可以參考下

前言

clickhouse數(shù)據(jù)庫清理數(shù)據(jù)的方式很多,每種方式都各有自己的優(yōu)缺點,請根據(jù)實際需要采用適合自己的方式,下面逐一介紹。

一、通過刪除表分區(qū)的方式

##查詢某表分區(qū)
ck001 :) select database,table,partition,name, bytes_on_disk  from system.parts where table='ck_test1';

┌─database─┬─table┬─partition─┬─name────┬─bytes_on_disk─┐
│ default  │ ck_test1 │ 202302    │ 202302_3_3_0 │           221 │
│ default  │ ck_test1 │ 202301    │ 202301_4_4_0 │           232 │
└──────────┴────────────────────┴───────────┴

##刪除某表分區(qū)
ck001 :) alter table ck_test1 drop partition 202301;

二、執(zhí)行delete方式

該方式為異步執(zhí)行,并非實時。

## DELETE操作
-- 刪除記錄
alter table ck_table01 delete where id='11';
-- 刪除分片表數(shù)據(jù)
alter table ck_table01 on cluster main_cluster where create_date>< '2023-02-02 15:00:00';

三、執(zhí)行truncate方式

truncate適用于刪除全表數(shù)據(jù)的情況,而且效率比DELETE更高。

truncate table default.ck_table01;

四、設(shè)置表數(shù)據(jù)生命周期

--設(shè)置白鷗ck_table01的TTL為30分鐘
create table default.ck_table01
(
    id Int64,
    name Nullable(String),
    address Nullable(String),
    create_date Date
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(create_date)
ORDER BY id
TTL toDate(create_date) + toIntervalMinute(30)

toIntervalMinute:n分鐘過期

toIntervalDay:n天過期

toIntervalMonth:n月過期

五、刪除數(shù)據(jù)文件目錄

clickhouse數(shù)據(jù)目錄和元數(shù)據(jù)目錄是分開的,所以刪除數(shù)據(jù)目錄文件并不影響表結(jié)構(gòu)。下面以清空全部表數(shù)據(jù)為例。

1、停止clickhoue數(shù)據(jù)庫

systemctl stop clickhouse-server

2、刪除數(shù)據(jù)文件目錄

rm -rf /opt/clickhouse/data/default/

3、啟動clickhouse數(shù)據(jù)庫

systemctl start clickhouse-server

總結(jié)

方法三、五將清理全部數(shù)據(jù),請確保數(shù)據(jù)安全,根據(jù)實際場景謹慎應(yīng)用。

到此這篇關(guān)于clickhouse數(shù)據(jù)庫刪除數(shù)據(jù)的五種方式的文章就介紹到這了,更多相關(guān)clickhouse刪除數(shù)據(jù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論