# pg_tde 如何沿 PostgreSQL 存储路径保持数据加密

> 从 tde_heap、Storage Manager、内部密钥、主密钥到 WAL 加密，理解 pg_tde 的实际工作路径。

---

LLMS 索引： [llms.txt](/zh/llms.txt)

---

> 本页沿用 Percona pg_tde 2.3.0 手册。Mimus 的配套构建、备份工具和跨大版本迁移见 [Mimus PG TDE](/zh/docs/tde/)。

本文为 PGSTY 基于上游文档整理的导读。


只有加密真正经过存储路径，保护才有意义。pg_tde 使用 `tde_heap` 标记需要加密的表，再通过 PostgreSQL Storage Manager 在页面落盘前加密、进入缓存前解密。

## 两层密钥结构 {#the-two-key-hierarchy}

每个加密数据文件都有内部密钥；主密钥保护内部密钥，并保存在 keyring 或外部 KMS 中。这样轮换保护密钥时，不必立即重写每个数据页。

## WAL 的位置 {#where-wal-fits}

WAL 加密是集群级设置。WAL 页面使用内部密钥，内部密钥由服务器主密钥保护；WAL 读取端根据密钥元数据决定哪些记录需要解密。

## 对运维的影响 {#operator-consequence}

密钥提供商可用且认证信息正确时，表可以正常读取；提供商或凭据缺失时，读取可能失败。[密钥管理指南](/zh/docs/tde/upstream/global-key-provider-configuration/overview/)和[恢复限制](/zh/docs/tde/upstream/index/tde-limitations/)应与数据库配置放在同一份运行手册中。

[PG.CENTER 双语底本](https://github.com/pgsty/doc.pg.center/blob/4410c32dc9186a22859008303f474b72a779f583/content/percona/blog/guide/encryption-architecture.zh.md) · [上游原文](https://github.com/percona/pg_tde/blob/5dd7a9e4e3599d88546f5de67ff0f4ef3fe51a9a/documentation/docs/architecture/encryption-architecture.md)
