Skip to main content

描述

包含服务器支持的磁盘类型列表,以及每种类型的内嵌文档。磁盘类型在磁盘配置的 type 中指定,用于决定磁盘将数据存储在何处以及以何种方式存储 (例如本地文件系统、对象存储、另一块磁盘上的缓存等) 。 请注意,此表列出的是可用的磁盘 类型,而 system.disks 列出的是服务器上已配置的磁盘实例。

  • name (String) — 磁盘类型的名称,即磁盘配置 中 type 指定的值。
  • description (String) — 对该磁盘类型用途的概述。
  • syntax (String) — 在磁盘配置 中指定该磁盘类型的写法。
  • examples (String) — 使用示例。
  • introduced_in (String) — 首次引入该磁盘类型的 ClickHouse 版本,格式为 major.minor。
  • related (Array(String)) — 相关磁盘类型的名称。

配置示例

磁盘可通过两种方式配置:静态配置,即在服务器配置文件 (XML 或 YAML) 中配置;或 动态配置,即在 CREATE/ATTACH 查询的设置中使用 disk 函数进行配置。两种方式接受的磁盘类型和参数相同。

静态配置

磁盘在服务器配置中的 storage_configuration 下定义。下面的示例定义了一个 s3 磁盘,以及一个使用该磁盘的存储策略。
config.xml
<clickhouse>
    <storage_configuration>
        <disks>
            <s3_disk>
                <type>s3</type>
                <endpoint>https://s3.eu-west-1.amazonaws.com/clickhouse-eu-west-1.clickhouse.com/data/</endpoint>
                <use_environment_credentials>1</use_environment_credentials>
            </s3_disk>
        </disks>
        <policies>
            <s3_policy>
                <volumes>
                    <main>
                        <disk>s3_disk</disk>
                    </main>
                </volumes>
            </s3_policy>
        </policies>
    </storage_configuration>
</clickhouse>
同样的配置,用 YAML 表示如下:
config.yaml
storage_configuration:
  disks:
    s3_disk:
      type: s3
      endpoint: https://s3.eu-west-1.amazonaws.com/clickhouse-eu-west-1.clickhouse.com/data/
      use_environment_credentials: 1
  policies:
    s3_policy:
      volumes:
        main:
          disk: s3_disk
随后,表即可通过其存储策略使用该磁盘:
Query
CREATE TABLE test (a Int32, b String)
ENGINE = MergeTree() ORDER BY a
SETTINGS storage_policy = 's3_policy';

动态配置

也可以使用 disk 函数,直接在 CREATE/ATTACH 查询的设置中定义磁盘,而无需先在配置文件中预定义磁盘:
Query
CREATE TABLE test (a Int32, b String)
ENGINE = MergeTree() ORDER BY a
SETTINGS disk = disk(
    type = s3,
    endpoint = 'https://s3.eu-west-1.amazonaws.com/clickhouse-eu-west-1.clickhouse.com/data/',
    use_environment_credentials = 1
);
请参阅配置外部存储,了解每种磁盘类型的完整参数列表。

示例

Query
SELECT name, description
FROM system.disk_types
WHERE name IN ('local', 'object_storage')
ORDER BY name

另请参阅

Last modified on June 29, 2026