> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-fbfa8bee.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 包含服务器支持的磁盘类型列表及其内嵌文档的系统表。

# system.disk_types

<div id="description">
  ## 描述
</div>

包含服务器支持的磁盘类型列表，以及每种类型的内嵌文档。磁盘类型在磁盘配置的 `type` 中指定，用于决定磁盘将数据存储在何处以及以何种方式存储 (例如本地文件系统、对象存储、另一块磁盘上的缓存等) 。

请注意，此表列出的是可用的磁盘 *类型*，而 [`system.disks`](/zh/reference/system-tables/disks) 列出的是服务器上已配置的磁盘实例。

<div id="columns">
  ## 列
</div>

* `name` ([String](/zh/reference/data-types/index)) — 磁盘类型的名称，即磁盘配置 中 `type` 指定的值。
* `description` ([String](/zh/reference/data-types/index)) — 对该磁盘类型用途的概述。
* `syntax` ([String](/zh/reference/data-types/index)) — 在磁盘配置 中指定该磁盘类型的写法。
* `examples` ([String](/zh/reference/data-types/index)) — 使用示例。
* `introduced_in` ([String](/zh/reference/data-types/index)) — 首次引入该磁盘类型的 ClickHouse 版本，格式为 major.minor。
* `related` ([Array(String)](/zh/reference/data-types/index)) — 相关磁盘类型的名称。

<div id="configuration-examples">
  ## 配置示例
</div>

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

<div id="static-configuration">
  ### 静态配置
</div>

磁盘在服务器配置中的 `storage_configuration` 下定义。下面的示例定义了一个 `s3` 磁盘，以及一个使用该磁盘的存储策略。

```xml title="config.xml" theme={null}
<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 表示如下：

```yaml title="config.yaml" theme={null}
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
```

随后，表即可通过其存储策略使用该磁盘：

```sql title="Query" theme={null}
CREATE TABLE test (a Int32, b String)
ENGINE = MergeTree() ORDER BY a
SETTINGS storage_policy = 's3_policy';
```

<div id="dynamic-configuration">
  ### 动态配置
</div>

也可以使用 `disk` 函数，直接在 `CREATE`/`ATTACH` 查询的设置中定义磁盘，而无需先在配置文件中预定义磁盘：

```sql title="Query" theme={null}
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
);
```

请参阅[配置外部存储](/zh/concepts/features/configuration/server-config/storing-data)，了解每种磁盘类型的完整参数列表。

<div id="example">
  ## 示例
</div>

```sql title="Query" theme={null}
SELECT name, description
FROM system.disk_types
WHERE name IN ('local', 'object_storage')
ORDER BY name
```

<div id="see-also">
  ## 另请参阅
</div>

* [`system.disks`](/zh/reference/system-tables/disks) — 服务器上配置的磁盘实例。
* [`system.storage_policies`](/zh/reference/system-tables/storage_policies) — 存储策略和卷。
