• clickhouse日常维护


    1.查询正在执行的sql

    select query_id, user, address, query  FROM system.processes ORDER BY query_id;

    终止查询:
    kill query where query_id = 'query_id'

    2.查询mutations
    SELECT 和 INSERT 之外,在 ClickHouse 中还存在一类被称作 Mutation 的操作,也就是 ALTER DELETE 和 ALTER UPDATE

    SELECT database, table, mutation_id, command, create_time, is_done FROM system.mutations;

    终止mutation
    kill mutation where mutation_id = 'mutation_id';

    3.各数据库占用空间统计

    SELECT 
        database, 
        formatReadableSize(sum(bytes_on_disk)) AS on_disk
    FROM system.parts
    GROUP BY database;

    4.查看字段压缩比

    SELECT
        database,
        table,
        column,
        any(type),
        sum(column_data_compressed_bytes) AS compressed,
        sum(column_data_uncompressed_bytes) AS uncompressed,
        round(uncompressed / compressed, 2) AS ratio,
        compressed / sum(rows) AS bpr,
        sum(rows)
    FROM system.parts_columns
    WHERE active AND (database != 'system')
    GROUP BY
        database,
        table,
        column
    ORDER BY
        database ASC,
        table ASC,
        column ASC
    
    Query id: afcc3d43-73cb-4be6-a2c4-b0de1d0d88d4
    
    ┌─database────┬─table──┬─column────────┬─any(type)────────┬──compressed─┬─uncompressed─┬──ratio─┬──────────────────bpr─┬──sum(rows)─┐
    │ db_sentinel │ metric │ app           │ String           │   7563311023765177915649.780.52239873576554361447804235 │
    │ db_sentinel │ metric │ block_qps     │ Int64            │    5152350511582153888224.790.035587342372983181447804235 │
    │ db_sentinel │ metric │ count         │ Int64            │   2042649031158215388856.70.141085996339829741447804235 │
    │ db_sentinel │ metric │ exception_qps │ Int64            │    5411489811582153888214.030.037377220408531271447804235 │
    │ db_sentinel │ metric │ gmt_create    │ DateTime         │  146120454857910769443.961.00925561113585221447804235 │
    │ db_sentinel │ metric │ gmt_modified  │ DateTime         │  146120454857910769443.961.00925561113585221447804235 │
    │ db_sentinel │ metric │ id            │ Int64            │  5983378896115821538881.944.1327264773472641447804235 │
    │ db_sentinel │ metric │ machine_ip    │ Nullable(String) │  2310772922211360059999.151.59605343466894881447804235 │
    │ db_sentinel │ metric │ month         │ Date             │    129304872895538472223.930.0089311017936067851447804235 │
    │ db_sentinel │ metric │ pass_qps      │ Int64            │  3362071882115821538883.442.322186798963191447804235 │
    │ db_sentinel │ metric │ resource      │ String           │ 133768024221168620476898.749.2393723534038431447804235 │
    │ db_sentinel │ metric │ resource_code │ Int64            │  3054311246115821538883.792.10961618440078661447804235 │
    │ db_sentinel │ metric │ rt            │ Float64          │  3896826770115821538882.972.6915425965721121447804235 │
    │ db_sentinel │ metric │ success_qps   │ Int64            │  3361088814115821538883.452.32150779279907261447804235 │
    │ db_sentinel │ metric │ timestamp     │ DateTime         │    310106195791076944186.740.0214190691326441651447804235 │
    └─────────────┴────────┴───────────────┴──────────────────┴─────────────┴──────────────┴────────┴──────────────────────┴────────────┘
    
    15 rows in set. Elapsed: 0.057 sec. 

    5.慢查询

    SELECT 
        user, 
        client_hostname AS host, 
        client_name AS client, 
        formatDateTime(query_start_time, '%T') AS started, 
        query_duration_ms / 1000 AS sec, 
        round(memory_usage / 1048576) AS MEM_MB, 
        result_rows AS RES_CNT, 
        result_bytes / 1048576 AS RES_MB, 
        read_rows AS R_CNT, 
        round(read_bytes / 1048576) AS R_MB, 
        written_rows AS W_CNT, 
        round(written_bytes / 1048576) AS W_MB, 
        query
    FROM system.query_log
    WHERE type = 2
    ORDER BY query_duration_ms DESC
    LIMIT 10;

    6.表压缩大小

    SELECT
        database,
        table,
        sum(rows) AS `总行数`,
        formatReadableSize(sum(data_uncompressed_bytes)) AS `原始大小`,
        formatReadableSize(sum(data_compressed_bytes)) AS `压缩大小`,
        round((sum(data_compressed_bytes) / sum(data_uncompressed_bytes)) * 100., 2) AS `压缩率/%`
    FROM system.parts
    GROUP BY
        database,
        table
    ORDER BY database ASC
    
    Query id: d3c88c77-590b-40e7-9328-03406704c2c3
    
    ┌─database────┬─table──┬─────总行数─┬─原始大小───┬─压缩大小──┬─压缩率/%─┐
    │ db_sentinel │ metric │ 1447804235268.76 GiB │ 36.67 GiB │    13.65 │
    └─────────────┴────────┴────────────┴────────────┴───────────┴──────────┘
    
    1 rows in set. Elapsed: 0.024 sec. 
  • 相关阅读:
    for循环中break和continue的区别
    详解vue生命周期及每个阶段适合进行的操作
    ansible部署
    ansible介绍
    jenkins介绍和安装
    查看磁盘型号和内存及raid信息
    shell 概览
    day5 函数和参数
    day4(dict和set)
    day3(if和for)
  • 原文地址:https://www.cnblogs.com/hxlasky/p/15480822.html
Copyright © 2020-2023  润新知