ClickHouse multiple volume stora

2019-11-06  本文已影响0人  白奕新

0、what's this

在ClickHouse中可以配置存储策略,配置多块盘与盘存储空间的阈值,当达到空间阈值时自动触发数据迁移。

1、config

配置在config.xml里面

<storage_configuration>
    <disks> <!-- 可以在这个节点下配置磁盘信息 -->
        <fast_disk> <!-- disk name,自定义 -->
            <path>/mnt/fast_ssd/clickhouse</path>
        </fast_disk>
        <disk1>
            <path>/mnt/hdd1/clickhouse</path>
            <keep_free_space_bytes>10485760</keep_free_space_bytes>
        </disk1>
        <disk2>
            <path>/mnt/hdd2/clickhouse</path>
            <keep_free_space_bytes>10485760</keep_free_space_bytes>
        </disk2>
    </disks>
    
    <policies>
       <!--定义的第一个policy-->
       <hdd_in_order> 
            <volumes>
                <single> 
                    <disk>disk1</disk>
                    <disk>disk2</disk>
                </single>
            </volumes>
        </hdd_in_order>
        
       <!--定义的第二个policy-->
        <moving_from_ssd_to_hdd><!-- policy name,自定义 -->
            <volumes>
                <hot><!-- volume name,自定义 -->
                    <disk>fast_disk</disk>
                    <max_data_part_size_bytes>1073741824</max_data_part_size_bytes>
                </hot>
                <cold>
                    <disk>disk1</disk>
                </cold>            
            </volumes>
            <move_factor>0.2</move_factor>
        </moving_from_ssd_to_hdd>
    </policies>    
</storage_configuration>
参数 含义 其他
keep_free_space_bytes 最少需要保留多少磁盘空间
max_data_part_size_bytes 定义part的最大大小,超过阈值直接移到下一个盘里面
move_factor 定义百分比,剩余空间低于阈值直接移到下一个盘里面 默认是0.1

2、detail

3、how to use


CREATE TABLE table_with_non_default_policy (
    EventDate Date,
    OrderID UInt64,
    BannerID UInt64,
    SearchPhrase String
) ENGINE = MergeTree
ORDER BY (OrderID, BannerID)
PARTITION BY toYYYYMM(EventDate) 
SETTINGS storage_policy = '{POLICY-NAME}'

当没有配置storage_policy的时候,则默认选择config.xml里面的<path>作为存储路径。

4、move partition manually

ALTER TABLE table_name MOVE PARTITION|PART partition_expr TO DISK|VOLUME 'disk_name'

example

(1)ALTER TABLE hits MOVE PART '20190301_14343_16206_438' TO VOLUME 'slow'
(2)ALTER TABLE hits MOVE PARTITION '2019-09-01' TO DISK 'fast_ssd'
上一篇 下一篇

猜你喜欢

热点阅读