Clickhouse 监控运维常用SQL小结

@羲凡——只为了更好的活着

Clickhouse 监控运维常用SQL小结

必须准备: 在users.xml中开启 <log_queries>1</log_queries>

1、查看磁盘空间
SELECT
    name,
    path,
    formatReadableSize(free_space) AS free_space,
    formatReadableSize(total_space) AS total_space,
    type
FROM system.disks
2、查看表大小
SELECT
table,
formatReadableSize(sum(data_compressed_bytes)) AS compressed_size ,
formatReadableSize(sum(data_uncompressed_bytes)) AS uncompressed_bytes
FROM system.parts
WHERE active AND (table LIKE 'data_%') --and partition like '(21,%)'
GROUP BY table 
order by uncompressed_bytes desc ;
3、查看列大小
select column,any(type), 	
formatReadableSize(sum(column_data_compressed_bytes)) compressed_size , 	
formatReadableSize(sum(column_data_uncompressed_bytes)) uncompressed_bytes, 	
sum(rows) 
from system.parts_columns 
where table ='data_report_local' and active --and partition like '(21,%)'
GROUP BY column
ORDER BY uncompressed_bytes desc ;
4、查看总连接数
SELECT * FROM system.metrics WHERE metric LIKE '%Connection';
5、查看正在执行的查询语句
SELECT query_id, user, address, elapsed, query
FROM system.processes
ORDER BY query_id ASC
6、kill 指定的查询语句
KILL QUERY WHERE query_id='query_id';
7、查看正在后台执行的更新语句
SELECT database,table,mutation_id,command,create_time,parts_to_do_names,parts_to_do,latest_fail_reason 
FROM system.mutations
where is_done<>1
8、kill 指定的更新语句
KILL MUTATION mutation_id = 'mutation_id';
9、手动合并parts
OPTIMIZE TABLE table [PARTITION partition] [FINAL]
10、今天前十的慢查询
SELECT
    user,
    formatDateTime(query_start_time, '%Y%m%d %T') AS start_time,
    query_duration_ms / 1000 AS query_duration_s,
    formatReadableSize(memory_usage ) AS memory_usage,
    result_rows ,
    formatReadableSize(result_bytes) AS result_bytes,
    read_rows ,
    formatReadableSize(read_bytes) AS read_bytes,
    written_rows ,
    formatReadableSize(written_bytes) AS written_bytes,
    query
FROM system.query_log
WHERE type = 2
and query_start_time>=today()
ORDER BY query_duration_s DESC
LIMIT 10
11、查看副本表是否异常
SELECT database, table, is_leader, total_replicas, active_replicas, zookeeper_exception 
FROM system.replicas 
WHERE is_readonly 
OR is_session_expired 
OR future_parts > 20 
OR parts_to_check > 10 
OR queue_size > 20 
OR inserts_in_queue > 10 
OR log_max_index - log_pointer > 10 
OR total_replicas < 2 
OR active_replicas < total_replicas;
12、修改TTL时间
alter table TABLE_NAME on cluster CLUSTER_NAME modify ttl create_time + tointervalday(30);
13、删除分区
-- delete 有时候删除不了就用下面的语句
alter table TABLE_NAME on cluster CLUSTER_NAME delete where task_id='136' ;
-- drop partition 如果分区字段有三个必须都写上,一定能删
alter table TABLE_NAME on cluster CLUSTER_NAME drop partition (136,'2213160');

|
|
|

====================================================================

@羲凡——只为了更好的活着

若对博客中有任何问题,欢迎留言交流

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值