

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 将本地 PostgreSQL 数据库迁移到 Aurora PostgreSQL
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql"></a>

*Baji Shaik 和 Jitender Kumar，Amazon Web Services*

## Summary
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-summary"></a>

Amazon Aurora PostgreSQL-Compatible Edition 将高端商业数据库的性能和可用性与开源数据库的简单性和成本效益结合在一起。Aurora 通过在同一 AWS 区域的三个可用区扩展存储来提供这些优势，并支持多达 15 个只读副本实例，用于横向扩展读取工作负载并在单个区域内提供高可用性。通过使用 Aurora 全局数据库，您最多可以在五个区域中复制 PostgreSQL 数据库，以便在区域出现故障时进行远程读取访问和灾难恢复。此模式描述了将本地 PostgreSQL 源数据库迁移到 Aurora PostgreSQL-Compatible 数据库的步骤。该模式包括两个迁移选项：使用 AWS 数据迁移服务（AWS DMS）或使用原生 PostgreSQL 工具（例如 [pg\_dump](https://www.postgresql.org/docs/current/app-pgdump.html)、[pg\_restore](https://www.postgresql.org/docs/current/app-pgrestore.html) 和 [psql](https://www.postgresql.org/docs/current/app-psql.html)）或第三方工具。 

此模式中描述的步骤也适用于亚马逊关系数据库服务 (Amazon RDS) 和亚马逊弹性计算云 (Amazon) 实例上的目标 PostgreSQL 数据库。 EC2

## 先决条件和限制
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-prereqs"></a>

**先决条件**
+ 一个有效的 Amazon Web Services account
+ 本地数据中心中的 PostgreSQL 源数据库
+ [Aurora PostgreSQL-Compatible 数据库实例](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_GettingStartedAurora.CreatingConnecting.AuroraPostgreSQL.html)或 [Amazon RDS for PostgreSQL 数据库实例](https://aws.amazon.com/getting-started/hands-on/create-connect-postgresql-db/)

**限制**
+ Amazon RDS for PostgreSQL 的数据库大小限制为 64 TB，Aurora PostgreSQL-Compatible 的数据库大小限制为 128 TB。
+ 如果您使用的是 AWS DMS 迁移选项，请查看[使用 PostgreSQL 数据库作为源的 AWS DMS 限制](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html#CHAP_Source.PostgreSQL.Limitations)。

**产品版本**
+ 有关 Amazon RDS 对 PostgreSQL 主要版本和次要版本的支持，请参阅 Amazon RDS 文档中的 [Amazon RDS for PostgreSQL 更新](https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLReleaseNotes/postgresql-versions.html)。
+ 有关 Aurora 中 PostgreSQL 的支持，请参阅 Aurora 文档中的 [Amazon Aurora PostgreSQL 更新](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraPostgreSQLReleaseNotes/AuroraPostgreSQL.Updates.html)。
+ 如果您使用的是 AWS DMS 迁移选项，请参阅 AWS DMS 文档中[支持的 PostgreSQL 版本](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html)。

## 架构
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-architecture"></a>

**源技术堆栈**
+ 本地 PostgreSQL 数据库

**目标技术堆栈**
+ Aurora PostgreSQL-Compatible 数据库实例

**源架构**

![本地 PostgreSQL 数据库的源架构](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/82114165-8102-44a2-8b12-485ac9eb8989/images/a8621ad3-781b-45a9-86a8-d0b0ec5c79ea.png)


**目标架构**

![Amazon Aurora 上 PostgreSQL 数据库的目标架构](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/82114165-8102-44a2-8b12-485ac9eb8989/images/fc2ec0cb-7b9b-4cc0-b70c-40e47c2f4c45.png)


**数据迁移架构**

*使用 AWS DMS*

![使用 AWS DMS 将本地 PostgreSQL 数据库迁移到 Aurora](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/82114165-8102-44a2-8b12-485ac9eb8989/images/5336adb4-e9eb-47d0-a5b5-d149261b1638.png)


*使用原生 PostgreSQL 工具*

![使用 pg_dump 和 pg_restore 将本地 PostgreSQL 数据库迁移到 Aurora](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/82114165-8102-44a2-8b12-485ac9eb8989/images/3c6fb533-45ff-443e-bfb1-97e60cbdd583.png)


## 工具
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-tools"></a>
+ [AWS Database Migration Service（AWS DMS）](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)可帮助您将数据存储迁移到 Amazon Web Services Cloud，或者在云和本地配置的组合之间迁移。该服务支持不同的源数据库和目标数据库。有关如何验证 AWS DMS 支持的 PostgreSQL 源数据库和目标数据库版本和版本的信息，请参阅[使用 PostgreSQL 数据库作为 AWS DMS 源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html)。建议使用最新版本的 AWS DMS，以获得最全面的版本和功能支持。
+ PostgreSQL 原生工具包括 [pg\_dump](https://www.postgresql.org/docs/current/app-pgdump.html)、[pg\_restore](https://www.postgresql.org/docs/current/app-pgrestore.html) 和[psql](https://www.postgresql.org/docs/current/app-psql.html)。

## 操作说明
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-epics"></a>

### 分析迁移
<a name="analyze-the-migration"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 验证源数据库和目标数据库的版本。 | 如果您使用的是 AWS DMS。请确保您使用的是 [PostgreSQL 的受支持版本](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html)。 | 数据库管理员 | 
| 确定存储类型和容量。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | 数据库管理员、系统管理员 | 
| 选择正确的实例类型、容量、存储功能和网络功能。 | 确定目标数据库实例的计算要求。查看可能需要额外注意的已知性能问题。要确定合适的实例类型，请考虑以下因素：[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html)<br />有关更多信息，请参阅 Amazon Aurora 用户指南中的 [Aurora 数据库实例类](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Concepts.DBInstanceClass.html)。 | 数据库管理员、系统管理员 | 
| 确定源数据库和目标数据库的网络访问安全要求。 | 确定使应用程序能够与数据库通信的相应安全组。 | 数据库管理员、系统管理员 | 
| 确定应用程序迁移策略。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | 数据库管理员、应用程序所有者、系统管理员 | 

### 配置基础设施
<a name="configure-the-infrastructure"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建 VPC。 | 为目标数据库实例创建新的虚拟私有云（VPC）。 | 系统管理员 | 
| 创建安全组。 | 在 VPC 内创建安全组（如前一个操作说明中所述），以允许数据库实例的入站连接。 | 系统管理员 | 
| 配置并启动 Aurora 数据库集群。 | 使用新的 VPC 和安全组创建目标数据库实例并启动该实例。 | 系统管理员 | 

### 迁移数据 – 选项 1（使用 AWS DMS）
<a name="migrate-data-option-1-using-aws-dms"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 完成迁移前步骤。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | 数据库管理员 | 
| 完成迁移步骤。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | 数据库管理员 | 
| 验证数据。 | 要确保您的数据从源准确迁移到目标，请按照 AWS DMS 文档中的[数据验证步骤](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Validating.html)进行操作。 | 数据库管理员 | 

### 迁移数据-选项 2（使用 pg\_dump 和 pg\_restore）
<a name="migrate-data-option-2-using-pg_dump-and-pg_restore"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 准备源数据库。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html)有关更多信息，请参阅 [pg\_dump](https://www.postgresql.org/docs/current/app-pgdump.html) 文档和 AWS DMS 文档中的[演练](https://docs.aws.amazon.com/dms/latest/sbs/chap-manageddatabases.postgresql-rds-postgresql-full-load-pd_dump.html)。 | 数据库管理员 | 
| 准备目标数据库。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html)有关更多信息，请参阅 [pg\_restore](https://www.postgresql.org/docs/current/app-pgrestore.html) 文档和 AWS DMS 文档中的[演练](https://docs.aws.amazon.com/dms/latest/sbs/chap-manageddatabases.postgresql-rds-postgresql-full-load-pd_dump.html)。 | 数据库管理员 | 
| 验证数据。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | 数据库管理员 | 

### 迁移应用程序
<a name="migrate-the-application"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 遵循应用程序迁移策略。 | 实施您在第一个操作说明中创建的应用程序迁移策略。 | 数据库管理员、应用程序所有者、系统管理员 | 

### 割接至目标数据库
<a name="cut-over-to-the-target-database"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 将应用程序客户端切换至新基础设施。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | 数据库管理员、应用程序所有者、系统管理员 | 
| 如果您需要回滚迁移。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/migrate-an-on-premises-postgresql-database-to-aurora-postgresql.html) | 数据库管理员、应用程序所有者 | 

### 关闭项目
<a name="close-the-project"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 关闭资源。 | 关闭临时 AWS 资源。 | 数据库管理员、系统管理员 | 
| 验证文档。 | 查看和验证项目文档。 | 数据库管理员、应用程序所有者、系统管理员 | 
| 收集指标。 | 收集与迁移时间、手动与工具占比、成本节约等相关的指标。 | 数据库管理员、应用程序所有者、系统管理员 | 
| 关闭项目。 | 关闭项目并提供任何反馈。 | 数据库管理员、应用程序所有者、系统管理员 | 

## 相关资源
<a name="migrate-an-on-premises-postgresql-database-to-aurora-postgresql-resources"></a>

**参考**
+ [AWS 数据库迁移服务](https://aws.amazon.com/dms/)
+ [VPCs 还有亚马逊 Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_VPC.html)
+ [Amazon Aurora 定价](https://aws.amazon.com/rds/aurora/pricing/)
+ [使用 PostgreSQL 数据库作为 AWS DMS 源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.PostgreSQL.html)
+ [如何创建 AWS DMS 复制实例](https://aws.amazon.com/premiumsupport/knowledge-center/create-aws-dms-replication-instance/)
+ [如何使用 AWS DMS 创建源端点和目标端点](https://aws.amazon.com/premiumsupport/knowledge-center/create-source-target-endpoints-aws-dms/)

**其他资源**
+ [AWS DMS 入门](https://aws.amazon.com/dms/getting-started/)
+ [数据迁移 step-by-step演练](https://docs.aws.amazon.com/dms/latest/sbs/DMS-SBS-Welcome.html)
+ [Amazon Aurora 资源](https://aws.amazon.com/rds/aurora/getting-started/)