# Hive 元数据存储

**Hive 元数据存储**（Hive Metastore，HMS）是 [Apache Hive](https://www.edgepedia.org/zh/apache-hive) 项目的元数据服务：一台服务器，将表的模式、位置和分区信息存放在后端关系型数据库中，并通过 Thrift API 将这些元数据提供给 Hive、Spark、Impala、Presto 和 Trino 等查询引擎。它最初为 Hadoop 上 Hive 自身的 SQL 引擎而构建，后来成为 Hadoop 数据湖生态事实上的共享目录，再往后又服务于 [Apache Iceberg](https://www.edgepedia.org/zh/apache-iceberg) 表。<sup>[1](https://docs-archive.cloudera.com/runtime/7.2.1/hive-hms-overview/hive-hms-overview.pdf)</sup><sup> • </sup><sup>[2](https://stackscape.org/en/p/apache-hive/)</sup>

| 关键事实 | 详情 |
|---|---|
| 存储内容 | 表模式、分区和数据位置，存于 MySQL 或 PostgreSQL 等关系型数据库<sup>[1](https://docs-archive.cloudera.com/runtime/7.2.1/hive-hms-overview/hive-hms-overview.pdf)</sup><sup> • </sup><sup>[3](https://aws.amazon.com.cdn.amazon.com/blogs/big-data/design-patterns-for-implementing-hive-metastore-for-amazon-emr-on-eks/)</sup> |
| 主要 API | Thrift，默认监听端口 9083（`hive.metastore.port`，自 Hive 1.3.0 起）<sup>[4](https://hive.apache.org/docs/latest/user/configuration-properties/)</sup><sup> • </sup><sup>[5](https://trino.io/docs/current/connector/hive.html)</sup> |
| 独立形态 | Hive 3.0（3.0.0 于 2018 年 6 月 7 日发布）使 HMS 成为独立服务，与 HiveServer2 及其他 Hive 和 Hadoop 组件解耦；Spark 等应用无需完整安装 Hive 即可使用<sup>[3](https://aws.amazon.com.cdn.amazon.com/blogs/big-data/design-patterns-for-implementing-hive-metastore-for-amazon-emr-on-eks/)</sup> |
| Iceberg REST | 自 Hive 4.1.0 起，HMS 内嵌一个 Iceberg REST 目录服务程序（JIRA HIVE-28059），基于 Iceberg 1.9.1 构建<sup>[6](https://www.hivebook.wiki/wiki/apache-iceberg-rest-catalog-open-api-for-lakehouse-catalogs)</sup> |
| 治理 | 访问控制极为有限，且不提供凭证下发；被归类为遗留兼容方案，而非新建之选<sup>[7](https://opendatalakehouse.com/compare/catalogs/)</sup> |
| 当前发布线 | Hive 4.2.1，2026 年 8 月 24 日发布，为缺陷修复版本，解决三个安全漏洞，其中一个位于 Hive 元数据存储的直接 SQL 分区路径；3.x 系列已于 2024 年 10 月 8 日宣告生命周期终止<sup>[8](https://hive.apache.org/general/downloads/)</sup> |

## 元数据存储的职责

湖仓目录位于查询引擎与已存储数据之间，是一种元数据服务，将表的逻辑名称与其在存储中的物理位置、模式以及表格式的快照连接起来；没有它，部分查询引擎也能将对象存储上的文件当作表来查询。<sup>[9](https://datus.ai/blog/what-is-lakehouse-catalog/)</sup><sup> • </sup><sup>[22](https://doris.apache.org/docs/4.x/lakehouse/file-analysis/)</sup> 在 Hive 的架构中，元数据存储持久化描述表的元数据（表名、列与分区及其属性、表属性，以及表数据所在的目录），并将元数据交给客户端，以便它们解析、鉴权并针对底层文件执行查询。<sup>[10](https://support.huaweicloud.com/intl/en-us/productdesc-mrs/mrs_08_001101.html)</sup><sup> • </sup><sup>[11](https://answers.databricks.com/open-source-data-catalog-2026)</sup>

Trino 可以说明该服务的触达范围远超 Hive 本身。Trino 使用 Hive 的数据文件以及存放在 MySQL 等数据库中的元数据，但不使用 HiveQL 或 Hive 的执行环境，其 Hive 连接器要求有一个 Hive 元数据存储服务或兼容实现（如 [AWS Glue](https://www.edgepedia.org/zh/aws-glue)）；该元数据存储服务也被用于 Trino 的 Delta Lake、Iceberg 和 Hudi 连接器。<sup>[5](https://trino.io/docs/current/connector/hive.html)</sup><sup> • </sup><sup>[12](https://trino.io/ecosystem/data-lake.html)</sup>

生态中反复强调的一个区分是目录与表格式之别。Apache Iceberg 和 [Apache Hudi](https://www.edgepedia.org/zh/apache-hudi) 是表格式，定义数据文件如何构成一张表；目录位于格式之上，在加载表时返回当前元数据，并负责创建、删除和重命名表。由于目录与格式是独立选择的，Iceberg 的 Spark 集成可以配合多种目录类型使用，其中包括 Hive、Hadoop、REST、JDBC 和 Nessie。<sup>[11](https://answers.databricks.com/open-source-data-catalog-2026)</sup>

## 架构

Hive 元数据存储由两个主要组件构成：后端数据库，即表模式、分区和数据位置等元数据的持久化存储；以及元数据存储服务 API，一个无状态服务，管理对该数据库的读写操作。<sup>[3](https://aws.amazon.com.cdn.amazon.com/blogs/big-data/design-patterns-for-implementing-hive-metastore-for-amazon-emr-on-eks/)</sup> 由于服务无状态，可以运行多个实例以实现高可用：客户端在 `hive.metastore.uris` 中指定多个元数据存储 URI，默认使用第一个，连接失败时随机另选一个。<sup>[13](https://hive.apache.org/docs/latest/admin/adminmanual-metastore-administration/)</sup>

部署模式历经演变。在 Hive 2.x 及更早版本中，元数据存储服务器可以作为库运行在 Hive 客户端内（本地或嵌入式），也可以作为远程服务器对接传统的独立关系型数据库。<sup>[13](https://hive.apache.org/docs/latest/admin/adminmanual-metastore-administration/)</sup> 2018 年发布的 Hive 3.0 引入了独立元数据存储：一个与其他 Hive 和 Hadoop 组件（如 HiveServer2）解耦的独立服务，使 [Apache Spark](https://www.edgepedia.org/zh/apache-spark) 等应用无需安装完整的 Hive 和 Hadoop 环境即可直接与 HMS 交互。独立元数据存储从 `metastore-site.xml` 读取配置，并作为独立的 Apache 发布件提供，含二进制和 Docker 镜像产物。<sup>[3](https://aws.amazon.com.cdn.amazon.com/blogs/big-data/design-patterns-for-implementing-hive-metastore-for-amazon-emr-on-eks/)</sup><sup> • </sup><sup>[14](https://hive.apache.org/docs/latest/admin/adminmanual-metastore-3-0-administration/)</sup><sup> • </sup><sup>[15](https://release-catalog.apache.org/hive-standalone-metastore/index.html)</sup>

Hive 对某些操作还支持直接访问后端数据库的 SQL 路径，Hive 4.2.1 的其中一个安全修复正落在此处。<sup>[8](https://hive.apache.org/general/downloads/)</sup>

## API 与生态触达

原生接口是 Thrift。Trino 用形如 `thrift://example.net:9083` 的 URI 配置它；在启用 Kerberos 的 Hadoop 集群中，Trino 使用 SASL 连接元数据存储的 Thrift 服务，并通过 Kerberos 进行认证。<sup>[5](https://trino.io/docs/current/connector/hive.html)</sup><sup> • </sup><sup>[12](https://trino.io/ecosystem/data-lake.html)</sup> Java 客户端使用 Metastore API，该 API 将元数据存储层与其他 Hive 内部组件解耦。<sup>[16](https://hive.apache.org/community/resources/hive-apis-overview/)</sup>

这个 Thrift API 本身已成为生态标准。AWS Glue Data Catalog 是 Hive 元数据存储的兼容实现，Google 的 Dataproc Metastore 和 Oracle 的 Data Catalog Metastore 则是托管服务，在其云中为 Hive、Spark 等客户端暴露同一接口。<sup>[5](https://trino.io/docs/current/connector/hive.html)</sup><sup> • </sup><sup>[17](https://docs.cloud.google.com/dataproc-metastore/docs/release-notes)</sup><sup> • </sup><sup>[18](https://docs.oracle.com/en-us/iaas/Content/data-catalog/using/metastore.htm)</sup> 一份 [Databricks](https://www.edgepedia.org/zh/databricks) 技术论文称 HMS 堪称当今使用最广泛的湖仓目录，是一个被众多开源引擎使用的开源项目；一份 Cloudera 出版物称其为 Cloudera 托管数据湖的支柱，承载了业界 90% 的工作负载。<sup>[19](https://www.databricks.com/sites/default/files/2025-06/unity-catalog-open-universal-governance-lakehouse-beyond.pdf)</sup><sup> • </sup><sup>[20](https://www.cloudera.com/content/dam/www/marketing/resources/ebooks/migrating-to-apache-iceberg-for-dummies.pdf?daqp=true)</sup>

## Apache Iceberg 与 REST 转向

对于 Iceberg 表，引擎可以通过两种方式经由 HMS 访问同一份数据：使用 HiveCatalog 的传统 Thrift API，或元数据存储自身暴露的 Iceberg REST 端点。JIRA HIVE-28059 于 2025 年 3 月解决，在 Hive 4.1.0（2025 年 7 月 31 日发布）中把 REST 目录服务程序放入 HMS；该模块以 `hive-standalone-metastore-rest-catalog` 形式发布，在 `org/apache/iceberg/rest` 下包含 `HMSCatalogServlet`、`HMSCatalogAdapter`、`HMSCachingCatalog` 和 `HMSCatalogFactory`，基于 Iceberg 1.9.1 构建。Hive 4.2.0 增加了 Iceberg REST 目录客户端，以及删除向量、自动压缩和 Z 排序等 Iceberg 特性。<sup>[6](https://www.hivebook.wiki/wiki/apache-iceberg-rest-catalog-open-api-for-lakehouse-catalogs)</sup><sup> • </sup><sup>[8](https://hive.apache.org/general/downloads/)</sup>

此举意义重大，因为正是 Iceberg REST 规范让目录之间可以互换：支持该规范的目录通常可以被替换，而不支持的则不能。OpenDataLakehouse 的对比仍将 HMS 的 API 描述为“Thrift，无处不在但已显陈旧”，但 Hivebook 2026 年的更新指出，最初被视为 REST 所要取代的两个目录——HMS 和 Glue——如今自身就支持 REST 规范。<sup>[7](https://opendatalakehouse.com/compare/catalogs/)</sup><sup> • </sup><sup>[6](https://www.hivebook.wiki/wiki/apache-iceberg-rest-catalog-open-api-for-lakehouse-catalogs)</sup>

## 治理局限与后继者

HMS 提供基本的目录功能：将表组织到模式中，并为每张表存储元数据；客户端用它获取表的位置，然后访问云存储处理数据。据一份 Databricks 论文，HMS 缺乏治理能力，转而依赖云存储策略进行访问控制，不原生支持事务等高级数据仓库特性，也无法处理表以外的资产类型。<sup>[19](https://www.databricks.com/sites/default/files/2025-06/unity-catalog-open-universal-governance-lakehouse-beyond.pdf)</sup> OpenDataLakehouse 的对比同样将其访问控制评为极为有限，凭证下发评为缺失，并将迁离 Hive 列为需单独规划的项目，而非默认步骤。<sup>[7](https://opendatalakehouse.com/compare/catalogs/)</sup>

较新的目录正瞄准这些缺口。[Apache Polaris](https://www.edgepedia.org/zh/apache-polaris)、[Unity Catalog](https://www.edgepedia.org/zh/unity-catalog-databricks) 和 [Lakekeeper](https://www.edgepedia.org/zh/lakekeeper) 都是 Iceberg REST 目录，具备基于角色的访问控制和凭证下发——即发放有范围限制的临时存储凭证，使引擎无需长期持有云凭证。<sup>[7](https://opendatalakehouse.com/compare/catalogs/)</sup> Unity Catalog OSS 采用 Apache 2.0 许可，同时兼容 Hive 元数据存储 API 和 Iceberg REST 目录 API；Databricks 于 2025 年 3 月 19 日宣布 Unity Catalog 中的 Hive 元数据存储联合功能正式可用，使 Unity Catalog 能够访问并治理存放在 AWS Glue 以及自托管或 Databricks 托管的 HMS 中的表。<sup>[11](https://answers.databricks.com/open-source-data-catalog-2026)</sup><sup> • </sup><sup>[21](https://dev.undress.workers.dev/read-https-www.databricks.com/blog/announcing-public-preview-hive-metastore-and-aws-glue-federation-unity-catalog)</sup>

## 发布历史

| 版本 | 日期 | 与 HMS 的关联 |
|---|---|---|
| 3.0.0 | 2018 年 6 月 7 日 | 首个独立 Hive 元数据存储<sup>[15](https://release-catalog.apache.org/hive-standalone-metastore/index.html)</sup> |
| 4.0.0 | 2024 年 3 月 | 默认支持 Iceberg；1.x 和 2.x 系列生命周期终止<sup>[2](https://stackscape.org/en/p/apache-hive/)</sup> |
| 3.x EOL | 2024 年 10 月 8 日 | 该系列不再有更新或发布<sup>[8](https://hive.apache.org/general/downloads/)</sup> |
| 4.1.0 | 2025 年 7 月 31 日 | 支持 JDK 17；独立 HMS 以二进制和 Docker 镜像形式提供；由 HMS 支撑的基于 REST 的目录服务器<sup>[8](https://hive.apache.org/general/downloads/)</sup> |
| 4.2.0 | 2025 年 11 月 17 日 | JDK 21 成为最低 Java 版本；Iceberg REST 目录客户端；元数据存储客户端代码分离为独立模块<sup>[8](https://hive.apache.org/general/downloads/)</sup> |
| 4.2.1 | 2026 年 8 月 24 日 | 修复 HMS 直接 SQL 分区路径、HiveServer2 SAML 持有者令牌认证和 Avro SerDe 模式 URL 处理中的安全问题<sup>[8](https://hive.apache.org/general/downloads/)</sup> |

## References

1. [Cloudera Runtime: Introduction to Hive metastore](https://docs-archive.cloudera.com/runtime/7.2.1/hive-hms-overview/hive-hms-overview.pdf)
2. [Apache Hive: SQL warehouse and metastore on Hadoop, Stackscape](https://stackscape.org/en/p/apache-hive/)
3. [Design patterns for implementing Hive Metastore for Amazon EMR on EKS, AWS Big Data Blog](https://aws.amazon.com.cdn.amazon.com/blogs/big-data/design-patterns-for-implementing-hive-metastore-for-amazon-emr-on-eks/)
4. [Apache Hive: Configuration Properties](https://hive.apache.org/docs/latest/user/configuration-properties/)
5. [Hive connector, Trino 484 Documentation](https://trino.io/docs/current/connector/hive.html)
6. [Apache Iceberg REST Catalog, Hivebook](https://www.hivebook.wiki/wiki/apache-iceberg-rest-catalog-open-api-for-lakehouse-catalogs)
7. [Comparing lakehouse catalogs, OpenDataLakehouse](https://opendatalakehouse.com/compare/catalogs/)
8. [Downloads, Apache Hive](https://hive.apache.org/general/downloads/)
9. [What Is a Lakehouse Catalog? Datus Blog](https://datus.ai/blog/what-is-lakehouse-catalog/)
10. [Hive Basic Principles, Huawei Cloud](https://support.huaweicloud.com/intl/en-us/productdesc-mrs/mrs_08_001101.html)
11. [Best open-source data catalog 2026? Databricks Community Answers](https://answers.databricks.com/open-source-data-catalog-2026)
12. [Trino Ecosystem: Data lake components](https://trino.io/ecosystem/data-lake.html)
13. [Apache Hive: AdminManual Metastore Administration](https://hive.apache.org/docs/latest/admin/adminmanual-metastore-administration/)
14. [Apache Hive: AdminManual Metastore 3.0 Administration](https://hive.apache.org/docs/latest/admin/adminmanual-metastore-3-0-administration/)
15. [Apache Hive Standalone Metastore, Apache Release Catalog](https://release-catalog.apache.org/hive-standalone-metastore/index.html)
16. [Apache Hive: Hive APIs Overview](https://hive.apache.org/community/resources/hive-apis-overview/)
17. [Dataproc Metastore release notes, Google Cloud Documentation](https://docs.cloud.google.com/dataproc-metastore/docs/release-notes)
18. [Data Catalog Metastore, Oracle Cloud Documentation](https://docs.oracle.com/en-us/iaas/Content/data-catalog/using/metastore.htm)
19. [Unity Catalog: Open and Universal Governance for the Lakehouse and Beyond, Databricks](https://www.databricks.com/sites/default/files/2025-06/unity-catalog-open-universal-governance-lakehouse-beyond.pdf)
20. [Migrating to Apache Iceberg For Dummies, Cloudera Special Edition](https://www.cloudera.com/content/dam/www/marketing/resources/ebooks/migrating-to-apache-iceberg-for-dummies.pdf?daqp=true)
21. [Announcing General Availability of Hive Metastore and AWS Glue Federation in Unity Catalog, Databricks Blog](https://dev.undress.workers.dev/read-https-www.databricks.com/blog/announcing-public-preview-hive-metastore-and-aws-glue-federation-unity-catalog)
22. [Analyzing Files on S3/HDFS - Apache Doris](https://doris.apache.org/docs/4.x/lakehouse/file-analysis/)

---
*Initially written Oct 26, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Databases and data systems › Data mining, warehousing, and big data › Big data platforms and frameworks

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/hive-metastore

English original: https://www.edgepedia.org/hive-metastore
