ClickHouse多路径存储策略

ClickHouse多路径存储策略

要使用Clickhouse的多路径存储,需要ClickHouse的版本号在19.15之后。

自ClickHouse 19.15开始,ClickHouse支持所有MergeTree表引擎多路径存储。

多路径配置测试:

  1. 配置文件信息,path:/etc/clickhouse-server/config.d/${xxxx}.xml
    • 配置信息也可写/etc/clickhouse-server/config.xml
    • 需要注意的点
      • 1.若节点已部署clickhouse,因为config.xml已有默认的 信息,所以需要显示声明
      • 2.下的 需要以 /结尾
      • 3.删除或配置时,需要确保ch内已删除相应的table,不然重启ch时会报错。
      • 4.集群内的策略配置可以不同
    • xml配置
      • 磁盘的预留空间
      • 磁盘空间的预留因子,当磁盘free_size小于此阀值时,触发move操作
      • max_data_part_size_bytes分片阀值,分片大小超过此阀值时,触发move操作
<yandex>
    
	<storage_configuration>
    	<disks>
            
            <default>
                
            	<keep_free_space_bytes>322122547200keep_free_space_bytes>
            default>
            
        	<fast_disk>
                
            	<path>/clickhouse-ssd-data-1/fast-data/path>
            	<keep_free_space_bytes>322122547200keep_free_space_bytes>
            fast_disk>
            
            <hdd_disk>
            	<path>/clickhouse-hhd-data-1/hhd-data/path>
            hdd_disk>
        disks>
        <policies>
            
        	<hot_cold>
            	<volumes>
                    
                	<hot>
                        
                   	 	<disk>fast_diskdisk>
                      
               		 hot>
                    
                	<cold>
                    	<disk>hdd_diskdisk>
                	cold>
                
            	volumes>
                
                <move_factor>0.2move_factor>
            hot_cold>
            <v_order>
            	<volumes>
                    
                	<disk_group>
                    	<disk>fast_diskdisk>
                        <disk>hdd_diskdisk>
                    disk_group>
                volumes>
            v_order>
        policies>
    storage_configuration>
yandex>
  1. 建表语句

    • 多存储策略适用于所有的MergeTree引擎,包括RepliacatedMergeTree与分布式表

    • 建表SQL

      CREATE TABLE test.test_policy
      (
          `a` String,
          `part` String
      )
      ENGINE = MergeTree
      PARTITION BY part
      SETTINGS storage_policy='hot_cold',index_granularity = 8192
      
    • 查看ch对应节点内的策略信息

      SELECT 
          policy_name, 
          volume_name, 
          volume_priority, 
          disks, 
          max_data_part_size, 
          move_factor
      FROM system.storage_policies
      
    • 查看ch内table的disk位置

      SELECT 
          name,
          partition,
          disk_name,
          formatReadableSize(sum(bytes_on_disk))
      FROM system.parts
      WHERE table = 'test_table' and disk_name='fast_disk' group by  name,partition,disk_name
      
    • 查看disk信息

      SELECT 
          name, 
          path, 
          formatReadableSize(free_space) AS free, 
          formatReadableSize(total_space) AS total, 
          formatReadableSize(keep_free_space) AS reserved
      FROM system.disks
      

你可能感兴趣的:(ClickHouse)