

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 資料庫
<a name="databases-pattern-list"></a>

**Topics**
+ [使用連結的伺服器從 Amazon EC2 上的 Microsoft SQL Server 存取內部部署 Microsoft SQL Server 資料表](access-on-premises-microsoft-sql-server-tables-from-microsoft-sql-server-on-amazon-ec2-using-linked-servers.md)
+ [使用僅供讀取複本將 HA 新增至 Amazon RDS Custom 上的 Oracle PeopleSoft](add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica.md)
+ [分析從 Oracle 到 PostgreSQL 的部分資料庫遷移的物件相依性](multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql.md)
+ [評估將 SQL Server 資料庫遷移至 AWS 上的 MongoDB Atlas 的查詢效能](assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws.md)
+ [使用 IaC 原則自動化 Amazon Aurora 全域資料庫的藍/綠部署](p-automate-blue-green-deployments-aurora-global-databases-iac.md)
+ [自動化跨 的 Amazon RDS 執行個體複寫 AWS 帳戶](automate-the-replication-of-amazon-rds-instances-across-aws-accounts.md)
+ [使用 AWS Lambda 和 任務排程器，在 Amazon EC2 上執行的 SQL Server Express 版本中自動化資料庫任務](automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.md)
+ [使用 DR Orchestrator Framework 自動化跨區域容錯移轉和容錯回復](automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework.md)
+ [使用 Systems Manager 和 EventBridge 自動備份 SAP HANA 資料庫](automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge.md)
+ [使用 Python 應用程式自動產生 Amazon DynamoDB 的 PynamoDB 模型和 CRUD 函數 DynamoDB](automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application.md)
+ [使用 Cloud Custodian 封鎖對 Amazon RDS 的公開存取](block-public-access-to-amazon-rds-by-using-cloud-custodian.md)
+ [使用 設定 Amazon RDS for Microsoft SQL Server 的 Windows 身分驗證 AWS Managed Microsoft AD](configure-windows-authentication-for-amazon-rds-using-microsoft-ad.md)
+ [設定對 Amazon DynamoDB 的跨帳戶存取權](configure-cross-account-access-to-amazon-dynamodb.md)
+ [在 AWS 上 SQL Server 的 Always On 可用性群組中設定唯讀路由](configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws.md)
+ [在 pgAdmin 中使用 SSH 通道進行連線](connect-by-using-an-ssh-tunnel-in-pgadmin.md)
+ [將 JSON Oracle 查詢轉換為 PostgreSQL 資料庫 SQL](convert-json-oracle-queries-into-postgresql-database-sql.md)
+ [使用 跨帳戶複製 Amazon DynamoDB 資料表 AWS Backup](copy-amazon-dynamodb-tables-across-accounts-using-aws-backup.md)
+ [使用自訂實作跨帳戶複製 Amazon DynamoDB 資料表](copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation.md)
+ [建立 Amazon RDS 和 Amazon Aurora 的詳細成本和用量報告](create-detailed-cost-and-usage-reports-for-amazon-rds-and-amazon-aurora.md)
+ [使用 Terraform 在 Amazon EC2 和 Amazon FSx 上部署 SQL Server 容錯移轉叢集執行個體](deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx.md)
+ [在 Amazon Aurora PostgreSQL 和 Amazon RDS for PostgreSQL 中模擬 Oracle PL/SQL 關聯陣列](emulate-oracle-plsql-associative-arrays-in-aurora-and-rds-postgresql.md)
+ [在 Amazon RDS 中啟用 PostgreSQL 資料庫執行個體的加密連線](enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.md)
+ [加密現有的 Amazon RDS for PostgreSQL 資料庫執行個體](encrypt-an-existing-amazon-rds-for-postgresql-db-instance.md)
+ [在啟動時強制執行 Amazon RDS 資料庫的自動標記](enforce-automatic-tagging-of-amazon-rds-databases-at-launch.md)
+ [預估 DynamoDB 資料表的隨需容量成本](estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity.md)
+ [Amazon DynamoDB 資料表的預估儲存成本](estimate-storage-costs-for-an-amazon-dynamodb-table.md)
+ [使用 AWR 報告估計 Oracle 資料庫的 Amazon RDS 引擎大小](estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.md)
+ [使用 AWS DMS 將 Amazon RDS for SQL Server 資料表匯出至 S3 儲存貯體](export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms.md)
+ [在 Aurora PostgreSQL 中處理動態 SQL 陳述式中的匿名區塊](handle-anonymous-blocks-in-dynamic-sql-statements-in-aurora-postgresql.md)
+ [協助強制執行 DynamoDB 標記](help-enforce-dynamodb-tagging.md)
+ [使用 AWS DMS 和 Amazon Aurora 實作跨區域災難復原](implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora.md)
+ [將具有超過 100 個引數的 Oracle 函數和程序遷移至 PostgreSQL](migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql.md)
+ [將 Redis 工作負載遷移至 AWS 上的 Redis Enterprise Cloud](migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.md)
+ [使用具有相同主機名稱的 SAP HSR 將 SAP HANA 遷移至 AWS](migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname.md)
+ [使用 遷移 Microsoft SQL Server Always On 可用性群組 AWS Application Migration Service](migrate-microsoft-sql-server-always-on-group-using-mgn.md)
+ [使用分散式可用性群組將 SQL Server 遷移至 AWS](migrate-sql-server-to-aws-using-distributed-availability-groups.md)
+ [在 上將關聯式資料庫遷移至 MongoDB Atlas AWS](migrate-relational-database-to-mongodb-atlas.md)
+ [在 上將自我託管的 MongoDB 環境遷移至 MongoDB Atlas AWS](migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud.md)
+ [使用 AWS DMS 將 Oracle 資料庫遷移至 Amazon DynamoDB](migrate-an-oracle-database-to-amazon-dynamodb-using-aws-dms.md)
+ [使用 SharePlex 和 AWS DMS 從 Oracle 8i 或 9i 遷移至 Amazon RDS for Oracle](migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms.md)
+ [將內部部署 MySQL 資料庫遷移至 Amazon EC2](migrate-an-on-premises-mysql-database-to-amazon-ec2.md)
+ [在沒有加密的情況下監控 Amazon Aurora 是否有執行個體](monitor-amazon-aurora-for-instances-without-encryption.md)
+ [使用 Amazon CloudWatch 監控 Oracle GoldenGate 日誌](monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch.md)
+ [在 Amazon RDS for Oracle 上將 Oracle Database Enterprise Edition 轉換為 Standard Edition 2](replatform-oracle-database-enterprise-edition-to-standard-edition-2-on-amazon-rds-for-oracle.md)
+ [使用 Precisely Connect 將大型主機資料庫複寫至 AWS](replicate-mainframe-databases-to-aws-by-using-precisely-connect.md)
+ [使用 Lambda 和 Secrets Manager 來排程 Amazon RDS for PostgreSQL 和 Aurora PostgreSQL 的任務](schedule-jobs-for-amazon-rds-for-postgresql-and-aurora-postgresql-by-using-lambda-and-secrets-manager.md)
+ [使用內部部署 SMTP 伺服器和 Database Mail 傳送 Amazon RDS for SQL Server 資料庫執行個體的通知](send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail.md)
+ [在 AWS 上設定 SAP on IBM Db2 的災難復原](set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.md)
+ [使用 Terraform 設定資料庫遷移的 CI/CD 管道](set-up-ci-cd-pipeline-for-db-migration-with-terraform.md)
+ [使用 FSx for Windows File Server 在 Amazon EC2 上設定 Microsoft SQL Server 容錯移轉叢集](microsoft-sql-failover-cluster-on-amazon-ec2.md)
+ [使用作用中待命資料庫為 Amazon RDS Custom 上的 Oracle 電子商務套件設定 HA/DR 架構](set-up-an-ha-dr-architecture-for-oracle-e-business-suite-on-amazon-rds-custom-with-an-active-standby-database.md)
+ [在 上將資料從 IBM Db2、SAP、Sybase 和其他資料庫串流至 MongoDB Atlas AWS](stream-data-from-ibm-db2-to-mongodb-atlas.md)
+ [Amazon RDS Custom for Oracle 上 Oracle PeopleSoft 應用程式的轉換角色](transition-roles-for-an-oracle-peoplesoft-application-on-amazon-rds-custom-for-oracle.md)
+ [將資料從 Amazon Redshift 叢集跨帳戶卸載至 Amazon S3](unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.md)
+ [依工作負載的資料庫遷移模式](databases-database-migration-patterns-by-workload-pattern-list.md)
+ [更多模式](databases-more-patterns-pattern-list.md)

# 使用連結的伺服器從 Amazon EC2 上的 Microsoft SQL Server 存取內部部署 Microsoft SQL Server 資料表
<a name="access-on-premises-microsoft-sql-server-tables-from-microsoft-sql-server-on-amazon-ec2-using-linked-servers"></a>

*Tirumala Dasari 和 Eduardo Valentim，Amazon Web Services*

## 總結
<a name="access-on-premises-microsoft-sql-server-tables-from-microsoft-sql-server-on-amazon-ec2-using-linked-servers-summary"></a>

此模式說明如何使用連結的伺服器，從在 Amazon Elastic Compute Cloud (Amazon EC2) Windows 或 Linux 執行個體上執行或託管的 Microsoft SQL Server 資料庫存取在 Microsoft Windows 上執行的內部部署 Microsoft SQL Server 資料庫資料表。

## 先決條件和限制
<a name="access-on-premises-microsoft-sql-server-tables-from-microsoft-sql-server-on-amazon-ec2-using-linked-servers-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Amazon EC2 搭配在 Amazon Linux AMI (Amazon Machine Image) 上執行的 Microsoft SQL Server
+ 內部部署 Microsoft SQL Server (Windows) 伺服器與 Windows 或 Linux EC2 執行個體之間的 AWS Direct Connect

**產品版本**
+ SQL Server 2016 或更新版本

## Architecture
<a name="access-on-premises-microsoft-sql-server-tables-from-microsoft-sql-server-on-amazon-ec2-using-linked-servers-architecture"></a>

**來源技術堆疊**
+ 在 Windows 上執行的內部部署 Microsoft SQL Server 資料庫
+ Amazon EC2 搭配在 Windows AMI 或 Linux AMI 上執行的 Microsoft SQL Server

**目標技術堆疊**
+ 在 Amazon Linux AMI 上執行的 Amazon EC2 搭配 Microsoft SQL Server
+ Amazon EC2 搭配在 Windows AMI 上執行的 Microsoft SQL Server

**來源和目標資料庫架構**

![\[AWS 雲端 architecture with VPC, availability zones, and hybrid environment connecting to on-premises database.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/8e4a3222-0850-4980-8028-c710dcdb9186/images/fa157992-0ed9-46e1-8059-0cbbb74a98ec.png)


## 工具
<a name="access-on-premises-microsoft-sql-server-tables-from-microsoft-sql-server-on-amazon-ec2-using-linked-servers-tools"></a>
+ [Microsoft SQL Server Management Studio (SSMS)](https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver16) 是用於管理 SQL Server 基礎設施的整合環境。它提供使用者介面和一組工具，其中包含與 SQL Server 互動的豐富指令碼編輯器。

## 史詩
<a name="access-on-premises-microsoft-sql-server-tables-from-microsoft-sql-server-on-amazon-ec2-using-linked-servers-epics"></a>

### 在 Windows SQL Server 中將身分驗證模式變更為 Windows for SQL Server
<a name="change-authentication-mode-to-windows-for-sql-server-in-windows-sql-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 透過 SSMS 連線至 Windows SQL Server。 |  | DBA | 
| 從 Windows SQL Server 執行個體的內容 （按一下滑鼠右鍵） 選單，將 SQL Server 中的身分驗證模式變更為 Windows。 |  | DBA | 

### 重新啟動 Windows MSSQL 服務
<a name="restart-the-windows-mssql-service"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 重新啟動 SQL 服務。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/access-on-premises-microsoft-sql-server-tables-from-microsoft-sql-server-on-amazon-ec2-using-linked-servers.html) | DBA | 

### 建立新的登入，然後選擇要在 Windows SQL Server 中存取的資料庫
<a name="create-new-login-and-choose-databases-to-access-in-windows-sql-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在安全索引標籤中，開啟登入的內容 （按一下滑鼠右鍵） 選單，然後選取新的登入。 |  | DBA | 
| 在一般索引標籤中，選擇 SQL Server 身分驗證、輸入使用者名稱、輸入密碼，然後確認密碼，並清除在下次登入時變更密碼的選項。 |  | DBA | 
| 在伺服器角色索引標籤中，選擇公有。 |  | DBA | 
| 在使用者映射索引標籤中，選擇您要存取的資料庫和結構描述，然後反白顯示資料庫以選取資料庫角色。 | 選取公有和 db\$1datareader 以從資料庫資料表存取資料。 | DBA | 
| 選擇確定以建立使用者。 |  | DBA | 

### 將 Windows SQL Server IP 新增至 Linux SQL Server 主機檔案
<a name="add-windows-sql-server-ip-to-linux-sql-server-host-file"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 透過終端機視窗連線至 Linux SQL Server 方塊。 |  | DBA | 
| 開啟 /etc/hosts 檔案，並使用 SQL Server 新增 Windows 機器的 IP 地址。 |  | DBA | 
| 儲存主機檔案。 |  | DBA | 

### 在 Linux SQL Server 上建立連結的伺服器
<a name="create-linked-server-on-linux-sql-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用預存程序 master.sys.sp\$1addlinkedserver 和 master.dbo.sp\$1addlinkedsrvlogin 建立連結的伺服器。 | 如需使用這些預存程序的詳細資訊，請參閱*其他資訊*一節。 | DBA、開發人員 | 

### 驗證在 SSMS 中建立的連結伺服器和資料庫
<a name="verify-the-created-linked-server-and-databases-in-ssms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 SSMS 的 Linux SQL Server 中，前往連結的伺服器並重新整理。 |  | DBA | 
| 在左側窗格中展開建立的連結伺服器和目錄。 | 您將看到選取的 SQL Server 資料庫，其中包含資料表和檢視。 | DBA | 

### 確認您可以存取 Windows SQL Server 資料庫資料表
<a name="verify-that-you-can-access-windows-sql-server-database-tables"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 SSMS 查詢視窗中，執行查詢：「從 【sqllin】.dms\$1sample\$1win.dbo.mlb\$1data 選取前 3 \$1」。 | 請注意， FROM 子句使用四部分語法： computer.database.schema.table （例如 SELECT 名稱 "SQL2 database" FROM 【sqllin】.master.sys.databases)。在我們的範例中，我們在主機檔案中建立了 SQL2 的別名，因此您不需要在方括號之間輸入實際的 NetBIOS 名稱。如果您確實使用實際的 NetBIOS 名稱，請注意，AWS 預設為 NetBIOS 名稱，例如 Win-xxxx，SQL Server 需要有破折號名稱的方括號。 | DBA、開發人員 | 

## 相關資源
<a name="access-on-premises-microsoft-sql-server-tables-from-microsoft-sql-server-on-amazon-ec2-using-linked-servers-resources"></a>
+ [Linux 上 SQL Server 的版本備註](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-release-notes?view=sql-server-2017) 

 

## 其他資訊
<a name="access-on-premises-microsoft-sql-server-tables-from-microsoft-sql-server-on-amazon-ec2-using-linked-servers-additional"></a>

**使用預存程序建立連結的伺服器**

SSMS 不支援為 Linux SQL Server 建立連結伺服器，因此您必須使用這些預存程序來建立它們：

```
EXEC master.sys.sp_addlinkedserver @server= N'SQLLIN' , @srvproduct= N'SQL Server'    
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'SQLLIN',@useself=N'False',@locallogin=NULL,@rmtuser=N'username',@rmtpassword='Test123$'
```

注意 1：在預存程序 中輸入您先前在 Windows SQL Server 中建立的登入憑證`master.dbo.sp_addlinkedsrvlogin`。

注意 2：`@server`名稱`SQLLIN`和主機檔案項目名稱`172.12.12.4 SQLLIN`應該相同。

 您可以使用此程序為下列案例建立連結的伺服器：
+ 透過連結伺服器從 Linux SQL Server 到 Windows SQL Server （如此模式所述）
+ 透過連結伺服器將 Windows SQL Server 轉換為 Linux SQL Server
+ 透過連結伺服器將 Linux SQL Server 連線到另一個 Linux SQL Server

# 使用僅供讀取複本將 HA 新增至 Amazon RDS Custom 上的 Oracle PeopleSoft
<a name="add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica"></a>

*sampath kathirvel，Amazon Web Services*

## 總結
<a name="add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica-summary"></a>

若要在 Amazon Web Services (AWS) 上執行 [Oracle PeopleSoft](https://www.oracle.com/applications/peoplesoft/) 企業資源規劃 (ERP) 解決方案，您可以使用 [Amazon Relational Database Service (Amazon RDS)](https://aws.amazon.com/rds/) 或 [Amazon RDS Custom for Oracle](https://aws.amazon.com/rds/custom/)，以支援需要存取基礎作業系統和資料庫環境的舊版、自訂和封裝應用程式。如需規劃遷移時要考量的關鍵因素，請參閱 AWS 方案指引中的 [Oracle 資料庫遷移策略](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/strategies.html)。

截至本文撰寫為止，RDS Custom for Oracle 不支援[異地](https://aws.amazon.com/blogs/aws/multi-az-option-for-amazon-rds-oracle/)同步備份選項，此選項可供 [Amazon RDS for Oracle](https://aws.amazon.com/rds/oracle/) 做為使用儲存體複寫的 HA 解決方案使用。相反地，此模式會使用建立和維護主要資料庫實體副本的待命資料庫來實現 HA。此模式著重於使用 Oracle Data Guard 設定僅供讀取複本，在具有 HA 的 Amazon RDS Custom 上執行 PeopleSoft 應用程式資料庫的步驟。

此模式也會將僅供讀取複本變更為唯讀模式。讓僅供讀取複本處於唯讀模式可提供額外的優點：
+ 從主要資料庫卸載唯讀工作負載
+ 使用 Oracle Active Data Guard 功能從待命資料庫擷取運作狀態良好的區塊，以啟用損毀區塊的自動修復
+ 使用 Far Sync 功能讓遠端待命資料庫保持同步，而不會產生與長途重做日誌傳輸相關的效能額外負荷。

在唯讀模式下使用複本需要 [Oracle Active Data Guard](https://www.oracle.com/assets/technology-price-list-070617.pdf) 選項，因為這是 Oracle Database Enterprise Edition 的單獨授權功能，因此需要支付額外費用。

## 先決條件和限制
<a name="add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica-prereqs"></a>

**先決條件 **
+ Amazon RDS Custom 上的現有 PeopleSoft 應用程式。如果您沒有應用程式，請參閱將 [Oracle PeopleSoft 遷移至 Amazon RDS Custom](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-oracle-peoplesoft-to-amazon-rds-custom.html) 模式。
+ 單一 PeopleSoft 應用程式層。不過，您可以調整此模式以使用多個應用程式層。
+ Amazon RDS Custom 已設定至少 8 GB 的交換空間。
+ Oracle Active Data Guard 資料庫授權，可將僅供讀取複本轉換為唯讀模式，並使用它將報告任務卸載至待命。如需詳細資訊，請參閱 [Oracle Technology 商業價目表](https://www.oracle.com/corporate/pricing/#technology)。

**限制**** **
+ [RDS Custom for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-reqs-limits.html#custom-reqs-limits.limits) 的一般限制和不支援的組態
+ 與 [Amazon RDS Custom for Oracle 僅供讀取複本](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-rr.html#custom-rr.limitations)相關聯的限制

**產品版本**
+ 如需 Amazon RDS Custom 支援的 Oracle 資料庫版本，請參閱 [RDS Custom for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RDS_Fea_Regions_DB-eng.Feature.RDSCustom.html#Concepts.RDS_Fea_Regions_DB-eng.Feature.RDSCustom.ora)。
+ 如需 Amazon RDS Custom 支援的 Oracle 資料庫執行個體類別，請參閱 [RDS Custom for Oracle 的資料庫執行個體類別支援](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-reqs-limits.html#custom-reqs-limits.instances)。

## Architecture
<a name="add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica-architecture"></a>

**目標技術堆疊**
+ Amazon RDS Custom for Oracle
+ AWS Secrets Manager
+ Oracle Active Data Guard
+ Oracle PeopleSoft 應用程式

**目標架構**

下圖顯示 Amazon RDS Custom 資料庫執行個體和 Amazon RDS Custom 僅供讀取複本。僅供讀取複本使用 Oracle Active Data Guard 複寫到另一個可用區域。您也可以使用僅供讀取複本卸載主要資料庫上的讀取流量，並用於報告目的。

![\[VPC 包含 AWS Secrets Manager、Amazon EFS、應用程式層和資料庫層。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/7df4b2d0-b833-4ba3-98e4-a178db395d9d/images/463aefbe-70ad-4cd3-9ddc-0d8347e848c6.png)


如需在 AWS 上使用 Oracle PeopleSoft 的代表性架構，請參閱[在 AWS 上設定高可用性的 PeopleSoft 架構](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/set-up-a-highly-available-peoplesoft-architecture-on-aws.html)。

## 工具
<a name="add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica-tools"></a>

**AWS 服務**
+ [Amazon RDS Custom for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/working-with-custom-oracle.html) 是一種受管資料庫服務，適用於需要存取基礎作業系統和資料庫環境的舊版、自訂和封裝應用程式。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您以 API 呼叫 Secrets Manager，以程式設計方式擷取秘密，取代程式碼中的硬式編碼登入資料，包括密碼。在此模式中，您會從秘密名稱`RDS_DATAGUARD`為 的 Secrets Manager 擷取資料庫使用者密碼`do-not-delete-rds-custom-+<<RDS Resource ID>>+-dg`。

**其他工具**
+ [Oracle Data Guard](https://docs.oracle.com/en/database/oracle/oracle-database/19/sbydb/preface.html#GUID-B6209E95-9DA8-4D37-9BAD-3F000C7E3590) 可協助您建立、維護、管理和監控待命資料庫。

## 最佳實務
<a name="add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica-best-practices"></a>

若要朝零資料遺失 (RPO=0) 目標運作，請使用 `MaxAvailability` Data Guard 保護模式，並使用重做傳輸`SYNC+NOAFFIRM`設定以獲得更好的效能。如需選取資料庫保護模式的詳細資訊，請參閱*其他資訊*一節。

## 史詩
<a name="add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica-epics"></a>

### 建立僅供讀取複本
<a name="create-the-read-replica"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立僅供讀取複本。 | 若要建立 Amazon RDS Custom 資料庫執行個體的僅供讀取複本，請遵循 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html#USER_ReadRepl.Create)中的指示，並使用您建立的 Amazon RDS Custom 資料庫執行個體 （請參閱*先決條件*一節） 做為來源資料庫。根據預設，Amazon RDS Custom 僅供讀取複本會建立為實體待命，且處於掛載狀態。這是為了確保符合 Oracle Active Data Guard 授權。此模式包含用於設定多租戶容器資料庫 (CDB) 或非 CDB 執行個體的程式碼。 | DBA | 

### 將 Oracle Data Guard 保護模式變更為 MaxAvailability
<a name="change-oracle-data-guard-protection-mode-to-maxavailability"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 存取主要資料庫上的 Data Guard 代理程式組態。 | 在此範例中，Amazon RDS Custom 僅供讀取複本`RDS_CUSTOM_ORCL_D`適用於非 CDB 執行個體和 CDB `RDS_CUSTOM_RDSCDB_B` 執行個體。非 CDB 的資料庫為 `orcl_a`（主要） 和 `orcl_d`（待命）。CDB 的資料庫名稱為 `rdscdb_a`（主要） 和 `rdscdb_b`（待命）。您可以直接或透過主要資料庫連線至 RDS Custom 僅供讀取複本。您可以在 `$ORACLE_HOME/network/admin`目錄中的 `tnsnames.ora` 檔案中找到資料庫的淨服務名稱。RDS Custom for Oracle 會自動為您的主要資料庫和僅供讀取複本填入這些項目。`RDS_DATAGUARD` 使用者的密碼存放在 AWS Secrets Manager 中，秘密名稱為 `do-not-delete-rds-custom-+<<RDS Resource ID>>+-dg`。如需如何使用從 Secrets Manager 擷取的 SSH （安全殼層） 金鑰連線至 RDS Custom 執行個體的詳細資訊，請參閱[使用 SSH 連線至 RDS Custom 資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-creating.html#custom-creating.ssh)。若要透過 Data Guard 命令列 (`dgmgrl`) 存取 Oracle Data Guard 代理程式組態，請使用下列程式碼。**非 CDB**<pre>$ dgmgrl RDS_DATAGUARD@RDS_CUSTOM_ORCL_D<br />DGMGRL for Linux: Release 19.0.0.0.0 - Production on Fri Sep 30 22:44:49 2022<br />Version 19.10.0.0.0<br />Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.<br />Welcome to DGMGRL, type "help" for information.<br />Password:<br />Connected to "ORCL_D"<br />Connected as SYSDG.<br />DGMGRL> <br />DGMGRL> show database orcl_d<br />Database - orcl_d<br />Role: PHYSICAL STANDBY<br />Intended State: APPLY-ON<br />Transport Lag: 0 seconds (computed 0 seconds ago)<br />Apply Lag: 0 seconds (computed 0 seconds ago)<br />Average Apply Rate: 11.00 KByte/s<br />Instance(s):<br />ORCL<br />SUCCESS<br />DGMGRL></pre>**CDB**<pre>-bash-4.2$ dgmgrl C##RDS_DATAGUARD@RDS_CUSTOM_RDSCDB_B<br />DGMGRL for Linux: Release 19.0.0.0.0 - Production on Wed Jan 11 20:24:11 2023<br />Version 19.16.0.0.0<br />Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.<br />Welcome to DGMGRL, type "help" for information.<br />Password:<br />Connected to "RDSCDB_B"<br />Connected as SYSDG.<br />DGMGRL><br />DGMGRL> show database rdscdb_b<br />Database - rdscdb_b<br />  Role:               PHYSICAL STANDBY<br />  Intended State:     APPLY-ON<br />  Transport Lag:      0 seconds (computed 1 second ago)<br />  Apply Lag:          0 seconds (computed 1 second ago)<br />  Average Apply Rate: 2.00 KByte/s<br />  Real Time Query:    OFF<br />  Instance(s):<br />    RDSCDB<br />Database Status:<br />SUCCESS<br />DGMGRL></pre> | DBA | 
| 從主節點連線至 DGMGRL 以變更日誌傳輸設定。 | 將日誌傳輸模式變更為 `FastSync`，對應於重做傳輸設定 `SYNC+NOAFFIRM`。為了確保您在角色切換後擁有有效的設定，請同時變更主要資料庫和待命資料庫。**非 CDB**<pre>DGMGRL><br />DGMGRL> edit database orcl_d set property logxptmode=fastsync;<br />Property "logxptmode" updated<br />DGMGRL> show database orcl_d LogXptMode;<br />LogXptMode = 'fastsync'<br />DGMGRL> edit database orcl_a set property logxptmode=fastsync;<br />Property "logxptmode" updated<br />DGMGRL> show database orcl_a logxptmode;<br />LogXptMode = 'fastsync'<br />DGMGRL>   </pre>**CDB**<pre>DGMGRL> edit database rdscdb_b set property logxptmode=fastsync;DGMGRL> edit database rdscdb_b set property logxptmode=fastsync;<br />Property "logxptmode" updated<br />DGMGRL> show database rdscdb_b LogXptMode;<br />  LogXptMode = 'fastsync'<br />DGMGRL> edit database rdscdb_a set property logxptmode=fastsync;<br />Property "logxptmode" updated<br />DGMGRL> show database rdscdb_a logxptmode;<br />  LogXptMode = 'fastsync'<br />DGMGRL></pre> | DBA | 
| 將保護模式變更為 MaxAvailability。 | `DGMGRL` 從主節點`MaxAvailability`連線至 ，將保護模式變更為 。**非 CDB**<pre>DGMGRL> edit configuration set protection mode as maxavailability;<br />Succeeded.<br />DGMGRL> show configuration;<br />Configuration - rds_dg<br />Protection Mode: MaxAvailability<br />Members:<br />orcl_a - Primary database<br />orcl_d - Physical standby database <br />Fast-Start Failover: Disabled<br />Configuration Status:<br />SUCCESS (status updated 38 seconds ago)<br />DGMGRL> </pre>**CDB**<pre>DGMGRL> show configuration<br />Configuration - rds_dg<br />  Protection Mode: MaxAvailability<br />  Members:<br />  rdscdb_a - Primary database<br />    rdscdb_b - Physical standby database <br />Fast-Start Failover:  Disabled<br />Configuration Status:<br />SUCCESS   (status updated 57 seconds ago)<br />DGMGRL></pre> | DBA | 

### 將複本狀態從掛載變更為唯讀，並啟用重做
<a name="change-the-replica-status-from-mount-to-read-only-and-enable-redo-apply"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止重做會套用至待命資料庫。 | 依預設，僅供讀取複本會在 `MOUNT` 模式中建立。若要以唯讀模式開啟它，您必須先`DGMGRL`從主要節點或待命節點連線至 來關閉重做套用。**非 CDB**<pre>DGMGRL> show database orcl_dDGMGRL> show database orcl_d<br />Database - orcl_d<br />Role: PHYSICAL STANDBY<br />Intended State: APPLY-ON<br />Transport Lag: 0 seconds (computed 1 second ago)<br />Apply Lag: 0 seconds (computed 1 second ago)<br />Average Apply Rate: 11.00 KByte/s<br />Real Time Query: OFF<br />Instance(s):<br />ORCL<br />Database Status:<br />SUCCESS<br />DGMGRL> edit database orcl_d set state=apply-off;<br />Succeeded.<br />DGMGRL> show database orcl_d<br />Database - orcl_d<br />Role: PHYSICAL STANDBY<br />Intended State: APPLY-OFF<br />Transport Lag: 0 seconds (computed 1 second ago)<br />Apply Lag: 42 seconds (computed 1 second ago)<br />Average Apply Rate: (unknown)<br />Real Time Query: OFF<br />Instance(s):<br />ORCL<br />Database Status:<br />SUCCESS<br />DGMGRL></pre>**CDB**<pre>DGMGRL> show configurationDGMGRL> show configuration<br />Configuration - rds_dg<br />  Protection Mode: MaxAvailability<br />  Members:<br />  rdscdb_a - Primary database<br />    rdscdb_b - Physical standby database <br />Fast-Start Failover:  Disabled<br />Configuration Status:<br />SUCCESS   (status updated 57 seconds ago)<br />DGMGRL> show database rdscdb_b;<br />Database - rdscdb_b<br />  Role:               PHYSICAL STANDBY<br />  Intended State:     APPLY-ON<br />  Transport Lag:      0 seconds (computed 1 second ago)<br />  Apply Lag:          0 seconds (computed 1 second ago)<br />  Average Apply Rate: 2.00 KByte/s<br />  Real Time Query:    OFF<br />  Instance(s):<br />    RDSCDB<br />Database Status:<br />SUCCESS<br />DGMGRL> edit database rdscdb_b set state=apply-off;<br />Succeeded.<br />DGMGRL> show database rdscdb_b;<br />Database - rdscdb_b<br />  Role:               PHYSICAL STANDBY<br />  Intended State:     APPLY-OFF<br />  Transport Lag:      0 seconds (computed 1 second ago)<br />  Apply Lag:          0 seconds (computed 1 second ago)<br />  Average Apply Rate: (unknown)<br />  Real Time Query:    OFF<br />  Instance(s):<br />    RDSCDB<br />Database Status:<br />SUCCESS</pre> | DBA | 
| 以唯讀模式開啟僅供讀取複本執行個體。 | 使用 TNS 項目連接至待命資料庫，並從主要節點或待命節點連接至待命資料庫，以唯讀模式開啟該資料庫。**非 CDB**<pre>$ sqlplus RDS_DATAGUARD@RDS_CUSTOM_ORCL_D as sysdg<br />-bash-4.2$ sqlplus RDS_DATAGUARD@RDS_CUSTOM_ORCL_D as sysdg<br />SQL*Plus: Release 19.0.0.0.0 - Production on Fri Sep 30 23:00:14 2022<br />Version 19.10.0.0.0<br />Copyright (c) 1982, 2020, Oracle. All rights reserved.<br />Enter password: <br />Last Successful login time: Fri Sep 30 2022 22:48:27 +00:00<br />Connected to:<br />Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production<br />Version 19.10.0.0.0<br />SQL> select open_mode from v$database;<br />OPEN_MODE<br />--------------------<br />MOUNTED<br />SQL> alter database open read only;<br />Database altered.<br />SQL> select open_mode from v$database;<br />OPEN_MODE<br />--------------------<br />READ ONLY<br />SQL> </pre>**CDB**<pre>-bash-4.2$ sqlplus C##RDS_DATAGUARD@RDS_CUSTOM_RDSCDB_B as sysdg<br />SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jan 11 21:14:07 2023<br />Version 19.16.0.0.0<br />Copyright (c) 1982, 2022, Oracle.  All rights reserved.<br />Enter password: <br />Last Successful login time: Wed Jan 11 2023 21:12:05 +00:00<br />Connected to:<br />Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production<br />Version 19.16.0.0.0<br />SQL> select name,open_mode from v$database;<br />NAME   OPEN_MODE<br />--------- --------------------<br />RDSCDB   MOUNTED<br />SQL> alter database open read only;<br />Database altered.<br />SQL> select name,open_mode from v$database;<br />NAME   OPEN_MODE<br />--------- --------------------<br />RDSCDB   READ ONLY<br />SQL></pre> | DBA | 
| 在僅供讀取複本執行個體上啟用重做。 | 使用主要節點或待命節點中的 `DGMGR`L，在僅供讀取複本執行個體上啟用重做。**非 CDB**<pre>$ dgmgrl RDS_DATAGUARD@RDS_CUSTOM_ORCL_D<br />DGMGRL for Linux: Release 19.0.0.0.0 - Production on Fri Sep 30 23:02:16 2022<br />Version 19.10.0.0.0<br />Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.<br />Welcome to DGMGRL, type "help" for information.<br />Password:<br />Connected to "ORCL_D"<br />Connected as SYSDG.<br />DGMGRL> <br />edit database orcl_d set state=apply-on;<br />DGMGRL> edit database orcl_d set state=apply-on;<br />Succeeded.<br />DGMGRL> show database orcl_d<br />Database - orcl_d<br />Role: PHYSICAL STANDBY<br />Intended State: APPLY-ON<br />Transport Lag: 0 seconds (computed 0 seconds ago)<br />Apply Lag: 0 seconds (computed 0 seconds ago)<br />Average Apply Rate: 496.00 KByte/s<br />Real Time Query: ON<br />Instance(s):<br />ORCL<br />Database Status:<br />SUCCESS<br />DGMGRL></pre>**CDB**<pre>-bash-4.2$ dgmgrl C##RDS_DATAGUARD@RDS_CUSTOM_RDSCDB_B-bash-4.2$ dgmgrl C##RDS_DATAGUARD@RDS_CUSTOM_RDSCDB_B<br />DGMGRL for Linux: Release 19.0.0.0.0 - Production on Wed Jan 11 21:21:11 2023<br />Version 19.16.0.0.0<br />Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.<br />Welcome to DGMGRL, type "help" for information.<br />Password:<br />Connected to "RDSCDB_B"<br />Connected as SYSDG.<br />DGMGRL> edit database rdscdb_b set state=apply-on;<br />Succeeded.<br />DGMGRL> show database rdscdb_b           <br />Database - rdscdb_b<br />  Role:               PHYSICAL STANDBY<br />  Intended State:     APPLY-ON<br />  Transport Lag:      0 seconds (computed 0 seconds ago)<br />  Apply Lag:          0 seconds (computed 0 seconds ago)<br />  Average Apply Rate: 35.00 KByte/s<br />  Real Time Query:    ON<br />  Instance(s):<br />    RDSCDB<br />Database Status:<br />SUCCESS<br />DGMGRL> show database rdscdb_b   <br />Database - rdscdb_b<br />  Role:               PHYSICAL STANDBY<br />  Intended State:     APPLY-ON<br />  Transport Lag:      0 seconds (computed 1 second ago)<br />  Apply Lag:          0 seconds (computed 1 second ago)<br />  Average Apply Rate: 16.00 KByte/s<br />  Real Time Query:    ON<br />  Instance(s):<br />    RDSCDB<br />Database Status:<br />SUCCESS<br />DGMGRL></pre> | DBA | 

## 相關資源
<a name="add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica-resources"></a>
+ [將 Amazon RDS 設定為 Oracle PeopleSoft 資料庫](https://d1.awsstatic.com/whitepapers/configuring-amazon-rds-as-peoplesoft-database.pdf) (AWS 白皮書）
+ [Oracle Data Guard Broker 指南 ](https://docs.oracle.com/en/database/oracle/oracle-database/19/dgbkr/index.html)(Oracle 參考文件）
+ [Data Guard 概念和管理 ](https://docs.oracle.com/en/database/oracle/oracle-database/19/sbydb/index.html)(Oracle 參考文件）

## 其他資訊
<a name="add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica-additional"></a>

**選取您的資料庫保護模式**

Oracle Data Guard 提供三種保護模式，根據您的可用性、保護和效能需求來設定 Data Guard 環境。下表摘要說明這三種模式。


| 
| 
| 保護模式 | 重做傳輸設定 | Description | 
| --- |--- |--- |
| ***最大效能*** | `ASYNC` | 對於主要資料庫上發生的交易，重做資料會以非同步方式傳輸並寫入待命資料庫重做日誌。因此，效能影響極小。`MaxPerformance` 由於非同步日誌運送， 無法提供 RPO=0。 | 
| ***最大保護*** | `SYNC+AFFIRM` | 對於主要資料庫上的交易，在確認交易之前，重做資料會同步傳輸並寫入待命資料庫重做磁碟上的日誌。如果待命資料庫無法使用，主要資料庫會自行關閉，以確保交易受到保護。 | 
| ***最大可用性*** | `SYNC+AFFIRM` | 這類似於 `MaxProtection` 模式，除非未收到來自待命資料庫的確認。在這種情況下，它會像處於 `MaxPerformance` 模式一樣運作，以保留主要資料庫的可用性，直到能夠將其重做串流再次寫入同步待命資料庫為止。 | 
| `SYNC+NOAFFIRM` | 對於主要資料庫上的交易，重做會同步傳輸至待命資料庫，而主要只會等待確認已在待命上收到重做，而不是已寫入待命磁碟。此模式也稱為 `FastSync`，可在發生多個同時故障的特殊情況下，提供可能暴露於資料遺失的效能優勢。 | 

RDS Custom for Oracle 中的僅供讀取複本會以最大效能保護模式建立，這也是 Oracle Data Guard 的預設保護模式。最大效能模式可為主要資料庫提供最低的效能影響，這可協助您符合以秒為單位測量的復原點目標 (RPO) 需求。

若要實現零資料遺失 (RPO=0) 目標，您可以自訂 Oracle Data Guard 保護模式為 `MaxAvailability`，並使用 `SYNC+NOAFFIRM`設定進行重做傳輸以獲得更好的效能。由於只有在對應的重做向量成功傳輸到待命資料庫之後，才會確認主要資料庫上的遞交，因此主要執行個體和複本之間的網路延遲對於對遞交敏感的工作負載至關重要。我們建議您為工作負載執行負載測試，以評估在 僅供讀取複本自訂為在 `MaxAvailability` 模式下執行時的效能影響。

與在不同可用區域中部署僅供讀取複本相比，在與主要資料庫相同的可用區域中部署僅供讀取複本可提供較低的網路延遲。不過，在相同可用區域中部署主要和僅供讀取複本可能不符合您的 HA 需求，因為在極少數的可用區域無法使用的情況下，主要執行個體和僅供讀取複本執行個體都會受到影響。

# 分析從 Oracle 到 PostgreSQL 的部分資料庫遷移的物件相依性
<a name="multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql"></a>

*anuradha chintha，Amazon Web Services*

## 總結
<a name="multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql-summary"></a>

此模式說明將部分 Oracle 資料庫遷移至 Amazon Relational Database Service (Amazon RDS) 或 Amazon Aurora PostgreSQL 時，系統識別和管理系統相依性的重要性。在部分遷移中，只會遷移來自原始資料庫的資料庫物件和資料子集，而來源資料庫會繼續操作和提供依賴非遷移元件的應用程式

處理具有上游和下游相依性之緊密耦合應用程式的大規模資料庫時，您必須識別和分析遷移的範圍。若要開始部分遷移，請識別範圍物件，包括資料表、觸發條件、檢視、預存程序、函數和套件。範圍識別程序遵循全方位的方法：
+ 第一層範圍物件是透過應用程式程式碼和關鍵模組特定任務中的直接參考來識別。
+ 第二層物件是透過全面的相依性分析衍生的。

當您了解系統的不同部分如何互動時，您可以更好地規劃移動資料庫元件的正確順序，並降低遷移失敗的風險。下表列出不同類型的相依性分析。


| 
| 
| 分析類型 | 重點領域 | 用途 | 
| --- |--- |--- |
| 物件相依性 | 表格檢視預存程序函數觸發 | 識別資料庫物件與其階層結構之間的關係 | 
| 區段相依性 | 外部金鑰關係主要金鑰鏈跨結構描述參考 | 映射資料關係並維護參考完整性 | 
| 安全相依性 | 使用者許可角色階層物件權限 | 確保適當的存取控制遷移和安全性維護 | 
| 存取模式 | 讀取操作寫入操作 | 決定資料庫互動模式 | 

若要維持來源和目標系統之間的一致性，請在轉換期間建立資料同步機制。您還必須修改應用程式程式碼和函數，以處理來源 Oracle 和目標 PostgreSQL 資料庫之間的資料分佈。

## 先決條件和限制
<a name="multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ Oracle 資料庫 （來源）
+ Amazon RDS 或 Amazon Aurora PostgreSQL （目標）

**產品版本**
+ Oracle 19c 或更新版本
+ PostgreSQL 16 或更新版本

## Architecture
<a name="multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql-architecture"></a>

**來源技術堆疊**
+ Oracle 19c 或更新版本

**目標技術堆疊**
+ Amazon RDS 或 Amazon Aurora PostgreSQL

**目標架構**

下圖顯示從內部部署 Oracle 資料庫到 Amazon RDS for Oracle 的遷移程序，其中包含下列項目：
+ 識別資料庫相依性
+ 使用 AWS Schema Conversion Tool (AWS SCT) 遷移資料庫程式碼和物件
+ 使用 AWS Database Migration Service (AWS DMS) 遷移資料
+ 使用 透過變更資料擷取 (CDC) 複寫持續變更 AWS DMS

如需詳細資訊，請參閱 AWS 文件中的[整合 AWS Database Migration Service 與 AWS Schema Conversion Tool](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_DMSIntegration.html) 。

![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/90160825-3199-4382-95a8-ad63139c5c89/images/b09c36a4-27fa-412e-877e-57a31bcce0dc.png)


## 工具
<a name="multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql-tools"></a>

**AWS 服務**
+ [適用於 Oracle 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 可協助您在 中設定、操作和擴展 Oracle 關聯式資料庫 AWS 雲端。
+ Amazon Aurora 是一種全受管關聯式資料庫引擎，專為雲端而建置，並與 MySQL 和 PostgreSQL 相容。
+ AWS Schema Conversion Tool (AWS SCT) 透過自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，支援異質資料庫遷移。
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移到 AWS 雲端 或在雲端和內部部署設定的組合之間遷移。

**其他服務**
+ [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) 是一種整合的開發環境，可簡化傳統和雲端部署中 Oracle 資料庫的開發和管理。對於此模式，您可以使用 [SQL\$1Plus](https://docs.oracle.com/cd/B19306_01/server.102/b14357/qstart.htm)。

## 最佳實務
<a name="multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql-best-practices"></a>

如需佈建和遷移 Oracle 資料庫的最佳實務，請參閱[遷移至 Amazon RDS for Oracle 的最佳實務](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/best-practices.html)。

## 史詩
<a name="multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql-epics"></a>

### 識別物件相依性
<a name="identify-object-dependencies"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立物件資料表。 | 識別對應用程式功能至關重要的物件，並建立名為 的資料表`DEPENDENT_ANALYSIS_BASELINE`。將每個物件的記錄新增至資料表。如需範例，請參閱*其他資訊*一節。 | 資料工程師，DBA | 
| 建立資料庫程序。 | 建立名為 的預存程序`sp_object_dependency_analysis`，使用`DBA_DEPENDENCIES`資料表中的資料以雙向 （向前和向後） 分析物件相依性。如需範例，請參閱*其他資訊*一節。 | 資料工程師，DBA | 
| 執行程序。 | 在每個連續層級執行指令碼，直到找不到新的物件相依性為止。所有相依性和關卡都存放在 `DEPENDENT_ANALYSIS_BASELINE` 資料表中。 | DBA，資料工程師 | 

### 建立區段層級相依性的程序
<a name="create-a-procedure-for-segment-level-dependencies"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立相依性資料表。 | 建立名為 的區段層級相依性資料表`REFERENTIAL_ANALYSIS_BASELINE`。發現所有物件層級相依性時，請透過查詢資料表`DEPENDENT_ANALYSIS_BASELINE`來檢查 的父`DBA_CONSTRAINT`資料表。排除其他資料表參考基準資料表的相依性。回填會處理這些關係。以下是範例指令碼：<pre>CREATE TABLE REFERENTIAL_ANALYSIS_BASELINE<br />(CHILD_OWNER VARCHAR2(50 BYTE),<br />CHILD_NAME VARCHAR2(100 BYTE),<br />PARENT_OWNER VARCHAR2(50 BYTE),<br />PARENT_NAME VARCHAR2(50 BYTE),<br />REFERENCE_PATH VARCHAR2(1000 BYTE));</pre> | 資料工程師，DBA | 
| 建立資料庫程序。 | 建立名為 的程序`SP_OBJECT_REFERENTIAL_ANALYSIS`，並產生所有已識別物件的參考分析。如需範例，請參閱*其他資訊*一節。 | 資料工程師，DBA | 
| 執行程序。 | 執行 程序以取得參考相依性。在 中產生參考分析物件詳細資訊`REFERENTIAL_ANALYSIS_BASELINE`。 | 資料工程師，DBA | 

### 識別讀取和寫入的物件
<a name="identify-objects-that-read-and-write"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立讀取和寫入物件的資料表。 | 使用下列指令碼建立名為 的讀取物件資料表`TABLE_READ_OBJECT_DETAILS`和名為 的寫入物件資料表`TABLE_WRITE_OBJECT_DETAILS`：<pre>CREATE TABLE TABLE_READ_OBJECT_DETAILS<br />(OWNER VARCHAR2(50 BYTE),<br />TAB_NAME VARCHAR2(50 BYTE),<br />READER_OWNER VARCHAR2(50 BYTE),<br />READER_NAME VARCHAR2(50 BYTE),<br />READER_TYPE VARCHAR2(50 BYTE));</pre><pre>CREATE TABLE TABLE_WRITE_OBJECT_DETAILS<br />(TABLE_NAME VARCHAR2(100 BYTE),<br />WRITEOBJ_OWNER VARCHAR2(100 BYTE),<br />WRITEOBJ_NAME VARCHAR2(100 BYTE),<br />WRITEOBJ_TYPE VARCHAR2(100 BYTE),<br />LINE VARCHAR2(100 BYTE),<br />TEXT VARCHAR2(4000 BYTE),<br />OWNER VARCHAR2(50 BYTE));</pre> | 資料工程師，DBA | 
| 建立分析程序。 | 分別建立`SP_WRITER_OBJECTS_ANALYSIS`用於分析讀取物件和寫入物件的程序 `SP_READER_OBJECTS_ANALYSIS`和 。這些程序使用模式比對來尋找相關物件。如需範例，請參閱*其他資訊*一節。 | 資料工程師，DBA | 
| 執行程序。 | 執行這些程序來識別相依物件。 | DBA，資料工程師 | 

### 檢閱資料庫權限
<a name="review-database-privileges"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立用於檢閱權限的資料表。 | 建立資料表以分析名為 的權限`OBJECT_PRIVS_ANALYSIS`。若要以遞迴方式擷取`DEPENDENT_ANALYSIS_BASELINE`資料表中的物件權限，請使用下列指令碼：<pre>CREATE TABLE OBJECT_PRIVS_ANALYSIS<br />(OWNER VARCHAR2(50 BYTE),<br />OBJECT_NAME VARCHAR2(50 BYTE),<br />USER_NAME VARCHAR2(50 BYTE),<br />PRIVS VARCHAR2(50 BYTE));</pre> | 資料工程師，DBA | 
| 建立檢閱權限的程序。 | 建立名為 的程序`SP_OBJECT_PRIVS_ANALYSIS`。產生已識別物件的權限分析。如需範例，請參閱*其他資訊*一節。 | DBA，資料工程師 | 
| 執行 程序。 | 執行 程序，在 `OBJECT_PRIVS_ANALYSIS` 資料表中擷取它們。 | DBA，資料工程師 | 

## 疑難排解
<a name="multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 無法存取字典資料表 | 確保建立分析物件的使用者可以存取 DBA 資料表。 | 

## 相關資源
<a name="multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql-resources"></a>

**AWS 文件**
+ [Amazon RDS 和 Aurora 文件](https://docs.aws.amazon.com/rds/)
+ [Oracle 資料庫 19c 至 Amazon Aurora PostgreSQL 遷移手冊](https://docs.aws.amazon.com/dms/latest/oracle-to-aurora-postgresql-migration-playbook/chap-oracle-aurora-pg.html)
+ [什麼是 AWS Database Migration Service？](https://docs.aws.amazon.com/dms/latest/userguide/)
+ [什麼是 AWS Schema Conversion Tool？](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/)

**其他文件**
+ [Oracle 資料庫物件](https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Database-Objects.html)

## 其他資訊
<a name="multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql-additional"></a>

**的指令碼 `DEPENDENT_ANALYSIS_BASELINE`**

```
CREATE TABLE DEPENDENT_ANALYSIS_BASELINE
(OWNER VARCHAR2(128 BYTE) NOT NULL ENABLE,
OBJECT_NAME VARCHAR2(128 BYTE) NOT NULL ENABLE,
OBJECT_TYPE VARCHAR2(20 BYTE),
DEPEDNCY_LEVEL NUMBER,
PROJECT_NEED VARCHAR2(20 BYTE),
CATAGORY VARCHAR2(4000 BYTE),
COMMENTS VARCHAR2(4000 BYTE),
CATAGORY1 CLOB,
COMMENTS1 CLOB,
CUSTOMER_COMMENTS VARCHAR2(1000 BYTE),
BACKFILL_TO_GUS VARCHAR2(1000 BYTE),
BACKFILL_NEAR_REAL_TIME_OR_BATCH VARCHAR2(1000 BYTE),
PK_EXISTS VARCHAR2(3 BYTE),
UI_EXISTS VARCHAR2(3 BYTE),
LOB_EXISTS VARCHAR2(3 BYTE),
MASTER_LINK VARCHAR2(100 BYTE),
CONSTRAINT PK_DEPENDENT_ANALYSIS_BASELINE PRIMARY KEY (OWNER,OBJECT_NAME,OBJECT_TYPE));
```

**的程序 `SP_WRITER_OBJECTS_ANALYSIS`**

```
CREATE OR REPLACE PROCEDURE SP_WRITER_OBJECTS_ANALYSIS IS
BEGIN
  EXECUTE IMMEDIATE 'TRUNCATE TABLE TABLE_WRITE_OBJECT_DETAILS';
  FOR I IN (SELECT OWNER, OBJECT_NAME FROM DEPENDENT_ANALYSIS_BASELINE WHERE OBJECT_TYPE = 'TABLE')
  LOOP
    INSERT INTO TABLE_WRITE_OBJECT_DETAILS(OWNER, TABLE_NAME, WRITEOBJ_OWNER, WRITEOBJ_NAME, WRITEOBJ_TYPE, LINE, TEXT)
    SELECT DISTINCT I.OWNER, I.OBJECT_NAME, OWNER WRITEOBJ_OWNER, NAME, TYPE, LINE, TRIM(TEXT)
    FROM DBA_SOURCE 
    WHERE UPPER(TEXT) LIKE '%' || I.OBJECT_NAME || '%'
      AND (UPPER(TEXT) LIKE '%INSERT%' || I.OBJECT_NAME || '%' 
        OR UPPER(TEXT) LIKE '%UPDATE%' || I.OBJECT_NAME || '%' 
        OR UPPER(TEXT) LIKE '%DELETE%' || I.OBJECT_NAME || '%' 
        OR UPPER(TEXT) LIKE '%UPSERT%' || I.OBJECT_NAME || '%' 
        OR UPPER(TEXT) LIKE '%MERGE%' || I.OBJECT_NAME || '%') 
      AND UPPER(TEXT) NOT LIKE '%PROCEDURE%' 
      AND UPPER(TEXT) NOT LIKE 'PROCEDURE%' 
      AND UPPER(TEXT) NOT LIKE '%FUNCTION%' 
      AND UPPER(TEXT) NOT LIKE 'FUNCTION%'
      AND UPPER(TEXT) NOT LIKE '%TRIGGER%' 
      AND UPPER(TEXT) NOT LIKE 'TRIGGER%' 
      AND UPPER(TRIM(TEXT)) NOT LIKE '%AFTER UPDATE%' 
      AND UPPER(TRIM(TEXT)) NOT LIKE 'BEFORE UPDATE%' 
      AND UPPER(TRIM(TEXT)) NOT LIKE 'BEFORE INSERT%' 
      AND UPPER(TRIM(TEXT)) NOT LIKE 'AFTER INSERT%' 
      AND UPPER(TRIM(TEXT)) NOT LIKE 'BEFORE DELETE%' 
      AND UPPER(TRIM(TEXT)) NOT LIKE 'AFTER DELETE%' 
      AND UPPER(TRIM(TEXT)) NOT LIKE '%GGLOGADM.GG_LOG_ERROR%' 
      AND (TRIM(TEXT) NOT LIKE '/*%' AND TRIM(TEXT) NOT LIKE '--%' ) 
      AND (OWNER, NAME, TYPE) IN (SELECT OWNER, NAME, TYPE FROM DBA_DEPENDENCIES WHERE REFERENCED_NAME = I.OBJECT_NAME);
  END LOOP;
END;
```

**的指令碼 `SP_READER_OBJECTS_ANALYSIS`**

```
CREATE OR REPLACE PROCEDURE SP_READER_OBJECTS_ANALYSIS IS
BEGIN
  EXECUTE IMMEDIATE 'TRUNCATE TABLE TABLE_READ_OBJECT_DETAILS';
  FOR I IN (SELECT OWNER, OBJECT_NAME FROM DEPENDENT_ANALYSIS_BASELINE WHERE OBJECT_TYPE = 'TABLE')
  LOOP
    INSERT INTO TABLE_READ_OBJECT_DETAILS
    SELECT DISTINCT i.owner, i.object_name, owner, name, type 
    FROM dba_dependencies 
    WHERE referenced_name = I.OBJECT_NAME
    AND referenced_type = 'TABLE' 
    AND type NOT IN ('SYNONYM', 'MATERIALIZED VIEW', 'VIEW') 
    AND (owner, name, type) NOT IN (
      SELECT DISTINCT owner, trigger_name, 'TRIGGER' 
      FROM dba_triggers 
      WHERE table_name = I.OBJECT_NAME 
      AND table_owner = i.owner
      UNION ALL
      SELECT DISTINCT owner, name, type 
      FROM dba_source
      WHERE upper(text) LIKE '%' || I.OBJECT_NAME || '%' 
      AND (upper(text) LIKE '%INSERT %' || I.OBJECT_NAME || '%' 
        OR upper(text) LIKE '%UPDATE% ' || I.OBJECT_NAME || '%' 
        OR upper(text) LIKE '%DELETE %' || I.OBJECT_NAME || '%' 
        OR upper(text) LIKE '%UPSERT %' || I.OBJECT_NAME || '%' 
        OR upper(text) LIKE '%MERGE %' || I.OBJECT_NAME || '%') 
      AND upper(text) NOT LIKE '%PROCEDURE %' 
      AND upper(text) NOT LIKE 'PROCEDURE %'
      AND upper(text) NOT LIKE '%FUNCTION %' 
      AND upper(text) NOT LIKE 'FUNCTION %'
      AND upper(text) NOT LIKE '%TRIGGER %'
      AND upper(text) NOT LIKE 'TRIGGER %'
      AND upper(trim(text)) NOT LIKE 'BEFORE INSERT %'
      AND upper(trim(text)) NOT LIKE 'BEFORE UPDATE %' 
      AND upper(trim(text)) NOT LIKE 'BEFORE DELETE %' 
      AND upper(trim(text)) NOT LIKE 'AFTER INSERT %' 
      AND upper(trim(text)) NOT LIKE 'AFTER UPDATE %' 
      AND upper(trim(text)) NOT LIKE 'AFTER DELETE %' 
      AND (trim(text) NOT LIKE '/*%' AND trim(text) NOT LIKE '--%'));
  END LOOP;
END;
```

**的指令碼 `SP_OBJECT_REFERENTIAL_ANALYSIS`**

```
CREATE OR REPLACE PROCEDURE SP_OBJECT_REFERENTIAL_ANALYSIS IS
BEGIN
  EXECUTE IMMEDIATE 'TRUNCATE TABLE REFERENTIAL_ANALYSIS_BASELINE';
  INSERT INTO REFERENTIAL_ANALYSIS_BASELINE
  WITH rel AS (
    SELECT DISTINCT c.owner, c.table_name, c.r_owner r_owner,
      (SELECT table_name FROM dba_constraints 
       WHERE constraint_name = c.r_constraint_name 
       AND owner = c.r_owner) r_table_name 
    FROM dba_constraints c 
    WHERE constraint_type = 'R' 
    AND c.owner NOT IN (SELECT username FROM dba_users WHERE oracle_maintained = 'Y')
    AND c.r_owner NOT IN (SELECT username FROM dba_users WHERE oracle_maintained = 'Y')),
  tab_list AS (
    SELECT OWNER, object_name 
    FROM DEPENDENT_ANALYSIS_BASELINE 
    WHERE UPPER(OBJECT_TYPE) = 'TABLE')
  SELECT DISTINCT owner child_owner, table_name child, r_owner parent_owner,
    r_table_name parent, SYS_CONNECT_BY_PATH(r_table_name, ' -> ') || ' -> ' || table_name PATH
  FROM rel 
  START WITH (r_owner, r_table_name) IN (SELECT * FROM tab_list)
  CONNECT BY NOCYCLE (r_owner, r_table_name) = ((PRIOR owner, PRIOR table_name))
  UNION
  SELECT DISTINCT owner child_owner, table_name child, r_owner parent_owner,
    r_table_name parent, SYS_CONNECT_BY_PATH(table_name, ' -> ') || ' -> ' || r_table_name PATH
  FROM rel 
  START WITH (owner, table_name) IN (SELECT * FROM tab_list)
  CONNECT BY NOCYCLE (owner, table_name) = ((PRIOR r_owner, PRIOR r_table_name));
END;
```

**的指令碼 `SP_OBJECT_PRIVS_ANALYSIS`**

```
CREATE OR REPLACE PROCEDURE SP_OBJECT_PRIVS_ANALYSIS IS
  V_SQL VARCHAR2(4000);
  V_CNT NUMBER;
BEGIN
  V_SQL := 'TRUNCATE TABLE OBJECT_PRIVS_ANALYSIS';
  EXECUTE IMMEDIATE V_SQL;
  FOR I IN (SELECT OWNER, OBJECT_NAME FROM DEPENDENT_ANALYSIS_BASELINE WHERE OBJECT_TYPE = 'TABLE')
  LOOP
    INSERT INTO OBJECT_PRIVS_ANALYSIS(OWNER, OBJECT_NAME, USER_NAME, PRIVS)
    WITH obj_to_role AS (
      SELECT DISTINCT GRANTEE role_name, 
        DECODE(privilege, 'SELECT', 'READ', 'REFERENCE', 'READ', 'INSERT', 'WRITE', 
               'UPDATE', 'WRITE', 'DELETE', 'WRITE', privilege) privs
      FROM DBA_TAB_PRIVS t, DBA_ROLES r 
      WHERE OWNER = I.OWNER 
      AND TYPE = 'TABLE' 
      AND TABLE_NAME = I.OBJECT_NAME 
      AND t.GRANTEE = r.ROLE 
      AND r.ROLE IN (SELECT ROLE FROM DBA_ROLES WHERE ORACLE_MAINTAINED = 'N')
    )
    SELECT I.OWNER, I.OBJECT_NAME, grantee, privs 
    FROM (
      -- Recursively Role to User mapping with privilege
      SELECT DISTINCT grantee, privs 
      FROM (SELECT rp.granted_role, rp.grantee, privs,
        (SELECT DECODE(COUNT(*), 0, 'ROLE', 'USER') 
         FROM (SELECT 'User' FROM DBA_users WHERE username = rp.GRANTEE)) grantee_type 
        FROM DBA_role_privs rp, obj_to_role r 
        WHERE rp.granted_role = r.role_name 
        AND grantee IN ((SELECT USERNAME FROM DBA_USERS WHERE ORACLE_MAINTAINED = 'N') 
                       UNION (SELECT ROLE FROM DBA_ROLES WHERE ORACLE_MAINTAINED = 'N'))
        AND granted_role IN (SELECT ROLE FROM DBA_ROLES WHERE ORACLE_MAINTAINED = 'N') 
        START WITH granted_role IN (SELECT DISTINCT role_name FROM obj_to_role) 
        CONNECT BY granted_role = PRIOR grantee) 
      WHERE grantee_type = 'USER'
    )
    UNION
    (
      -- Direct Object grants to User
      SELECT I.OWNER, I.OBJECT_NAME, GRANTEE, 
        DECODE(privilege, 'SELECT', 'READ', 'REFERENCE', 'READ', 'INSERT', 'WRITE',
               'UPDATE', 'WRITE', 'DELETE', 'WRITE', privilege) privs 
      FROM DBA_TAB_PRIVS, DBA_USERS 
      WHERE GRANTEE = USERNAME 
      AND OWNER = I.OWNER 
      AND TYPE = 'TABLE' 
      AND TABLE_NAME = I.OBJECT_NAME
    ) 
    ORDER BY 2 DESC;
  END LOOP;
END;
```

**的程序 `SP_OBJECT_DEPENDENCY_ANALYSIS`**

```
CREATE OR REPLACE PROCEDURE SP_OBJECT_DEPENDENCY_ANALYSIS (v_level NUMBER) IS
  TYPE typ IS RECORD (
    schema VARCHAR2(100),
    obj_type VARCHAR2(100),
    obj_name VARCHAR2(100),
    path VARCHAR2(5000)
  );
  TYPE array IS TABLE OF typ;
  l_data array;
  c SYS_REFCURSOR;
  l_errors NUMBER;
  l_errno NUMBER;
  l_msg VARCHAR2(4000);
  l_idx NUMBER;
  l_level NUMBER;
BEGIN
  l_level := v_level + 1;
  OPEN c FOR 
    WITH obj_list AS (
      SELECT owner schema_name, object_type, object_name 
      FROM DEPENDENT_ANALYSIS_BASELINE 
      WHERE depedncy_level = v_level
    ),
    fw_dep_objects AS (
      SELECT level lvl, owner, name, type, referenced_owner, referenced_name,
        referenced_type, SYS_CONNECT_BY_PATH(name, ' -> ') || ' -> ' || referenced_name PATH 
      FROM dba_dependencies
      START WITH (owner, CASE WHEN type = 'PACKAGE BODY' THEN 'PACKAGE' ELSE type END, name) 
        IN (SELECT schema_name, object_type, object_name FROM obj_list)
      CONNECT BY NOCYCLE (owner, type, name) = 
        ((PRIOR referenced_owner, PRIOR referenced_type, PRIOR referenced_name))
    ),
    bw_dep_objects AS (
      SELECT level lvl, owner, name, type, referenced_owner, referenced_name,
        referenced_type, SYS_CONNECT_BY_PATH(name, ' <- ') || ' <- ' || referenced_name PATH 
      FROM dba_dependencies
      START WITH (referenced_owner, CASE WHEN referenced_type = 'PACKAGE BODY' THEN 'PACKAGE' 
        ELSE referenced_type END, referenced_name) IN (SELECT schema_name, object_type, object_name FROM obj_list)
      CONNECT BY NOCYCLE (referenced_owner, referenced_type, referenced_name) = 
        ((PRIOR owner, PRIOR type, PRIOR name))
    )
    SELECT * FROM (
      (SELECT DISTINCT referenced_owner schema, referenced_type obj_type, 
        referenced_name obj_name, path FROM fw_dep_objects)
      UNION
      (SELECT DISTINCT owner schema, type obj_type, name obj_name, path 
       FROM bw_dep_objects)
    )
    WHERE schema IN (SELECT username FROM all_users WHERE oracle_maintained = 'N')
    ORDER BY obj_type;

  LOOP
    FETCH c BULK COLLECT INTO l_data LIMIT 100;
    BEGIN
      FORALL i IN 1..l_data.count SAVE EXCEPTIONS
        INSERT INTO DEPENDENT_ANALYSIS_BASELINE (
          owner, object_name, object_type, catagory, depedncy_level, project_need, comments
        ) 
        VALUES (
          l_data(i).schema, 
          l_data(i).obj_name,
          CASE WHEN l_data(i).obj_type = 'PACKAGE BODY' THEN 'PACKAGE' ELSE l_data(i).obj_type END,
          'level ' || l_level || ' dependency',
          l_level,
          '',
          'from dependency proc' || l_data(i).path
        );
    EXCEPTION
      WHEN OTHERS THEN
        l_errors := sql%bulk_exceptions.count;
        FOR i IN 1..l_errors LOOP
          l_errno := sql%bulk_exceptions(i).error_code;
          l_msg := SQLERRM(-l_errno);
          l_idx := sql%bulk_exceptions(i).error_index;
          UPDATE DEPENDENT_ANALYSIS_BASELINE 
          SET catagory1 = catagory1 || ', found in level' || l_level || ' dependent of ' || l_data(l_idx).path,
              comments1 = comments1 || ', from dependency proc exception ' || l_data(i).path
          WHERE owner = l_data(l_idx).schema 
          AND object_name = l_data(l_idx).obj_name 
          AND object_type = l_data(l_idx).obj_type;
        END LOOP;
    END;
    EXIT WHEN c%NOTFOUND;
  END LOOP;
  CLOSE c;
END;
```

# 評估將 SQL Server 資料庫遷移至 AWS 上的 MongoDB Atlas 的查詢效能
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws"></a>

*Battulga Purevragchaa，Amazon Web Services*

*Krishnakumar Sathyanarayana，PeerIslands 美國公司*

*Babu Srinivasan，MongoDB*

## 摘要
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-summary"></a>

此模式提供使用接近真實世界的資料載入 MongoDB，以及評估 MongoDB 查詢效能的指引，盡可能接近生產案例。評估提供輸入，協助您規劃從關聯式資料庫遷移至 MongoDB。此模式使用 [PeerIslands Test Data Generator 和 Performance Analyzer](https://tools.peerislands.io/) 來測試查詢效能。

此模式對於 Microsoft SQL Server 遷移至 MongoDB 特別有用，因為執行結構描述轉換並將資料從目前的 SQL Server 執行個體載入至 MongoDB 可能非常複雜。相反地，您可以將接近真實世界的資料載入 MongoDB、了解 MongoDB 效能，並在開始實際遷移之前微調結構描述設計。

## 先決條件和限制
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 熟悉 [MongoDB Atlas](https://www.mongodb.com/docs/atlas/getting-started/)
+ 目標 MongoDB 結構描述
+ 典型查詢模式

**限制**
+ 資料載入時間和效能會受到 MongoDB 叢集執行個體大小的限制。我們建議您選擇建議用於生產用途的執行個體，以了解實際效能。
+ PeerIslands Test Data Generator and Performance Analyzer 目前僅支援線上資料載入和查詢。尚未支援離線批次處理 （例如，使用 Spark 連接器將資料載入 MongoDB)。
+ PeerIslands Test Data Generator and Performance Analyzer 支援集合中的欄位關係。它不支援跨集合的關係。

**產品版本**
+ 此模式同時支援 [MongoDB Atlas](https://www.mongodb.com/atlas) 和 [MongoDB Enterprise Advanced](https://www.mongodb.com/products/mongodb-enterprise-advanced)。

## Architecture
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-architecture"></a>

**目標技術堆疊**
+ MongoDB Atlas 或 MongoDB Enterprise Advanced

**架構**

![\[評估將 SQL Server 資料庫遷移至 AWS 上 MongoDB Atlas 的查詢效能的架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/25f0ab73-d587-4bd0-9fc0-ac675d5aa349/images/717caae4-d52e-4c78-bb7d-2ecb5acccd42.png)


PeerIslands Test Data Generator and Performance Analyzer 是使用 Java 和 Angular 建置的，並將產生的資料存放在 Amazon Elastic Block Store (Amazon EBS)。此工具包含兩個工作流程：測試資料產生和效能測試。
+ 在測試資料產生中，您會建立範本，這是必須產生之資料模型的 JSON 表示法。建立範本後，您可以在目標集合中產生資料，如負載產生組態所定義。
+ 在效能測試中，您會建立設定檔。設定檔是一種多階段測試案例，您可以在其中設定建立、讀取、更新和刪除 (CRUD) 操作、彙總管道、每個操作的權重，以及每個階段的持續時間。建立設定檔之後，您可以根據組態在目標資料庫上執行效能測試。

PeerIslands Test Data Generator and Performance Analyzer 將其資料存放在 Amazon EBS 上，因此您可以使用任何 MongoDB 支援的連線機制，包括對等互連、允許清單和私有端點，將 Amazon EBS 連線至 MongoDB。根據預設，工具不包含操作元件；不過，如果需要，可以使用 Amazon Managed Service for Prometheus、Amazon Managed Grafana、Amazon CloudWatch 和 AWS Secrets Manager 進行設定。

## 工具
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-tools"></a>
+ [PeerIslands Test Data Generator and Performance Analyzer](https://tools.peerislands.io/) 包含兩個元件。測試資料產生器元件可協助您根據 MongoDB 結構描述產生高度客戶特定的真實世界資料。該工具完全由 UI 驅動，具有豐富的資料程式庫，可用於在 MongoDB 上快速產生數十億筆記錄。此工具也提供在 MongoDB 結構描述中的欄位之間實作關係的功能。Performance Analyzer 元件可協助您產生高度客戶特定的查詢和彙總，並在 MongoDB 上執行逼真的效能測試。您可以使用 Performance Analyzer，針對特定使用案例使用豐富的負載描述檔和參數化查詢來測試 MongoDB 效能。

## 最佳實務
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-best-practices"></a>

請參閱下列資源：
+ [MongoDB 結構描述設計最佳實務 ](https://www.mongodb.com/developer/products/mongodb/mongodb-schema-design-best-practices/)(MongoDB 開發人員網站）
+ [在 AWS 上部署 MongoDB Atlas 的最佳實務](https://www.mongodb.com/presentation/best-practices-of-deploying-mongodb-atlas-on-aws) (MongoDB 網站）
+ [使用 AWS PrivateLink 將應用程式安全地連接到 MongoDB Atlas 資料平面](https://aws.amazon.com/blogs/apn/connecting-applications-securely-to-a-mongodb-atlas-data-plane-with-aws-privatelink/) (AWS 部落格文章）
+ [MongoDB 效能的最佳實務指南 ](https://www.mongodb.com/basics/best-practices)(MongoDB 網站）

## 史詩
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-epics"></a>

### 了解您的來源資料
<a name="understand-your-source-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 了解目前 SQL Server 來源的資料庫使用量。 | 了解您目前的 SQL Server 使用量。這可以透過對資料庫的`INFORMATION`結構描述執行查詢來實現。決定資料表的數量和每個資料表的大小。分析與每個資料表相關聯的索引。如需 SQL 分析的詳細資訊，請參閱 PeerIslands 網站上的部落格文章 [SQL2Mongo：Data Migration Journey](https://engineering.peerislands.io/sql2mongo-data-migration-journey-fec91a421d60)。 | DBA | 
| 了解來源結構描述。 | 決定資料表結構描述和資料的業務表示方式 （例如，郵遞區號、名稱和貨幣）。使用您現有的實體關係 (ER) 圖表，或從現有的資料庫產生 ER 圖表。如需詳細資訊，請參閱 PeerIslands 網站上的部落格文章 [SQL2Mongo：Data Migration Journey](https://engineering.peerislands.io/sql2mongo-data-migration-journey-fec91a421d60)。 | DBA | 
| 了解查詢模式。 | 記錄您使用的前 10 個 SQL 查詢。您可以使用資料庫中可用的 **performance\$1schema.events\$1statements\$1summary\$1by\$1digest** 資料表來了解熱門查詢。如需詳細資訊，請參閱 PeerIslands 網站上的部落格文章 [SQL2Mongo：Data Migration Journey](https://engineering.peerislands.io/sql2mongo-data-migration-journey-fec91a421d60)。 | DBA | 
| 了解 SLA 承諾。 | 記錄資料庫操作的目標服務層級協議 (SLAs)。典型的措施包括查詢延遲和每秒查詢數。措施及其目標通常可在非功能需求 (NFR) 文件中取得。 | DBA | 

### 定義 MongoDB 結構描述
<a name="define-the-mongodb-schema"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 定義目標結構描述。 | 定義目標 MongoDB 結構描述的各種選項。如需詳細資訊，請參閱 MongoDB Atlas 文件中的[結構描述](https://www.mongodb.com/docs/atlas/app-services/schemas/)。根據資料表關係考慮最佳實務和設計模式。 | MongoDB 工程師 | 
| 定義目標查詢模式。 | 定義 MongoDB 查詢和彙總管道。這些查詢等同於您為 SQL Server 工作負載擷取的熱門查詢。若要了解如何建構 MongoDB 彙總管道，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/manual/core/aggregation-pipeline/)。 | MongoDB 工程師 | 
| 定義 MongoDB 執行個體類型。 | 決定您計劃用於測試的執行個體大小。如需指引，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/atlas/sizing-tier-selection/)。 | MongoDB 工程師 | 

### 準備目標資料庫
<a name="prepare-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 MongoDB Atlas 叢集。 | 若要在 AWS 上設定 MongoDB 叢集，請遵循 [MongoDB 文件](https://www.mongodb.com/docs/atlas/tutorial/create-new-cluster/)中的指示。 | MongoDB 工程師 | 
| 在目標資料庫中建立使用者。 | 遵循 MongoDB 文件中[的指示，設定 MongoDB ](https://www.mongodb.com/docs/atlas/connect-to-database-deployment/)Atlas 叢集以進行存取和網路安全。 | MongoDB 工程師 | 
| 在 AWS 中建立適當的角色，並設定 Atlas 的角色型存取控制。 | 如有必要，請遵循 [MongoDB 文件](https://www.mongodb.com/docs/atlas/security/set-up-unified-aws-access/)中的指示來設定其他使用者。透過 AWS 角色設定[身分驗證和授權](https://www.mongodb.com/docs/atlas/security/config-db-auth/)。 | MongoDB 工程師 | 
| 設定 MongoDB Atlas 存取的 Compass。 | 設定 [MongoDB Compass GUI 公用程式](https://www.mongodb.com/products/compass)，以便於導覽和存取。 | MongoDB 工程師 | 

### 使用測試資料產生器設定基本負載
<a name="set-up-the-base-load-by-using-test-data-generator"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝測試資料產生器。 | 在您的環境中安裝 [PeerIsland Test Data Generator](https://github.com/PeerIslands/loadgen_binary)。 | MongoDB 工程師 | 
| 設定測試資料產生器以產生適當的資料。 | 使用資料程式庫為 MongoDB 結構描述中的每個欄位產生特定資料，以建立範本。如需詳細資訊，請參閱 [MongoDB Data Generator & Perf。Analyzer](https://vimeo.com/570068857) 影片。 | MongoDB 工程師 | 
| 水平擴展測試資料產生器以產生所需的負載。 | 使用您建立的範本，透過設定所需的平行處理，開始針對目標集合產生負載。決定時間範圍並擴展以產生必要的資料。 | MongoDB 工程師 | 
| 驗證 MongoDB Atlas 中的負載。 | 檢查載入 MongoDB Atlas 的資料。 | MongoDB 工程師 | 
| 在 MongoDB 上產生所需的索引。 | 根據查詢模式，視需要定義索引。如需最佳實務，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/manual/applications/indexes/)。 | MongoDB 工程師 | 

### 執行效能測試
<a name="conduct-performance-testing"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Performance Analyzer 中設定負載描述檔。 | 透過設定特定查詢及其對應的權重、測試執行持續時間和階段，在 Performance Analyzer 中建立效能測試設定檔。如需詳細資訊，請參閱 [MongoDB Data Generator & Perf。Analyzer](https://vimeo.com/570068857) 影片。 | MongoDB 工程師 | 
| 執行效能測試。 | 使用您建立的效能測試描述檔，透過設定所需的平行處理開始針對目標集合進行測試。水平擴展效能測試工具，以針對 MongoDB Atlas 執行查詢。 | MongoDB 工程師 | 
| 記錄測試結果。 | 記錄查詢的 P95, P99 延遲。 | MongoDB 工程師 | 
| 調校您的結構描述和查詢模式。 | 修改索引和查詢模式，以解決任何效能問題。 | MongoDB 工程師 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 | 刪除您用於測試資料產生器和效能分析器的所有臨時資源。 | AWS 管理員 | 
| 更新效能測試結果。 | 了解 MongoDB 查詢效能並將其與您的 SLAs 進行比較。如有必要，請微調 MongoDB 結構描述並重新執行程序。 | MongoDB 工程師 | 
| 結束專案。 | 關閉專案並提供意見回饋。 | MongoDB 工程師 | 

## 相關資源
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-resources"></a>
+ GitHub 儲存庫：[S3toAtlas](https://github.com/mongodb-partners/S3toAtlas)
+ 結構描述：[MongoDB 結構描述設計](https://www.mongodb.com/developer/products/mongodb/mongodb-schema-design-best-practices/)
+ 彙總管道 ：[MongoDB 彙總管道](https://www.mongodb.com/docs/manual/core/aggregation-pipeline/)
+ MongoDB Atlas 大小：[大小層選擇](https://www.mongodb.com/docs/atlas/sizing-tier-selection/)
+ 影片：[MongoDB Data Generator](https://vimeo.com/570068857) & Perf。分析器
+ 參考：[MongoDB 文件](https://www.mongodb.com/docs/)
+ 教學課程：** **[MongoDB 開發人員指南、](https://www.mongodb.com/docs/develop-applications/)M[MongoDB Jumpstart](https://www.youtube.com/playlist?list=PL4RCxklHWZ9v2lcat4oEVGQhZg6r4IQGV)
+ AWS Marketplace：** **[AWS Marketplace 上的 MongoDB Atlas](https://aws.amazon.com/marketplace/seller-profile?id=c9032c7b-70dd-459f-834f-c1e23cf3d092)
+ AWS 合作夥伴解決方案：** **[ AWS 參考部署上的 MongoDB Atlas](https://aws.amazon.com/quickstart/architecture/mongodb-atlas/)

其他資源：
+ [SQL 分析](https://engineering.peerislands.io/sql2mongo-data-migration-journey-fec91a421d60)
+ [MongoDB 開發人員社群論壇](https://www.mongodb.com/community/forums/)
+ [MongoDB 效能調校問題](https://www.mongodb.com/developer/products/mongodb/performance-tuning-tips/)
+ [Atlas 和 Redshift 的操作分析](https://github.com/mongodb-partners/Atlas_to_Redshift)
+ [使用 MongoDB Atlas 和 AWS Elastic Beanstalk 進行應用程式現代化](https://github.com/mongodb-partners/MEANStack_with_Atlas_on_AWS_EB)

# 使用 IaC 原則自動化 Amazon Aurora 全域資料庫的藍/綠部署
<a name="p-automate-blue-green-deployments-aurora-global-databases-iac"></a>

*Ishwar Chauthaiwale、ANKIT JAIN 和 Ramu Jagini，Amazon Web Services*

## 總結
<a name="p-automate-blue-green-deployments-aurora-global-databases-iac-summary"></a>

對於在 [Amazon Aurora 全域資料庫](https://aws.amazon.com/rds/aurora/global-database/)上執行關鍵工作負載的組織而言，管理資料庫更新、遷移或擴展工作可能具有挑戰性。確保在零停機時間的情況下無縫執行這些操作，對於維護服務可用性和避免使用者中斷至關重要。

藍/綠部署策略可讓您同時執行兩個相同的環境，為這項挑戰提供解決方案：藍 （目前環境） 和綠 （新環境）。藍/綠策略可讓您實作變更、執行測試，並在風險最低且停機時間最低的環境中切換流量。

此模式使用基礎設施即程式碼 (IaC) 原則，協助您自動化 Aurora 全域資料庫的藍/綠部署程序。它使用 [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)、 [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)和 [Amazon Route 53](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/Welcome.html) 來簡化藍/綠部署。為了改善可靠性，它使用全域交易識別符 (GTIDs進行複寫。與二進位日誌 (binlog) 複寫相比， GTID 式複寫可在環境之間提供更好的資料一致性和容錯移轉功能。

**注意**  
此模式假設您使用的是 Aurora MySQL 相容版本全域資料庫叢集。如果您改為使用 Aurora PostgreSQL 相容，請使用 MySQL 命令的 PostgreSQL 對等項目。

透過遵循此模式中的步驟，您可以：
+ 佈建綠色 Aurora 全域資料庫：使用 CloudFormation 範本，您可以建立反映現有藍色環境的綠色環境。
+ 設定 GTID 式複寫：您可以設定 GTID 複寫，讓藍色和綠色環境保持同步。
+ 無縫切換流量：您可以使用 Route 53 和 Lambda，在完全同步後自動將流量從藍色環境切換到綠色環境。
+ 完成部署：您驗證綠色環境作為主要資料庫可完全運作，然後停止複寫並清除任何臨時資源。

此模式中的方法提供下列優點：
+ 在關鍵資料庫更新或遷移期間減少停機時間：自動化可確保在環境之間順利轉換，並將服務中斷降至最低。
+ 啟用快速復原：如果流量切換到綠色環境後發生問題，您可以快速恢復到藍色環境並維持服務連續性。
+ 增強測試和驗證：綠色環境可以完整測試，而不會影響即時藍色環境，從而降低生產過程中發生錯誤的可能性。
+ 確保資料一致性：以 GTID 為基礎的複寫可讓您的藍色和綠色環境保持同步，防止資料在遷移期間遺失或不一致。
+ 維持業務連續性：自動化藍/綠部署有助於避免長時間中斷和財務損失，方法是在更新或遷移期間保持您的服務可用。

## 先決條件和限制
<a name="p-automate-blue-green-deployments-aurora-global-databases-iac-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。
+ 來源 Aurora MySQL 相容全域資料庫叢集 （藍色環境）。全域資料庫提供多區域組態，以實現高可用性和災難復原。如需設定全域資料庫叢集的說明，請參閱 [Aurora 文件](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-getting-started.html)。
+ 在來源叢集上啟用 [GTID 型複寫](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/mysql-replication-gtid.html)。

**限制**
+ 有些 AWS 服務 不適用於所有 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

**產品版本**
+ Aurora MySQL 相容 8.0 或更新版本

## Architecture
<a name="p-automate-blue-green-deployments-aurora-global-databases-iac-architecture"></a>

![\[使用 GTID 複寫來同步不同區域中的藍色和綠色環境。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/19922266-c2e5-460b-9a0f-22e6d6736094/images/7a8c3095-7904-4080-906f-0c403c289a4f.png)


此圖展示了以下要點：
+ 全域資料庫設定：Aurora 全域資料庫叢集策略性地部署在兩個資料庫叢集中 AWS 區域。此組態可啟用地理分佈和區域備援，以增強災難復原功能。
+ 主要至次要區域複寫：邏輯複寫機制可確保從主要區域到次要區域的無縫資料同步。此複寫會在地理距離之間維持資料一致性，並將延遲降至最低。
+ 叢集之間的 GTID 式複寫：GTID 式複寫可維持藍色主要叢集與綠色主要叢集之間的交易一致性和排序資料流程，並確保可靠的資料同步。
+ 藍色主要至次要複寫：邏輯複寫會在藍色主要叢集及其次要叢集之間建立強大的資料管道。此複寫可實現持續資料同步和高可用性。
+ Route 53 DNS 組態：Route 53 託管區域記錄會管理所有藍色和綠色叢集資料庫端點的 DNS 解析。此組態提供無縫的端點映射，並在容錯移轉案例期間啟用有效的流量路由。

## 工具
<a name="p-automate-blue-green-deployments-aurora-global-databases-iac-tools"></a>

**AWS 服務**
+ [Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html) 是一種全受管關聯式資料庫引擎，專為雲端而建置，並與 MySQL 和 PostgreSQL 相容。
+ [CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可協助您建立和設定 AWS 資源的模型，以減少管理這些資源的時間，並有更多時間專注於執行 的應用程式 AWS。您可以建立範本來描述您想要的所有 AWS 資源，CloudFormation 會為您佈建和設定這些資源。
+  [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一種運算服務，支援執行程式碼，無需佈建或管理伺服器。Lambda 只有在需要時才會執行程式碼，可自動從每天數項請求擴展成每秒數千項請求。 
+ [Amazon Route 53](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/Welcome.html) 是一種可用性高、可擴展性強的 DNS Web 服務。

## 最佳實務
<a name="p-automate-blue-green-deployments-aurora-global-databases-iac-best-practices"></a>

建議您徹底檢閱 AWS 文件，以深入了解 Route 53 中的[藍/綠部署策略](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/blue-green-deployments-overview.html)、[GTID 式複寫](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/mysql-replication-gtid.html)和[加權路由政策](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy-weighted.html)。此知識對於有效實作和管理資料庫遷移、確保資料一致性，以及最佳化流量路由至關重要。透過全面了解這些 AWS 功能和最佳實務，您將更能處理未來的更新、盡可能減少停機時間，並維護彈性且安全的資料庫環境。

如需針對此模式使用 AWS 服務 的指導方針，請參閱下列 AWS 文件：
+ [Amazon Aurora MySQL 的最佳實務](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.BestPractices.html)
+ [CloudFormation 最佳實務](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html)
+ [使用 AWS Lambda 函數的最佳實務](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html)
+ [Amazon Route 53 的最佳實務](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/best-practices.html)

## 史詩
<a name="p-automate-blue-green-deployments-aurora-global-databases-iac-epics"></a>

### 建立綠色環境
<a name="create-the-green-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從藍色叢集建立快照備份。 | 在藍/綠部署中，綠色環境代表您目前 （藍色） 資料庫環境的新相同版本。您可以在切換生產流量之前，使用綠色環境安全地測試更新、驗證變更並確保穩定性。它可做為實作資料庫變更的預備基礎，並將對即時環境的干擾降至最低。若要建立綠色環境，請先在 Aurora MySQL 相容全域資料庫中建立主要 （藍色） 叢集的快照。此快照是建立綠色環境的基礎。若要建立快照：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)或者，您可以使用 AWS Command Line Interface (AWS CLI) 來建立快照：<pre>aws rds create-db-cluster-snapshot --db-cluster-snapshot-identifier blue-green-demo --db-cluster-identifier ex-global-cluster --region eu-west-1</pre>在繼續下一個步驟之前，請確定快照已成功完成。 | DBA | 
| 為您的全域資料庫及其資源產生 CloudFormation 範本。 | CloudFormation IaC 產生器可協助您從現有 AWS 資源產生 CloudFormation 範本。使用此功能為現有的 Aurora MySQL 相容全域資料庫及其相關聯的資源建立 CloudFormation 範本。此範本會設定子網路群組、安全群組、參數群組和其他設定。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html) | DBA | 
| 修改綠色環境的 CloudFormation 範本。 | 自訂 CloudFormation 範本以反映綠色環境的設定。這包括更新資源名稱和識別符，以確保綠色環境獨立於藍色叢集運作。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)如果您使用 `SnapshotIdentifier` 屬性還原資料庫叢集，請避免指定屬性，例如 `GlobalClusterIdentifier`、 `MasterUsername`或 `MasterUserPassword`。 | DBA | 
| 部署 CloudFormation 堆疊以建立綠色環境的資源。 | 在此步驟中，您會部署自訂 CloudFormation 範本，以建立綠色環境的資源。若要部署 CloudFormation 堆疊：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)CloudFormation 會啟動建立綠色環境資源的程序。此程序可能需要幾分鐘的時間才能完成。 | DBA | 
| 驗證 CloudFormation 堆疊和資源。 | 當 CloudFormation 堆疊部署完成時，您需要確認綠色環境已成功建立：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)驗證後，您的綠色環境已準備好進一步設定，包括從藍色環境複寫。 | DBA | 

### 設定 GTID 型複寫
<a name="configure-gtid-based-replication"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證藍色叢集上的 GTID 設定。 | GTIDs 提供高度可靠的方法來複寫藍色和綠色環境之間的資料。[GTID 型複寫](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/mysql-replication-gtid.html)透過為藍色環境中的每個交易指派唯一識別符，提供彈性、簡化的方法。相較於傳統的 binlog 複寫，此方法可確保環境之間的資料同步順暢、一致且易於管理。在設定複寫之前，您需要確保在藍色叢集上正確啟用 GTID 型複寫。此步驟保證藍色環境中的每個交易都是唯一的追蹤，並且可以在綠色環境中複寫。若要確認 GTID 已啟用：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)這些設定可針對藍色環境中所有未來的交易啟用 GTID 追蹤。確認這些設定後，您可以開始設定複寫。 | DBA | 
| 建立複寫使用者。 | 若要將資料從藍色環境複寫到綠色環境，您需要在藍色叢集上建立專用的複寫使用者。此使用者將負責管理複寫程序。若要設定複寫使用者：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)此使用者現在具有在兩個環境之間複寫資料的必要許可。 | DBA | 
| 在綠色叢集上設定 GTID 型複寫。 | 下一個步驟是為 GTID 型複寫設定綠色叢集。此設定可確保綠色環境會持續鏡像在藍色環境中發生的所有交易。若要設定綠色叢集：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html) | DBA | 
| 在綠色叢集上開始複寫。 | 您現在可以開始複寫程序。在綠色叢集上，執行 命令：<pre>START SLAVE;</pre>這可讓綠色環境開始同步資料，以及從藍色環境接收和套用交易。 | DBA | 
| 驗證複寫程序。 | 若要驗證綠色環境是否準確複寫藍色叢集的資料：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)如果所有指標都正確，GTID 型複寫功能會順暢運作，而且綠色環境會與藍色環境完全同步。 | DBA | 

### 從藍色叢集切換流量至綠色叢集
<a name="switch-traffic-from-blue-to-green-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 Route 53 加權路由政策。 | 驗證藍色和綠色環境之間的資料一致性後，您可以將流量從藍色叢集切換到綠色叢集。此轉換應該是順暢的，而且應該將停機時間降至最低，並確保應用程式資料庫的完整性。若要解決這些需求，您可以使用 Route 53 進行 DNS 路由，並使用 Lambda 自動化流量切換。此外，定義明確的轉返計劃可確保您可以在發生任何問題時還原至藍色叢集。第一步是在 Route 53 中設定加權路由。加權路由可讓您控制藍色和綠色叢集之間的流量分佈，並逐步將流量從一個環境轉移到另一個環境。若要設定加權路由：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)如需加權路由政策的詳細資訊，請參閱 [Route 53 文件](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy-weighted.html)。 | AWS DevOps | 
| 部署 Lambda 函數以監控複寫延遲。 | 為了確保綠色環境與藍色環境完全同步，請部署 Lambda 函數來監控叢集之間的複寫延遲。此函數可以檢查複寫狀態，特別是 **Seconds\$1Behind\$1Master** 指標，以判斷綠色叢集是否已準備好處理所有流量。以下是您可以使用的範例 Lambda 函數：<pre>import boto3<br /><br />def check_replication_lag(event, context):<br />    client = boto3.client('rds')<br />    response = client.describe_db_instances(DBInstanceIdentifier='green-cluster-instance')<br />    replication_status = response['DBInstances'][0]['ReadReplicaDBInstanceIdentifiers']<br />    if replication_status:<br />        lag = replication_status[0]['ReplicationLag']<br />        return lag<br />    return -1</pre>此函數會檢查複寫延遲並傳回 值。如果延遲為零，則綠色叢集會與藍色叢集完全同步。 | AWS DevOps | 
| 使用 Lambda 自動化 DNS 權重調整。 | 當複寫延遲達到零時，就可以將所有流量切換到綠色叢集。您可以使用另一個 Lambda 函數來自動化此轉換，該函數會調整 Route 53 中的 DNS 權重，以將 100% 的流量導向綠色叢集。以下是自動化流量切換的 Lambda 函數範例：<pre>import boto3<br /><br />def switch_traffic(event, context):<br />    route53 = boto3.client('route53')<br />    lag = check_replication_lag(event, context)<br />    if lag == 0:<br />        response = route53.change_resource_record_sets(<br />            HostedZoneId='YOUR_HOSTED_ZONE_ID',<br />            ChangeBatch={<br />                'Changes': [<br />                    {<br />                        'Action': 'UPSERT',<br />                        'ResourceRecordSet': {<br />                            'Name': 'db.example.com',<br />                            'Type': 'CNAME',<br />                            'SetIdentifier': 'GreenCluster',<br />                            'Weight': 100,<br />                            'TTL': 60,<br />                            'ResourceRecords': [{'Value': 'green-cluster-endpoint'}]<br />                        }<br />                    },<br />                    {<br />                        'Action': 'UPSERT',<br />                        'ResourceRecordSet': {<br />                            'Name': 'db.example.com',<br />                            'Type': 'CNAME',<br />                            'SetIdentifier': 'BlueCluster',<br />                            'Weight': 0,<br />                            'TTL': 60,<br />                            'ResourceRecords': [{'Value': 'blue-cluster-endpoint'}]<br />                        }<br />                    }<br />                ]<br />            }<br />        )<br />        return response</pre>此函數會檢查複寫延遲，並在延遲為零時更新 Route 53 DNS 權重，以將流量完全切換到綠色叢集。** **在切換過程中，如果藍色叢集遇到大量寫入流量，請考慮在切換期間暫時暫停寫入操作。這可確保複寫趕上進度，並防止藍色和綠色叢集之間的資料不一致。 | AWS DevOps | 
| 驗證流量開關。 | Lambda 函數調整 DNS 權重後，您應該驗證所有流量是否導向綠色叢集，以及切換是否成功。若要驗證：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)如果一切如預期執行，則流量切換會完成。 | AWS DevOps | 
| 如果您遇到任何問題，請復原變更。 | 如果流量切換之後發生任何問題，則擁有復原計劃至關重要。如有必要，以下說明如何快速還原至藍色叢集：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)透過實作此轉返計劃，您可以確保在發生任何非預期問題時對使用者造成的干擾降到最低。 | AWS DevOps | 

### 驗證並停止 GTID 型複寫
<a name="validate-and-stop-gtid-based-replication"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在綠色叢集上停止 GTID 型複寫。 | 將流量從藍色環境切換到綠色環境之後，您應該驗證轉換的成功，並確保綠色叢集如預期般運作。此外，藍色和綠色叢集之間的 GTID 型複寫必須停止，因為綠色環境現在可做為主要資料庫。完成這些任務可確保您的環境安全、簡化並針對持續操作進行最佳化。若要停止複寫：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)當您停止複寫時，綠色叢集會變得完全獨立，並做為工作負載的主要資料庫環境運作。 | DBA | 
| 清除資源。 | 清除從藍色遷移到綠色叢集期間建立的任何暫時或未使用的資源，可確保您的環境保持最佳化、安全且符合成本效益。清除包括調整安全設定、進行最終備份，以及停用不必要的資源。若要清除資源：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/p-automate-blue-green-deployments-aurora-global-databases-iac.html)清理資源有助於維護安全且簡化的環境、降低成本，並確保僅保留必要的基礎設施。 | AWS DevOps | 

## 相關資源
<a name="p-automate-blue-green-deployments-aurora-global-databases-iac-resources"></a>

CloudFormation:
+ [CloudFormation 使用者指南](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)
+ [CloudFormation 最佳實務](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html)
+ [使用 IaC 產生器從現有資源產生範本](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/generate-IaC.html)
+ 將[整個應用程式匯入 CloudFormation](https://aws.amazon.com/blogs/devops/import-entire-applications-into-aws-cloudformation/)(AWS 部落格文章）

Amazon Aurora：
+ [Amazon Aurora 使用者指南](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Welcome.html)
+ [管理 Amazon Aurora 資料庫叢集](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_Aurora.html)

藍/綠部署策略：
+ [Amazon Aurora 藍/綠部署概觀](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/blue-green-deployments-overview.html)

以 GTID 為基礎的複寫：
+ [使用 GTID 式複寫](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/mysql-replication-gtid.html) (Amazon RDS 文件）

AWS Lambda:
+ [AWS Lambda 開發人員指南](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)
+ [使用 AWS Lambda 函數的最佳實務](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html)

Amazon Route 53：
+ 《[Amazon Route 53 開發人員指南](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/Welcome.html)》
+ [加權路由](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy-weighted.html)

MySQL 用戶端工具：
+ [PyMYSQL](https://github.com/PyMySQL/PyMySQL)

# 自動化跨 的 Amazon RDS 執行個體複寫 AWS 帳戶
<a name="automate-the-replication-of-amazon-rds-instances-across-aws-accounts"></a>

*Parag Nagwekar 和 Arun Chandapillai，Amazon Web Services*

## 總結
<a name="automate-the-replication-of-amazon-rds-instances-across-aws-accounts-summary"></a>

此模式說明如何 AWS 帳戶 使用 和 自動化複寫、追蹤和復原不同 Amazon Relational Database Service (Amazon RDS) 資料庫執行個體的程序 AWS Step Functions AWS Lambda。您可以使用此自動化來執行 RDS 資料庫執行個體的大規模複寫，而不會受到任何效能影響或營運額外負荷，無論您的組織大小為何。您也可以使用此模式來協助您的組織遵守強制性資料控管策略或合規要求，以要求在不同 和 之間複寫 AWS 帳戶 和備援您的資料 AWS 區域。跨帳戶大規模複寫 Amazon RDS 資料是一種低效率且容易出錯的手動程序，成本高昂且耗時，但此模式中的自動化可協助您安全、有效且有效率地實現跨帳戶複寫。

## 先決條件和限制
<a name="automate-the-replication-of-amazon-rds-instances-across-aws-accounts-prereqs"></a>

**先決條件**
+ 兩個 AWS 帳戶
+ 在來源中啟動和執行的 RDS 資料庫執行個體 AWS 帳戶
+ 目的地中 RDS 資料庫執行個體的子網路群組 AWS 帳戶
+ 在來源中建立 AWS 帳戶 並與目的地帳戶共用的 AWS Key Management Service (AWS KMS) 金鑰 （如需政策詳細資訊的詳細資訊，請參閱此模式的其他資訊[其他資訊](#automate-the-replication-of-amazon-rds-instances-across-aws-accounts-additional)區段。)
+ 目的地 AWS KMS key 中的 AWS 帳戶 ，用於加密目的地帳戶中的資料庫

**限制**
+ 有些 AWS 服務 不適用於所有 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

**產品版本**
+ Python 3.9 （使用 AWS Lambda)
+ PostgreSQL 11.3、13.x 和 14.x

## Architecture
<a name="automate-the-replication-of-amazon-rds-instances-across-aws-accounts-architecture"></a>

**技術堆疊**
+ Amazon Relational Database Service (Amazon RDS)
+ Amazon Simple Notification Service (Amazon SNS)
+ AWS Key Management Service (AWS KMS)
+ AWS Lambda
+ AWS Secrets Manager
+ AWS Step Functions

**目標架構**

下圖顯示使用 Step Functions 將 RDS 資料庫執行個體的排程隨需複寫從來源帳戶 （帳戶 A) 協調到目的地帳戶 （帳戶 B) 的架構。

![\[使用 Step Functions 在來源和目的地帳戶之間複寫 Amazon RDS 資料庫執行個體。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6310ad9b-1b1a-4a67-b684-ef605fef3e87/images/001550bb-cf6b-493d-9de9-0229a43753a1.png)


在來源帳戶 （圖表中的帳戶 A) 中，Step Functions 狀態機器會執行下列動作：

1. 從帳戶 A 中的 RDS 資料庫執行個體建立快照。

1. 使用 AWS KMS key 來自帳戶 A 的 複製和加密快照。為了確保傳輸中的加密，無論資料庫執行個體是否已加密，快照都會加密。

1. 透過讓帳戶 B 存取快照，與帳戶 B 共用資料庫快照。

1. 將通知推送至 SNS 主題，然後 SNS 主題會叫用帳戶 B 中的 Lambda 函數。

在目的地帳戶 （圖表中的帳戶 B) 中，Lambda 函數會執行 Step Functions 狀態機器來協調下列項目：

1. 將共用快照從帳戶 A 複製到帳戶 B，同時使用 AWS KMS key 帳戶 A 的 先解密資料，然後使用帳戶 B AWS KMS key 中的 加密資料。

1. 從 Secrets Manager 讀取秘密，以擷取目前資料庫執行個體的名稱。

1. 使用 AWS KMS key Amazon RDS 的新名稱和預設值，從快照還原資料庫執行個體。

1. 讀取新資料庫的端點，並使用新資料庫端點更新 Secrets Manager 中的秘密，然後標記先前的資料庫執行個體，以便稍後刪除。

1. 保留資料庫的最新 N 個執行個體，並刪除所有其他執行個體。

## 工具
<a name="automate-the-replication-of-amazon-rds-instances-across-aws-accounts-tools"></a>

**AWS 服務**
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 中設定、操作和擴展關聯式資料庫 AWS 雲端。
+ [Amazon Simple Notification Service (Amazon SNS)](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) 可協助您協調和管理發佈者和用戶端之間的訊息交換，包括 Web 伺服器和電子郵件地址。
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可協助您設定 AWS 資源、快速且一致地佈建資源，以及在整個 AWS 帳戶 和 生命週期中管理資源 AWS 區域。
+ [AWS Key Management Service (AWS KMS)](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) 可協助您建立和控制密碼編譯金鑰，以協助保護您的資料。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一項運算服務，可協助您執行程式碼，無需佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需按使用的運算時間付費。
+ [適用於 Python (Boto3) 的 AWS SDK](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html) 是一種軟體開發套件，可協助您整合 Python 應用程式、程式庫或指令碼 AWS 服務。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您將程式碼中的硬式編碼憑證 (包括密碼) 取代為 Secrets Manager 的 API 呼叫，以便透過程式設計方法來擷取機密。
+ [AWS Step Functions](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html) 是一種無伺服器協同運作服務，可協助您結合 Lambda 函數和其他 AWS 服務 來建置業務關鍵應用程式。

**程式碼儲存庫**

此模式的程式碼可在 GitHub [Crossaccount RDS 複寫](https://github.com/aws-samples/aws-rds-crossaccount-replication)儲存庫中使用。

## 史詩
<a name="automate-the-replication-of-amazon-rds-instances-across-aws-accounts-epics"></a>

### AWS 帳戶 只需按一下，即可自動化跨 的 RDS 資料庫執行個體複寫
<a name="automate-the-replication-of-rds-db-instances-across-aws-accounts-with-a-single-click"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在來源帳戶中部署 CloudFormation 堆疊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-replication-of-amazon-rds-instances-across-aws-accounts.html) | 雲端管理員、雲端架構師 | 
| 在目的地帳戶中部署 CloudFormation 堆疊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-replication-of-amazon-rds-instances-across-aws-accounts.html) | 雲端架構師、DevOps 工程師、雲端管理員 | 
| 驗證在目的地帳戶中建立 RDS 資料庫執行個體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-replication-of-amazon-rds-instances-across-aws-accounts.html) | 雲端管理員、雲端架構師、DevOps 工程師 | 
| 訂閱 Lambda 函數至 SNS 主題。 | 您必須執行下列 AWS Command Line Interface (AWS CLI) 命令，將目的地帳戶 （帳戶 B) 中的 Lambda 函數訂閱至來源帳戶 （帳戶 A) 中的 SNS 主題。在帳戶 A 中，執行下列命令：<pre>aws sns add-permission \<br />--label lambda-access --aws-account-id <DestinationAccount> \<br />--topic-arn <Arn of SNSTopic > \<br />--action-name Subscribe ListSubscriptionsByTopic </pre>在帳戶 B 中，執行下列命令：<pre>aws lambda add-permission \<br />--function-name <Name of InvokeStepFunction> \<br />--source-arn <Arn of SNSTopic > \<br />--statement-id function-with-sns \<br />--action lambda:InvokeFunction \<br />--principal sns.amazonaws.com</pre>在帳戶 B 中，執行下列命令：<pre>aws sns subscribe \<br />--protocol "lambda" \<br />--topic-arn <Arn of SNSTopic> \<br />--notification-endpoint <Arn of InvokeStepFunction></pre> | 雲端管理員、雲端架構師、DBA | 
| 從來源帳戶同步 RDS 資料庫執行個體與目的地帳戶。 | 透過啟動來源帳戶中的 Step Functions 狀態機器來啟動隨需資料庫複寫。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-replication-of-amazon-rds-instances-across-aws-accounts.html)排程器已就緒，可協助您按排程自動執行複寫，但排程器預設為關閉。您可以在目的地帳戶中 CloudFormation 堆疊的 資源索引標籤中找到排程器的 Amazon CloudWatch 規則名稱。****如需如何修改 CloudWatch Events 規則的說明，請參閱 [ CloudWatch 文件中的刪除或停用 CloudWatch Events 規則](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/Delete-or-Disable-Rule.html)。 CloudWatch  | 雲端架構師、DevOps 工程師、雲端管理員 | 
| 視需要將資料庫復原至任何先前的複本。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-the-replication-of-amazon-rds-instances-across-aws-accounts.html) | 雲端管理員、DBA、DevOps 工程師 | 

## 相關資源
<a name="automate-the-replication-of-amazon-rds-instances-across-aws-accounts-resources"></a>
+ [跨區域僅供讀取複本 ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RDS_Fea_Regions_DB-eng.Feature.CrossRegionReadReplicas.html)(Amazon RDS 文件）
+ [藍/綠部署 ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RDS_Fea_Regions_DB-eng.Feature.BlueGreenDeployments.html)(Amazon RDS 文件）

## 其他資訊
<a name="automate-the-replication-of-amazon-rds-instances-across-aws-accounts-additional"></a>

您可以使用下列範例政策跨 共用您的 AWS KMS key AWS 帳戶。

```
{
    "Version": "2012-10-17",		 	 	 
    "Id": "cross-account-rds-kms-key",
    "Statement": [
        {
            "Sid": "Enable user permissions",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<SourceAccount>:root"
            },
            "Action": "kms:*",
            "Resource": "*"
        },
        {
            "Sid": "Allow administration of the key",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<DestinationAccount>:root"
            },
            "Action": [
                "kms:Create*",
                "kms:Describe*",
                "kms:Enable*",
                "kms:List*",
                "kms:Put*",
                "kms:Update*",
                "kms:Revoke*",
                "kms:Disable*",
                "kms:Get*",
                "kms:Delete*",
                "kms:ScheduleKeyDeletion",
                "kms:CancelKeyDeletion"
            ],
            "Resource": "*"
        },
        {
            "Sid": "Allow use of the key",
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::<DestinationAccount>:root",
                    "arn:aws:iam::<SourceAccount>:root"
                ]
            },
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKey*",
                "kms:DescribeKey",
                "kms:CreateGrant"
            ],
            "Resource": "*"
        }
    ]
}
```

# 使用 AWS Lambda 和 任務排程器，在 Amazon EC2 上執行的 SQL Server Express 版本中自動化資料庫任務
<a name="automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2"></a>

*Subhani Shaik，Amazon Web Services*

## 總結
<a name="automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2-summary"></a>

此模式示範如何在 SQL Server Express 版本中排程和管理資料庫任務，這是 SQL Server 的免費版本。不過，SQL Server Express 版本缺少通常處理自動化資料庫操作的 SQL Server Agent 服務。此模式說明如何使用任務排程器和 Lambda 做為在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上執行的 SQL Server Express 版本中自動化資料庫任務的替代方案。

[任務排程器](https://learn.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page)是內建的 Windows 系統公用程式，可促進例行任務的自動執行。它提供一種機制來排程和管理自動化操作，無需在週期性程序中手動介入。 [AWS Lambda](https://aws.amazon.com/lambda/) 是一種無伺服器運算服務，可自動執行程式碼以回應事件，而無需您管理基礎基礎設施。

## 先決條件和限制
<a name="automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ 使用 Amazon Virtual Private Cloud (Amazon VPC) 建立的虛擬私有雲端 (VPC)
+ 具有 Windows Server 的 Amazon EC2 執行個體
+ 使用 Windows Server 連接至 Amazon EC2 執行個體的 Amazon Elastic Block Store (Amazon EBS) 磁碟區
+ [SQL Server Express Edition](https://www.microsoft.com/en-us/download/details.aspx?id=101064) 二進位檔

**限制**
+ 如需 SQL Server Express Edition 功能限制的相關資訊，請參閱 [Microsoft 網站](https://learn.microsoft.com/en-us/sql/sql-server/editions-and-components-of-sql-server-2019?view=sql-server-ver16)。
+ 有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[AWS 依區域的服務](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)，然後選擇服務的連結。

**產品版本**
+ SQL Server 2016 或更新版本搭配 SQL Server Express 版本

## Architecture
<a name="automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2-architecture"></a>

下圖顯示已安裝 SQL Server Express 版本的 Amazon EC2 執行個體。執行個體可透過遠端桌面通訊協定 (RDP) 用戶端或從 存取 AWS Systems Manager Session Manager。 AWS Key Management Service (AWS KMS) 會處理 Amazon EBS 磁碟區的資料加密，以確保data-at-rest的安全性。基礎設施也包含 AWS Identity and Access Management (IAM)，可提供存取控制和管理執行 Lambda 函數的許可。Amazon Simple Storage Service (Amazon S3) 存放 Lambda 函數。

![\[在私有子網路上安裝 SQL Server Express 版本時執行的 Amazon EC2 執行個體。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/3af2174d-bf49-4e43-86f7-34759e5eea84/images/3a37dcb8-10af-42f2-8ff1-fab4f87eb646.png)


## 工具
<a name="automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2-tools"></a>

**AWS 服務**
+ [Amazon Elastic Block Store (Amazon EBS)](https://docs.aws.amazon.com/ebs/latest/userguide/what-is-ebs.html) 提供區塊層級儲存體磁碟區，可搭配使用 Amazon EC2 執行個體。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Key Management Service (AWS KMS)](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) 可協助您建立和控制密碼編譯金鑰，以協助保護您的資料。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一項運算服務，可協助您執行程式碼，無需佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需按使用的運算時間付費。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [AWS Systems Manager Session Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html) 是全受管 AWS Systems Manager 工具。使用 Session Manager，您可以管理 Amazon EC2 執行個體、邊緣裝置、內部部署伺服器和虛擬機器 VMs)。
+ [Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) 可協助您在已定義的虛擬網路中啟動 AWS 資源。此虛擬網路與您在自己的資料中心中操作的傳統網路相似，且具備使用 AWS可擴展基礎設施的優勢。

**其他工具**
+ [Microsoft SQL Server Management Studio (SSMS)](https://learn.microsoft.com/en-us/ssms/download-sql-server-management-studio-ssms) 是一種用於管理 SQL Server 的工具，包括存取、設定和管理 SQL Server 元件。
+ [Python](https://www.python.org/) 是一種一般用途的電腦程式設計語言。您可以使用它來建置應用程式、自動化任務，以及在 上開發服務[AWS 雲端](https://aws.amazon.com/developer/language/python/)。
+ [任務排程器](https://learn.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page)是一種 Microsoft 工具，可用來自動排程電腦上的例行任務。

## 最佳實務
<a name="automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2-best-practices"></a>
+ [Amazon EC2 的最佳實務](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-best-practices.html)
+ [在 Amazon EC2 上部署 Microsoft SQL Server 的最佳實務](https://docs.aws.amazon.com/prescriptive-guidance/latest/sql-server-ec2-best-practices/welcome.html)
+ [使用 AWS Lambda 函數的最佳實務](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html)
+ [IAM 中的安全最佳實務](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)

## 史詩
<a name="automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2-epics"></a>

### 建立 Amazon EC2 執行個體並安裝 SQL Server Express 版本
<a name="create-an-amazon-ec2-instance-and-install-sql-server-express-edition"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 部署 Amazon EC2 執行個體。 | 若要建立 Amazon EC2 執行個體，請開啟位於 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/)：// 的 Amazon EC2 主控台，然後從適用於 Windows Server 的執行個體清單中選取 [Amazon Machine Image (AMI)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html)。如需詳細資訊，請參閱 AWS 文件中的[啟動 Amazon EC2 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/LaunchingAndUsingInstances.html)。 | DBA、AWS DevOps | 
| 安裝 SQL Server Express 版本。 | 若要安裝 SQL Server Express 版本，請完成下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.html) | DBA、AWS DevOps | 

### 建立自動化資料庫維護任務
<a name="create-automated-database-maintenance-tasks"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別例行任務。 | 識別您要自動化的例行任務。例如，下列任務符合自動化的資格：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.html) | DBA | 
| 準備 SQL 指令碼。 | 若要準備 SQL 指令碼，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.html) | DBA | 
| 設定存取許可。 | 若要設定存取許可，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.html) | DBA | 

### 使用任務排程器自動化任務
<a name="automate-tasks-with-task-scheduler"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立批次檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.html)<pre>sqlcmd -S servername -U username -P password -i <T-SQL query path.sql></pre>[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.html)<pre><br />@echo off<br />sqlcmd -S [ServerName] -d [DatabaseName] -U username -P password -i "PathToSQLScript\Script.sql" -o "PathToOutput\Output.txt"</pre> | AWS DevOps、DBA | 
| 在任務排程器中建立任務。 | 若要在任務排程器中建立任務，請使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.html)若要手動執行任務，請在新建立的任務上按一下滑鼠右鍵，然後選取**執行**。 | DBA | 
| 檢視任務狀態。 | 若要在任務排程器中檢視任務的狀態，請使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.html) | DBA、AWS DevOps | 

### 使用 自動化任務 AWS Lambda
<a name="automate-tasks-with-lamlong"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 實作解決方案。 | 若要實作此模式的解決方案，請使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.html) | AWS DevOps，DevOps 工程師 | 

## 疑難排解
<a name="automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| Lambda 問題 | 如需使用 時可能遇到的錯誤和問題的協助 AWS Lambda，請參閱 AWS 文件[中的 Lambda 中的故障診斷問題](https://docs.aws.amazon.com/lambda/latest/dg/lambda-troubleshooting.html)。 | 

## 相關資源
<a name="automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2-resources"></a>
+ [Amazon EC2 執行個體類型](https://aws.amazon.com/ec2/instance-types/)
+ [AWS Lambda 文件](https://docs.aws.amazon.com/lambda/latest/dg/with-eventbridge-scheduler.html)
+ [AWS Lambda 定價](https://aws.amazon.com/lambda/pricing/)
+ [開發人員的任務排程器](https://learn.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page) (Microsoft 網站）

# 使用 DR Orchestrator Framework 自動化跨區域容錯移轉和容錯回復
<a name="automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework"></a>

*Jitendra Kumar、Pavithra Balasubramanian 和 Oliver Francis，Amazon Web Services*

## 總結
<a name="automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework-summary"></a>

此模式說明如何使用 [DR Orchestrator Framework](https://docs.aws.amazon.com/prescriptive-guidance/latest/automate-dr-solution-relational-database/dr-orchestrator-framework-overview.html) 協調和自動化手動、容易出錯的步驟，以跨 Amazon Web Services (AWS) 區域執行災難復原。模式涵蓋下列資料庫：
+ MySQL 的 Amazon Relational Database Service (Amazon RDS)、PostgreSQL 的 Amazon RDS 或 Amazon RDS for MariaDB
+ Amazon Aurora MySQL 相容版本或 Amazon Aurora PostgreSQL 相容版本 （使用集中式檔案）
+ Amazon ElastiCache (Redis OSS)

若要示範 DR Orchestrator Framework 的功能，您可以建立兩個資料庫執行個體或叢集。主要 位於 AWS 區域 `us-east-1`，次要 位於 `us-west-2`。若要建立這些資源，您可以使用 [aws-cross-region-dr-databases](https://github.com/aws-samples/aws-cross-region-dr-databases) GitHub 儲存庫的 `App-Stack` 資料夾中的 AWS CloudFormation 範本。

## 先決條件和限制
<a name="automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework-prereqs"></a>

**一般先決條件**
+ 部署在主要和次要 DR Orchestrator Framework AWS 區域
+ 兩個 [Amazon Simple Storage Service](https://aws.amazon.com/s3/) 儲存貯體
+ 具有兩個子網路和一個 AWS 安全群組的[虛擬私有雲端 (VPC)](https://aws.amazon.com/vpc/) 

**引擎特定的先決條件**
+ **Amazon Aurora** – 至少必須有兩個可用的 Aurora 全域資料庫 AWS 區域。您可以使用 `us-east-1`做為主要區域，並使用 `us-west-2`做為次要區域。
+ **Amazon ElastiCache (Redis OSS)** – ElastiCache 全域資料存放區必須提供兩種。 AWS 區域您可以`use us-east-1`做為主要區域，並使用 `us-west-2`做為次要區域。

**Amazon RDS 限制**
+ 在進行容錯移轉或容錯回復之前，DR Orchestrator Framework 不會檢查複寫延遲。必須手動檢查複寫延遲。
+ 此解決方案已使用具有一個僅供讀取複本的主要資料庫執行個體進行測試。如果您想要使用多個僅供讀取複本，請在生產環境中實作解決方案之前，先徹底測試解決方案。

**Aurora 限制**
+ 功能可用性和支援會因每個資料庫引擎的特定版本和不同版本而有所不同 AWS 區域。如需跨區域複寫功能和區域可用性的詳細資訊，請參閱[跨區域僅供讀取複本](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RDS_Fea_Regions_DB-eng.Feature.CrossRegionReadReplicas.html)。
+ Aurora 全域資料庫具有支援 Aurora 資料庫執行個體類別的特定組態需求，以及最大數量 AWS 區域。如需詳細資訊，請參閱 [Amazon Aurora 全域資料庫的組態需求](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-getting-started.html#aurora-global-database.configuration.requirements)。
+ 此解決方案已使用具有一個僅供讀取複本的主要資料庫執行個體進行測試。如果您想要使用多個僅供讀取複本，請在生產環境中實作解決方案之前，先徹底測試解決方案。

**ElastiCache 限制**
+ 如需全域資料存放區和 ElastiCache 組態需求的區域可用性資訊，請參閱 ElastiCache 文件中的[先決條件和限制](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Redis-Global-Datastores-Getting-Started.html)。

**Amazon RDS p****roduct 版本**

Amazon RDS 支援下列引擎版本：
+ **MySQL** – Amazon RDS 支援執行下列 [MySQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MySQL.html) 版本的資料庫執行個體：MySQL 8.0 和 MySQL 5.7
+ **PostgreSQL** – 如需有關 Amazon RDS for PostgreSQL 支援版本的資訊，請參閱[可用的 PostgreSQL 資料庫版本](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts.General.DBVersions)。
+ **MariaDB** – Amazon RDS 支援執行下列 [MariaDB](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MariaDB.html) 版本的資料庫執行個體：
  + MariaDB 10.11
  + MariaDB 10.6
  + MariaDB 10.5

**Aurora 產品版本**
+ Amazon Aurora 全域資料庫轉換需要 Aurora MySQL 相容於 MySQL 5.7 相容性，2.09.1 版及更新版本

  如需詳細資訊，請參閱 [Amazon Aurora 全域資料庫的限制](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html#aurora-global-database.limitations)。

**ElastiCache (Redis OSS) 產品版本**

Amazon ElastiCache (Redis OSS) 支援下列 Redis 版本：
+ Redis 7.1 (增強版)
+ Redis 7.0 (增強版)
+ Redis 6.2 (增強版)
+ Redis 6.0 (增強版)
+ Redis 5.0.6 (增強版)

如需詳細資訊，請參閱[支援的 ElastiCache (Redis OSS) 版本](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Redis-Global-Datastores-Getting-Started.html)。

## Architecture
<a name="automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework-architecture"></a>

**Amazon RDS** **架構**

Amazon RDS 架構包含下列資源：
+ 在主要區域 (`us-east-1`) 中建立的主要 Amazon RDS 資料庫執行個體，具有用戶端的讀取/寫入存取權
+ 在次要區域 (`us-west-2`) 中建立的 Amazon RDS 僅供讀取複本，具有用戶端的唯讀存取權
+ 部署在主要和次要區域的 DR Orchestrator Framework

![\[單一 AWS 帳戶中雙區域 RDS 架構的圖表。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/8d39561f-924e-4b3e-8175-c5c3cab163bd/images/ad217033-600c-40da-929c-b9f9aecb4c2c.png)


上圖顯示以下項目：

1. 主要執行個體與次要執行個體之間的非同步複寫

1. 主要區域中用戶端的讀取/寫入存取權

1. 次要區域中用戶端的唯讀存取權

**Aurora 架構**

Amazon Aurora 架構包含下列資源：
+ 在具有作用中寫入器端點的主要區域 (`us-east-1`) 中建立的主要 Aurora 資料庫叢集
+ 在次要區域 (`us-west-2`) 中建立且具有非作用中寫入器端點的 Aurora 資料庫叢集
+ 部署在主要和次要區域的 DR Orchestrator Framework

![\[單一 AWS 帳戶中雙區域 Aurora 部署的圖表。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/8d39561f-924e-4b3e-8175-c5c3cab163bd/images/524ec002-5aa7-47b2-8c8d-6d1a3b535e9e.png)


上圖顯示以下項目：

1. 主要叢集與次要叢集之間的非同步複寫

1. 具有主動寫入器端點的主要資料庫叢集

1. 具有非作用中寫入器端點的次要資料庫叢集

**ElastiCache (Redis OSS) 架構**

Amazon ElastiCache (Redis OSS) 架構包含下列資源：
+ 使用兩個叢集建立的 ElastiCache (Redis OSS) 全域資料存放區：

  1. 主要區域中的主要叢集 (`us-east-1`)

  1. 次要區域中的次要叢集 (`us-west-2`)
+ 兩個叢集之間具有 TLS 1.2 加密的 Amazon 跨區域連結
+ 部署在主要和次要區域的 DR Orchestrator Framework

![\[具有 Amazon 跨區域連結的雙區域 ElastiCache 部署圖表。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/8d39561f-924e-4b3e-8175-c5c3cab163bd/images/cf6620a0-dd42-4042-8dc2-012bf514ffc0.png)


**自動化和擴展**

DR Orchestrator Framework 可擴展，並支援平行容錯移轉或容錯回復多個 AWS 資料庫。

您可以使用下列承載程式碼容錯移轉您帳戶中的多個 AWS 資料庫。在此範例中，三個 AWS 資料庫 （兩個全域資料庫，例如 Aurora MySQL 相容或 Aurora PostgreSQL 相容，以及一個 Amazon RDS for MySQL 執行個體） 容錯移轉至 DR 區域：

```
{
  "StatePayload": [
    {
      "layer": 1,
      "resources": [
        {
          "resourceType": "PlannedFailoverAurora",
          "resourceName": "Switchover (planned failover) of Amazon Aurora global databases (MySQL)",
          "parameters": {
            "GlobalClusterIdentifier": "!Import dr-globaldb-cluster-mysql-global-identifier",
            "DBClusterIdentifier": "!Import dr-globaldb-cluster-mysql-cluster-identifier" 
          }
        },
        {
          "resourceType": "PlannedFailoverAurora",
          "resourceName": "Switchover (planned failover) of Amazon Aurora global databases (PostgreSQL)",
          "parameters": {
            "GlobalClusterIdentifier": "!Import dr-globaldb-cluster-postgres-global-identifier",
            "DBClusterIdentifier": "!Import dr-globaldb-cluster-postgres-cluster-identifier" 
          }
        },
        {
          "resourceType": "PromoteRDSReadReplica",
          "resourceName": "Promote RDS for MySQL Read Replica",
          "parameters": {
            "RDSInstanceIdentifier": "!Import rds-mysql-instance-identifier",
            "TargetClusterIdentifier": "!Import rds-mysql-instance-global-arn"
          }
        }         
      ]
    }
  ]
}
```

## 工具
<a name="automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework-tools"></a>

**AWS 服務**
+ [Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html) 是一種全受管關聯式資料庫引擎，專為雲端而建置，並與 MySQL 和 PostgreSQL 相容。
+ [Amazon ElastiCache](https://docs.aws.amazon.com/elasticache/) 可協助您在 中設定、管理和擴展分散式記憶體內快取環境 AWS 雲端。此模式使用 Amazon ElastiCache (Redis OSS)。
+ [AWS Lambda](https://aws.amazon.com/lambda/) 是一項運算服務，可協助您執行程式碼，無需佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需按使用的運算時間付費。在此模式中，Lambda 函數由 AWS Step Functions 用來執行步驟。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 中設定、操作和擴展關聯式資料庫 AWS 雲端。此模式支援 Amazon RDS for MySQL、Amazon RDS for PostgreSQL 和 Amazon RDS for MariaDB。
+ [適用於 Python (Boto3) 的 AWS SDK](https://aws.amazon.com/sdk-for-python/) 可協助您整合 Python 應用程式、程式庫或指令碼 AWS 服務。在此模式中，Boto3 APIs用於與資料庫執行個體或全域資料庫通訊。
+ [AWS Step Functions](https://aws.amazon.com/step-functions/) 是一種無伺服器協同運作服務，可協助您結合 AWS Lambda 函數和其他 AWS 服務 來建置業務關鍵應用程式。在此模式中，Step Functions 狀態機器用於協調和執行資料庫執行個體或全域資料庫的跨區域容錯移轉和容錯回復。

**程式碼儲存庫**

此模式的程式碼可在 GitHub 上的 [aws-cross-region-dr-databases](https://github.com/aws-samples/aws-cross-region-dr-databases/tree/main/App-Stack) 儲存庫中使用。

## 史詩
<a name="automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework-epics"></a>

### 安裝 DR Orchestrator Framework
<a name="install-dr-orchestrator-framework"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製 GitHub 儲存庫。 | 若要複製儲存庫，請執行下列命令：<pre>git clone https://github.com/aws-samples/aws-cross-region-dr-databases.git</pre> | AWS DevOps、AWS 管理員 | 
| 在 .zip 檔案封存中封裝 Lambda 函數程式碼。 | 建立 Lambda 函數的封存檔案，以包含 DR Orchestrator Framework 相依性：<pre>cd <YOUR-LOCAL-GIT-FOLDER>/DR-Orchestration-artifacts<br /><br />bash scripts/deploy-orchestrator-sh.sh</pre> | AWS 管理員 | 
| 建立 S3 儲存貯體。 | 需要 S3 儲存貯體來存放 DR Orchestrator Framework 以及您的最新組態。建立兩個 S3 儲存貯體，一個位於主要區域 (`us-east-1`)，另一個位於次要區域 (`us-west-2`)：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework.html)`xxxxxx` 以隨機值取代 ，讓儲存貯體名稱是唯一的。 | AWS 管理員 | 
| 建立子網路和安全群組。 | 在主要區域 (`us-east-1`) 和次要區域 (`us-west-2`) 中，為您的 VPC 中的 Lambda 函數部署建立兩個子網路和一個安全群組：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework.html) | AWS 管理員 | 
| 更新 DR Orchestrator 參數檔案。 | 在 `<YOUR-LOCAL-GIT-FOLDER>/DR-Orchestration-artifacts/cloudformation`資料夾中，更新下列 DR Orchestrator 參數檔案：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework.html)使用下列參數值，`y`將 `x`和 取代為您的資源名稱：<pre>[<br />    {<br />         "ParameterKey": "TemplateStoreS3BucketName",<br />         "ParameterValue": "dr-orchestrator-xxxxxx-us-east-1"<br />    },<br />    {<br />        "ParameterKey": "TemplateVPCId",<br />        "ParameterValue": "vpc-xxxxxx"<br />    },<br />    {<br />        "ParameterKey": "TemplateLambdaSubnetID1",<br />        "ParameterValue": "subnet-xxxxxx"<br />    },<br />    {<br />        "ParameterKey": "TemplateLambdaSubnetID2",<br />        "ParameterValue": "subnet-yyyyyy"<br />    },<br />    {<br />        "ParameterKey": "TemplateLambdaSecurityGroupID",<br />        "ParameterValue": "sg-xxxxxxxxxx"<br />    }<br /> ]</pre> | AWS 管理員 | 
| 將 DR Orchestrator Framework 程式碼上傳至 S3 儲存貯體。 | S3 儲存貯體中的程式碼會比本機目錄中的程式碼更安全。將`DR-Orchestration-artifacts`目錄，包括所有檔案和子資料夾，上傳至 S3 儲存貯體。若要上傳程式碼，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework.html) | AWS 管理員 | 
| 在主要區域中部署 DR Orchestrator Framework。 | 若要在主要區域 (`us-east-1`) 部署 DR Orchestrator Framework，請執行下列命令：<pre>cd <YOUR-LOCAL-GIT-FOLDER>/DR-Orchestration-artifacts/cloudformation<br /><br />aws cloudformation deploy \<br />--region us-east-1 \<br />--stack-name dr-orchestrator \<br />--template-file Orchestrator-Deployer.yaml \<br />--parameter-overrides file://Orchestrator-Deployer-parameters-us-east-1.json \<br />--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \<br />--disable-rollback</pre> | AWS 管理員 | 
| 在次要區域中部署 DR Orchestrator Framework。 | 在次要區域 (`us-west-2`) 中，執行下列命令：<pre>cd <YOUR-LOCAL-GIT-FOLDER>/DR-Orchestration-artifacts/cloudformation<br /><br />aws cloudformation deploy \<br />--region us-west-2 \<br />--stack-name dr-orchestrator \<br />--template-file Orchestrator-Deployer.yaml \<br />--parameter-overrides file://Orchestrator-Deployer-parameters-us-west-2.json \<br />--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \<br />--disable-rollback</pre> | AWS 管理員 | 
| 驗證部署。 | 如果 CloudFormation 命令成功執行，則會傳回下列輸出：<pre>Successfully created/updated stack - dr-orchestrator</pre>或者，您可以導覽至 CloudFormation 主控台並驗證`dr-orchestrator`堆疊的狀態。 | AWS 管理員 | 

### 建立資料庫執行個體或叢集
<a name="create-the-database-instances-or-clusters"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立資料庫子網路和安全群組。 | 在您的 VPC 中，為主要 (`us-east-1`) 和次要 (`us-west-2`) 區域中的資料庫執行個體或全域資料庫建立兩個子網路和一個安全群組：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework.html) | AWS 管理員 | 
| 更新主要資料庫執行個體或叢集的參數檔案。 | 在 `<YOUR LOCAL GIT FOLDER>/App-Stack`資料夾中，更新主要區域的參數檔案。**Amazon RDS**在 `RDS-MySQL-parameter-us-east-1.json` 檔案中，`DBSecurityGroup`使用您建立的資源名稱更新 `SubnetIds`和 ：<pre>{<br />  "Parameters": {<br />    "SubnetIds": "subnet-xxxxxx,subnet-xxxxxx",<br />    "DBSecurityGroup": "sg-xxxxxxxxxx",<br />    "MySqlGlobalIdentifier":"rds-mysql-instance",<br />    "InitialDatabaseName": "mysqldb",<br />    "DBPortNumber": "3789",<br />    "PrimaryRegion": "us-east-1",<br />    "SecondaryRegion": "us-west-2",<br />    "KMSKeyAliasName": "rds/rds-mysql-instance-KmsKeyId"<br />  }<br />}<br /></pre>**Amazon Aurora** 在 `Aurora-MySQL-parameter-us-east-1.json` 檔案中，`DBSecurityGroup`使用您建立的資源名稱更新 `SubnetIds`和 ：<pre>{<br />  "Parameters": {<br />    "SubnetIds": "subnet1-xxxxxx,subnet2-xxxxxx",<br />    "DBSecurityGroup": "sg-xxxxxxxxxx",<br />    "GlobalClusterIdentifier":"dr-globaldb-cluster-mysql",<br />    "DBClusterName":"dbcluster-01",<br />    "SourceDBClusterName":"dbcluster-02",<br />    "DBPortNumber": "3787",<br />    "DBInstanceClass":"db.r5.large",<br />    "InitialDatabaseName": "sampledb",<br />    "PrimaryRegion": "us-east-1",<br />    "SecondaryRegion": "us-west-2",<br />    "KMSKeyAliasName": "rds/dr-globaldb-cluster-mysql-KmsKeyId"<br />  }<br />}</pre>**Amazon ElastiCache (Redis OSS)**在 `ElastiCache-parameter-us-east-1.json` 檔案中，`DBSecurityGroup`使用您建立的資源名稱更新 `SubnetIds`和 。<pre>{<br />  "Parameters": {<br />    "CacheNodeType": "cache.m5.large",<br />    "DBSecurityGroup": "sg-xxxxxxxxxx",<br />    "SubnetIds": "subnet-xxxxxx,subnet-xxxxxx",<br />    "EngineVersion": "5.0.6",<br />    "GlobalReplicationGroupIdSuffix": "demo-redis-global-datastore",<br />    "NumReplicas": "1",<br />    "NumShards": "1",<br />    "ReplicationGroupId": "demo-redis-cluster",<br />    "DBPortNumber": "3788",<br />    "TransitEncryption": "true",<br />    "KMSKeyAliasName": "elasticache/demo-redis-global-datastore-KmsKeyId",<br />    "PrimaryRegion": "us-east-1",<br />    "SecondaryRegion": "us-west-2"<br />  }<br />}</pre> | AWS 管理員 | 
| 在主要區域中部署資料庫執行個體或叢集。 | 若要在主要區域 (`us-east-1`) 中部署執行個體或叢集，請根據您的資料庫引擎執行下列命令。**Amazon RDS**<pre>cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack<br /><br />aws cloudformation deploy \<br />--region us-east-1 \<br />--stack-name rds-mysql-app-stack \<br />--template-file RDS-MySQL-Primary.yaml \<br />--parameter-overrides file://RDS-MySQL-parameter-us-east-1.json \<br />--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \<br />--disable-rollback</pre>**Amazon Aurora**<pre>cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack<br /><br />aws cloudformation deploy \<br />--region us-east-1 \<br />--stack-name aurora-mysql-app-stack \<br />--template-file Aurora-MySQL-Primary.yaml \<br />--parameter-overrides file://Aurora-MySQL-parameter-us-east-1.json \<br />--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \<br />--disable-rollback</pre>**Amazon ElastiCache (Redis OSS)**<pre>cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack<br /><br />aws cloudformation deploy \<br />--region us-east-1 --stack-name elasticache-ds-app-stack \<br />--template-file ElastiCache-Primary.yaml \<br />--parameter-overrides file://ElastiCache-parameter-us-east-1.json \<br />--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \<br />--disable-rollback<br /></pre>確認 CloudFormation 資源已成功部署。 | AWS 管理員 | 
| 更新次要資料庫執行個體或叢集的參數檔案。 | 在 `<YOUR LOCAL GIT FOLDER>/App-Stack`資料夾中，更新次要區域的 參數檔案。**Amazon RDS**在 `RDS-MySQL-parameter-us-west-2.json` 檔案中，`DBSecurityGroup`使用您建立的資源名稱更新 `SubnetIDs`和 。`PrimaryRegionKMSKeyArn` 使用從 CloudFormation 主要資料庫執行個體堆疊的**輸出**區段`MySQLKmsKeyId`取得的 值來更新 ：<pre>{<br />  "Parameters": {<br />    "SubnetIds": "subnet-aaaaaaaaa,subnet-bbbbbbbbb",<br />    "DBSecurityGroup": "sg-cccccccccc",<br />    "MySqlGlobalIdentifier":"rds-mysql-instance",<br />    "InitialDatabaseName": "mysqldb",<br />    "DBPortNumber": "3789",<br />    "PrimaryRegion": "us-east-1",<br />    "SecondaryRegion": "us-west-2",<br />    "KMSKeyAliasName": "rds/rds-mysql-instance-KmsKeyId",<br />    "PrimaryRegionKMSKeyArn":"arn:aws:kms:us-east-1:xxxxxxxxx:key/mrk-xxxxxxxxxxxxxxxxxxxxx"<br />  }<br />} </pre>**Amazon Aurora**在 `Aurora-MySQL-parameter-us-west-2.json` 檔案中，`DBSecurityGroup`使用您建立的資源名稱更新 `SubnetIDs`和 。`PrimaryRegionKMSKeyArn` 使用`AuroraKmsKeyId`取自主要資料庫執行個體 CloudFormation 堆疊輸出****區段的 值來更新 ：<pre>{<br />  "Parameters": {<br />    "SubnetIds": "subnet1-aaaaaaaaa,subnet2-bbbbbbbbb",<br />    "DBSecurityGroup": "sg-cccccccccc",<br />    "GlobalClusterIdentifier":"dr-globaldb-cluster-mysql",<br />    "DBClusterName":"dbcluster-01",<br />    "SourceDBClusterName":"dbcluster-02",<br />    "DBPortNumber": "3787",<br />    "DBInstanceClass":"db.r5.large",<br />    "InitialDatabaseName": "sampledb",<br />    "PrimaryRegion": "us-east-1",<br />    "SecondaryRegion": "us-west-2",<br />    "KMSKeyAliasName": "rds/dr-globaldb-cluster-mysql-KmsKeyId"<br />  }<br />}</pre>**Amazon ElastiCache (Redis OSS)**在 `ElastiCache-parameter-us-west-2.json` 檔案中，`DBSecurityGroup`使用您建立的資源名稱更新 `SubnetIDs`和 。`PrimaryRegionKMSKeyArn` 使用`ElastiCacheKmsKeyId`取自主要資料庫執行個體 CloudFormation 堆疊輸出****區段的 值更新 ：<pre>{<br />  "Parameters": {<br />    "CacheNodeType": "cache.m5.large",<br />    "DBSecurityGroup": "sg-cccccccccc",<br />    "SubnetIds": "subnet-aaaaaaaaa,subnet-bbbbbbbbb",<br />    "EngineVersion": "5.0.6",<br />    "GlobalReplicationGroupIdSuffix": "demo-redis-global-datastore",<br />    "NumReplicas": "1",<br />    "NumShards": "1",<br />    "ReplicationGroupId": "demo-redis-cluster",<br />    "DBPortNumber": "3788",<br />    "TransitEncryption": "true",<br />    "KMSKeyAliasName": "elasticache/demo-redis-global-datastore-KmsKeyId",<br />    "PrimaryRegion": "us-east-1",<br />    "SecondaryRegion": "us-west-2"<br />  }<br />}</pre> | AWS 管理員 | 
| 在次要區域中部署資料庫執行個體或叢集。 | 根據您的資料庫引擎執行下列命令。**Amazon RDS**<pre>cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack<br /><br />aws cloudformation deploy \<br />--region us-west-2 \<br />--stack-name rds-mysql-app-stack \<br />--template-file RDS-MySQL-DR.yaml \<br />--parameter-overrides file://RDS-MySQL-parameter-us-west-2.json \<br />--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \<br />--disable-rollback</pre>**Amazon Aurora**<pre>cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack<br /><br />aws cloudformation deploy \<br />--region us-west-2 \<br />--stack-name aurora-mysql-app-stack \<br />--template-file Aurora-MySQL-DR.yaml \<br />--parameter-overrides file://Aurora-MySQL-parameter-us-west-2.json \<br />--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \<br />--disable-rollback</pre>**Amazon ElastiCache (Redis OSS)**<pre>cd <YOUR-LOCAL-GIT-FOLDER>/App-Stack<br /><br />aws cloudformation deploy \<br />--region us-west-2 \<br />--stack-name elasticache-ds-app-stack \<br />--template-file ElastiCache-DR.yaml \<br />--parameter-overrides file://ElastiCache-parameter-us-west-2.json \<br />--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM CAPABILITY_IAM \<br />--disable-rollback</pre>確認 CloudFormation 資源已成功部署。 | AWS 管理員 | 

## 相關資源
<a name="automate-cross-region-failover-and-failback-by-using-dr-orchestrator-framework-resources"></a>
+ [資料庫在 上的災難復原策略 AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/strategy-database-disaster-recovery/welcome.html) (AWS 方案指引策略）
+ [自動化 上關聯式資料庫的 DR 解決方案 AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/automate-dr-solution-relational-database/dr-orchestrator-framework-overview.html) (AWS 方案指引指南）
+ [使用 Amazon Aurora 全球資料庫](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html)
+ [AWS 區域 使用全域資料存放區跨 複寫](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Redis-Global-Datastore.html)
+ [自動化 上關聯式資料庫的 DR 解決方案 AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/automate-dr-solution-relational-database/introduction.html) (AWS 方案指引指南）

# 使用 Systems Manager 和 EventBridge 自動備份 SAP HANA 資料庫
<a name="automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge"></a>

*Ambarish Satarkar 和 Gaurav Rath，Amazon Web Services*

## 總結
<a name="automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge-summary"></a>

此模式說明如何使用 AWS Systems Manager、Amazon EventBridge、Amazon Simple Storage Service (Amazon S3) 和 AWS Backint Agent for SAP HANA 來自動化 SAP HANA 資料庫備份。

此模式使用 `BACKUP DATA`命令提供 Shell 指令碼型方法，並不需要在多個系統中維護每個作業系統 (OS) 執行個體的指令碼和任務組態。


| 
| 
| 注意：截至 2023 年 4 月，AWS Backup 宣布支援 Amazon Elastic Compute Cloud (Amazon EC2) 上的 SAP HANA 資料庫。如需詳細資訊，請參閱 [Amazon EC2 執行個體上的 SAP HANA 資料庫備份](https://docs.aws.amazon.com/aws-backup/latest/devguide/backup-saphana.html)。根據您的組織需求，您可以使用 AWS Backup 服務自動備份 SAP HANA 資料庫，也可以使用此模式。 | 
| --- |

## 先決條件和限制
<a name="automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge-prereqs"></a>

**先決條件**
+ 在為 Systems Manager 設定的受管 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上，具有執行中狀態支援版本的現有 SAP HANA 執行個體
+ Systems Manager Agent (SSM Agent) 2.3.274.0 或更新版本已安裝
+ 未啟用公有存取的 S3 儲存貯體
+ 名為 的 `hdbuserstore`Ankey`SYSTEM`
+ Automation Runbook 要按排程執行的 AWS Identity and Access Management (IAM) 角色
+ `AmazonSSMManagedInstanceCore` 和 `ssm:StartAutomationExecution`政策會連接至 Systems Manager Automation 服務角色。

**限制**
+ AWS Backint Agent for SAP HANA 不支援重複資料刪除。
+ AWS Backint Agent for SAP HANA 不支援資料壓縮。

**產品版本**

下列作業系統支援 AWS Backint Agent：
+ SUSE Linux Enterprise Server
+ SUSE Linux Enterprise Server for SAP
+ 適用於 SAP 的 Red Hat Enterprise Linux

AWS Backint Agent 支援下列資料庫： 
+ SAP HANA 1.0 SP12 （單一節點和多個節點）
+ SAP HANA 2.0 和更新版本 （單一節點和多個節點）

## Architecture
<a name="automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge-architecture"></a>

**目標技術堆疊**
+ AWS 後端代理程式
+ Amazon S3
+ AWS Systems Manager
+ Amazon EventBridge
+ SAP HANA

**目標架構**

下圖顯示安裝 AWS Backint Agent、S3 儲存貯體以及 Systems Manager 和 EventBridge 的安裝指令碼，這些指令碼使用 Command 文件來排程定期備份。

![\[排程定期備份的工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/0aa22a27-d100-483d-95f9-c3101f40402c/images/201d2b9a-b88e-4432-82cd-240b81da981e.png)


**自動化和擴展**
+ 您可以使用 Systems Manager Automation Runbook 安裝多個 AWS Backint 代理程式。
+ Systems Manager Runbook 的每個執行都可以根據目標選擇，擴展至 *n* 個 SAP HANA 執行個體。
+ EventBridge 可以自動化 SAP HANA 備份。

## 工具
<a name="automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge-tools"></a>
+ [AWS Backint Agent for SAP HANA](https://docs.aws.amazon.com/sap/latest/sap-hana/aws-backint-agent-sap-hana.html) 是一種獨立應用程式，可與您現有的工作流程整合，將 SAP HANA 資料庫備份到您在組態檔案中指定的 S3 儲存貯體。AWS Backint Agent 支援 SAP HANA 資料庫的完整、增量和差異備份。它在 SAP HANA 資料庫伺服器上執行，其中備份和目錄會從 SAP HANA 資料庫傳輸到 AWS Backint Agent。
+ [Amazon EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html) 是一種無伺服器事件匯流排服務，可用來將應用程式與來自各種來源的資料連線。EventBridge 會將即時資料從您的應用程式、軟體即服務 (SaaS) 應用程式和 AWS 服務串流傳送至目標，例如 AWS Lambda 函數、使用 API 目的地的 HTTP 調用端點，或其他帳戶中的事件匯流排。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種物件儲存服務。您可以使用 Amazon S3 隨時從 Web 任何地方存放和擷取任意資料量。
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) 可協助您在 AWS 上檢視和控制您的基礎設施。使用 Systems Manager 主控台，您可以檢視來自多個 AWS 服務的操作資料，並自動化 AWS 資源的操作任務。

**Code**

此模式的程式碼可在 [aws-backint-automated-backup](https://github.com/aws-samples/aws-backint-automated-backup) GitHub 儲存庫中使用。

## 史詩
<a name="automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge-epics"></a>

### 建立 hdbuserstore 金鑰 SYSTEM
<a name="create-an-hdbuserstore-key-system"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 hdbuserstore 金鑰。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge.html) | AWS 管理員、SAP HANA 管理員 | 

### 安裝 AWS Backint Agent
<a name="install-aws-backint-agent"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 AWS Backint Agent。 | 請遵循 [AWS Backint Agent 文件中的安裝和設定適用於 SAP HANA ](https://docs.aws.amazon.com/sap/latest/sap-hana/aws-backint-agent-installing-configuring.html)的 AWS Backint Agent 中的指示。 | AWS 管理員、SAP HANA 管理員 | 

### 建立 Systems Manager 命令文件
<a name="create-the-systems-manager-command-document"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Systems Manager 命令文件。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge.html) | AWS 管理員、SAP HANA 管理員 | 

### 定期排程備份
<a name="schedule-backups-on-a-regular-frequency"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 Amazon EventBridge 排程定期備份。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge.html)您可以從 S3 儲存貯體路徑驗證備份成功。 <pre> s3:/<your_bucket_name>/<target folder>/<SID>/usr/sap/<SID>/SYS/global/hdb/backint/DB_<SID>/</pre>您也可以從 SAP HANA 備份目錄驗證備份。 | AWS 管理員、SAP HANA 管理員 | 

## 相關資源
<a name="automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge-resources"></a>
+ [適用於 SAP HANA 的 AWS 後端代理程式](https://docs.aws.amazon.com/sap/latest/sap-hana/aws-backint-agent-sap-hana.html)
+ [安裝和設定適用於 SAP HANA 的 AWS Backint Agent](https://docs.aws.amazon.com/sap/latest/sap-hana/aws-backint-agent-installing-configuring.html)

# 使用 Python 應用程式自動產生 Amazon DynamoDB 的 PynamoDB 模型和 CRUD 函數 DynamoDB
<a name="automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application"></a>

*Vijit Vashishtha、Dheeraj Alimchandani 和 Dhananjay Karanjkar，Amazon Web Services*

## 總結
<a name="automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application-summary"></a>

通常需要實體和建立、讀取、更新和刪除 (CRUD) 操作函數，才能有效率地執行 Amazon DynamoDB 資料庫操作。PynamoDB 是以 Python 為基礎的介面，支援 Python 3。它還提供功能，例如支援 Amazon DynamoDB 交易、自動屬性值序列化和還原序列化，以及與常見 Python 架構的相容性，例如 Flask 和 Django。此模式透過提供簡化 DynamoDB 模型和 CRUD 操作函數自動建立的PynamoDB。雖然它為資料庫資料表產生必要的 CRUD 函數，但也可以從 Amazon PynamoDB 資料表反向工程 PynamoDB 模型和 CRUD 函數。 DynamoDB 此模式旨在使用 Python 型應用程式簡化資料庫操作。

以下是此解決方案的主要功能：
+ **PynamoDB 模型的 JSON 結構描述** – 透過匯入 JSON 結構描述檔案，在 Python 中自動產生 PynamoDB 模型。
+ **CRUD 函數產生** – 自動產生函數，以在 DynamoDB 資料表上執行 CRUD 操作。
+ **從 DynamoDB 反向工程** – 使用 PynamoDB 物件關聯映射 (ORM) 對現有 Amazon DynamoDB 資料表的 PynamoDB 模型和 CRUD 函數進行反向工程。 DynamoDB 

## 先決條件和限制
<a name="automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ Python 3.8 版或更新版本，[已下載](https://www.python.org/downloads/)並安裝
+ Jinja2 3.1.2 版或更新版本，[已下載](https://pypi.org/project/Jinja2/#files)並安裝
+ 您要為其產生 ORM 的 Amazon DynamoDB 資料表
+ AWS Command Line Interface (AWS CLI)，[已安裝](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)並[設定](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
+ PynamoDB 5.4.1 版或更新版本，[已安裝](https://pynamodb.readthedocs.io/en/stable/tutorial.html#installation)

## Architecture
<a name="automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application-architecture"></a>

**目標技術堆疊**
+ JSON 指令碼
+ Python 應用程式
+ PynamoDB 模型
+ Amazon DynamoDB 資料庫執行個體

**目標架構**

![\[使用 Python 應用程式從 DynamoDB 資料表產生 CRUD 函數和 PynamoDB 模型。 DynamoDB\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/74cc4c73-5c8b-448d-98fb-b681cfa5f860/images/c2c367d6-d88a-4f49-8571-89160539eb08.png)


1. 您可以建立輸入 JSON 結構描述檔案。此 JSON 結構描述檔案代表您要從 和 CRUD 函數建立 PynamoDB 模型之個別 DynamoDB 資料表的屬性。 PynamoDB 它包含以下三個重要金鑰：
   + `name` –目標 DynamoDB 資料表的名稱。
   + `region` – 資料表託管 AWS 區域 所在的
   + `attributes` – 屬於目標資料表一部分的屬性，例如[分割區索引鍵](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey) （也稱為*雜湊屬性*)、[排序索引鍵](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey)、[本機次要索引](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html)、[全域次要索引](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html)，以及任何[非索引鍵屬性](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.TablesItemsAttributes)。此工具預期輸入結構描述只會在應用程式直接從目標資料表擷取金鑰屬性時提供非金鑰屬性。如需如何在 JSON 結構描述檔案中指定屬性的範例，請參閱此模式[的其他資訊](#automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application-additional)一節。

1. 執行 Python 應用程式，並提供 JSON 結構描述檔案做為輸入。

1. Python 應用程式會讀取 JSON 結構描述檔案。

1. Python 應用程式會連線至 DynamoDB 資料表，以衍生結構描述和資料類型。應用程式會執行 [describe\$1table](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/describe_table.html) 操作，並擷取資料表的索引鍵和索引屬性。

1. Python 應用程式結合了 JSON 結構描述檔案和 DynamoDB 資料表中的屬性。它使用 Jinja 範本引擎來產生 PynamoDB 模型和對應的 CRUD 函數。

1. 您可以存取 PynamoDB 模型，在 DynamoDB 資料表上執行 CRUD 操作。

## 工具
<a name="automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application-tools"></a>

**AWS 服務**
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) 是一項全受管 NoSQL 資料庫服務，可提供快速、可預期且可擴展的效能。

**其他工具**
+ [Jinja](https://jinja.palletsprojects.com/en/) 是一種可擴展的範本引擎，可將範本編譯為最佳化的 Python 程式碼。此模式使用 Jinja 透過在範本中嵌入預留位置和邏輯來產生動態內容。
+ [PynamoDB](https://pynamodb.readthedocs.io/en/stable/) 是 Amazon DynamoDB 的 Python 型界面。
+ [Python](https://www.python.org/) 是一種一般用途的電腦程式設計語言。

**程式碼儲存庫**

此模式的程式碼可在 GitHub [自動產生 PynamoDB 模型和 CRUD 函數](https://github.com/aws-samples/amazon-reverse-engineer-dynamodb)儲存庫中使用。儲存庫分為兩個主要部分：控制器套件和範本。

*控制器套件*

控制器 Python 套件包含主要應用程式邏輯，可協助產生 PynamoDB 模型和 CRUD 函數。其中包含下列各項：
+ `input_json_validator.py` – 此 Python 指令碼會驗證輸入 JSON 結構描述檔案，並建立 Python 物件，其中包含目標 DynamoDB 資料表的清單，以及每個資料表的必要屬性。
+ `dynamo_connection.py` – 此指令碼會建立與 DynamoDB 資料表的連線，並使用 `describe_table`操作擷取建立 PynamoDB 模型所需的屬性。
+ `generate_model.py` – 此指令碼包含 Python 類別`GenerateModel`，可根據輸入 JSON 結構描述檔案和 `describe_table`操作來建立 PynamoDB 模型。
+ `generate_crud.py` – 對於 JSON 結構描述檔案中定義的 DynamoDB 資料表，此指令碼會使用 `GenerateCrud`操作來建立 Python 類別。

*範本*

此 Python 目錄包含下列 Jinja 範本：
+ `model.jinja` – 此 Jinja 範本包含用於產生 PynamoDB 模型指令碼的範本表達式。
+ `crud.jinja` – 此 Jinja 範本包含用於產生 CRUD 函數指令碼的範本表達式。

## 史詩
<a name="automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application-epics"></a>

### 設定環境
<a name="set-up-the-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 複製儲存庫。 | 輸入下列命令以複製[自動產生 PynamoDB 模型和 CRUD 函數](https://github.com/aws-samples/amazon-reverse-engineer-dynamodb)儲存庫。<pre>git clone https://github.com/aws-samples/amazon-reverse-engineer-dynamodb.git</pre> | 應用程式開發人員 | 
| 設定 Python 環境。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application.html) | 應用程式開發人員 | 

### 產生 PynamoDB 模型和 CRUD 函數
<a name="generate-the-pynamodb-model-and-crud-functions"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 修改 JSON 結構描述檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application.html) | 應用程式開發人員 | 
| 執行 Python 應用程式。 | 輸入下列命令來產生 PynamoDB 模型和 CRUD 函數，其中 `<input_schema.json>`是 JSON 結構描述檔案的名稱。<pre>python main.py --file <input_schema.json></pre> | 應用程式開發人員 | 

### 驗證 PynamoDB 模型和 CRUD 函數
<a name="verify-the-pynamodb-model-and-crud-functions"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證產生的 PynamoDB 模型。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application.html) | 應用程式開發人員 | 
| 驗證產生的 CRUD 函數。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application.html) | 應用程式開發人員 | 

## 相關資源
<a name="automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application-resources"></a>
+ [Amazon DynamoDB 的核心元件 ](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html)(DynamoDB 文件）
+ [使用次要索引改善資料存取 ](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SecondaryIndexes.html)(DynamoDB 文件）

## 其他資訊
<a name="automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application-additional"></a>

**JSON 結構描述檔案的範例屬性**

```
[
{
"name": "test_table",
"region": "ap-south-1",
"attributes": [
{
"name": "id",
"type": "UnicodeAttribute"
},
{
"name": "name",
"type": "UnicodeAttribute"
},
{
"name": "age",
"type": "NumberAttribute"
}
]
}
]
```

# 使用 Cloud Custodian 封鎖對 Amazon RDS 的公開存取
<a name="block-public-access-to-amazon-rds-by-using-cloud-custodian"></a>

*abhay kumar 和 Dwarika Patra，Amazon Web Services*

## 總結
<a name="block-public-access-to-amazon-rds-by-using-cloud-custodian-summary"></a>

許多組織會在多個雲端廠商上執行工作負載和服務。在這些混合雲端環境中，除了個別雲端提供者提供的安全性之外，雲端基礎設施還需要嚴格的雲端控管。Amazon Relational Database Service (Amazon RDS) 等雲端資料庫是一項重要的服務，必須監控是否有任何存取和許可漏洞。雖然您可以透過設定安全群組來限制對 Amazon RDS 資料庫的存取，但您可以新增第二層保護來禁止公開存取等動作。封鎖公開存取可協助您符合一般資料保護法規 (GDPR)、健康保險流通與責任法案 (HIPAA)、國家標準與技術研究所 (NIST)，以及支付卡產業資料安全標準 (PCI DSS)。

Cloud Custodian 是開放原始碼規則引擎，可用來強制執行 Amazon RDS 等 Amazon Web Services (AWS) 資源的存取限制。使用 Cloud Custodian，您可以設定規則，根據定義的安全和合規標準來驗證環境。您可以使用 Cloud Custodian 來管理雲端環境，方法是協助確保符合安全政策、標籤政策，以及未使用的資源和成本管理的垃圾回收。使用 Cloud Custodian，您可以使用單一界面在混合雲端環境中實作控管。例如，您可以使用 Cloud Custodian 介面與 AWS 和 Microsoft Azure 互動，減少使用 AWS Config AWS 安全群組和 Azure 政策等機制的工作量。

此模式提供在 上使用 Cloud Custodian AWS 以在 Amazon RDS 執行個體上強制執行公有可存取性限制的指示。

## 先決條件和限制
<a name="block-public-access-to-amazon-rds-by-using-cloud-custodian-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ [金鑰對](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-creds-create)
+ AWS Lambda 已安裝

## Architecture
<a name="block-public-access-to-amazon-rds-by-using-cloud-custodian-architecture"></a>

下圖顯示 Cloud Custodian 將政策部署到 AWS Lambda、 AWS CloudTrail 啟動`CreateDBInstance`事件，以及將 Amazon RDS 上的 Lambda 函數設定為 `PubliclyAccessible` false。

![\[在 AWS 上使用 Cloud Custodian 來限制對 Amazon RDS 執行個體的公開存取。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/90f9537e-9365-4da2-8a28-da0ff374743c/images/6d04ca3b-6aa4-4c62-ade9-8b7474928c5e.png)


## 工具
<a name="block-public-access-to-amazon-rds-by-using-cloud-custodian-tools"></a>

**AWS 服務**
+ [AWS CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html) 可協助您稽核 的控管、合規和營運風險 AWS 帳戶。
+ [AWS Command Line Interface (AWS CLI)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 是一種開放原始碼工具，可協助您 AWS 服務 透過命令列 shell 中的命令與 互動。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一項運算服務，可協助您執行程式碼，無需佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需支付使用的運算時間。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 中設定、操作和擴展關聯式資料庫 AWS 雲端。

**其他工具**
+ [Cloud Custodian](https://cloudcustodian.io/) 會將許多組織用來管理公有雲端帳戶的工具和指令碼統一為單一開放原始碼工具。它使用無狀態規則引擎進行政策定義和強制執行，具有指標、結構化輸出和雲端基礎設施的詳細報告。它與無伺服器執行期緊密整合，以低營運開銷提供即時修補和回應。

## 史詩
<a name="block-public-access-to-amazon-rds-by-using-cloud-custodian-epics"></a>

### 設定 AWS CLI
<a name="set-up-the-cli"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 AWS CLI。 | 若要安裝 AWS CLI，請遵循 [AWS 文件](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)中的指示。 | AWS 管理員 | 
| 設定 AWS 登入資料。 | 設定 AWS CLI 用來與 互動的設定 AWS，包括您要使用的 AWS 區域 和輸出格式。<pre>$>aws configure<br />AWS Access Key ID [None]: <your_access_key_id><br />AWS Secret Access Key [None]: <your_secret_access_key><br />Default region name [None]:<br />Default output format [None]:</pre>如需詳細資訊，請參閱 [AWS 文件](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)。 | AWS 管理員 | 
| 建立 IAM 角色。 | 若要使用 Lambda 執行角色建立 IAM 角色，請執行下列命令。<pre>aws iam create-role --role-name lambda-ex --assume-role-policy-document '{"Version": "2012-10-17",		 	 	 "Statement": [{ "Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, "Action": "sts:AssumeRole"}]}</pre> | AWS DevOps | 

### 設定雲端託管人
<a name="set-up-cloud-custodian"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 Cloud Custodian。 | 若要為您的作業系統和環境安裝 Cloud Custodian，請遵循 [Cloud Custodian 文件](https://cloudcustodian.io/docs/quickstart/index.html#install-cc)中的指示。 | DevOps 工程師 | 
| 檢查雲端託管結構描述。 | 若要查看您可以對其執行政策的 Amazon RDS 資源完整清單，請使用下列命令。<pre>custodian schema aws.rds</pre> | DevOps 工程師 | 
| 建立 Cloud Custodian 政策。 | 使用 YAML 擴充功能，在[其他資訊](#block-public-access-to-amazon-rds-by-using-cloud-custodian-additional)區段中儲存 *Cloud Custodian 政策檔案*下的程式碼。 | DevOps 工程師 | 
| 定義 Cloud Custodian 動作以變更可公開存取的旗標。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/block-public-access-to-amazon-rds-by-using-cloud-custodian.html) | DevOps 工程師 | 
| 執行試轉。 | （選用） 若要檢查政策識別哪些資源，而不對資源執行任何動作，請使用下列命令。<pre>custodian run -dryrun <policy_name>.yaml -s <output_directory></pre> | DevOps 工程師 | 

### 部署政策
<a name="deploy-the-policy"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 Lambda 部署政策。 | 若要建立將執行政策的 Lambda 函數，請使用下列命令。<pre>custodian run -s policy.yaml</pre>此政策接著將由事件 AWS CloudTrail `CreateDBInstance`啟動。因此， 針對符合條件的執行個體， AWS Lambda 會將可公開存取的旗標設定為 `false` 。 | DevOps 工程師 | 

## 相關資源
<a name="block-public-access-to-amazon-rds-by-using-cloud-custodian-resources"></a>
+ [AWS Lambda website](https://aws.amazon.com/lambda/)
+ [Amazon RDS 網站](https://aws.amazon.com/rds/)
+ [雲端託管人文件](https://cloudcustodian.io/docs/quickstart/index.html)

## 其他資訊
<a name="block-public-access-to-amazon-rds-by-using-cloud-custodian-additional"></a>

**雲端託管人政策 YAML 檔案**

```
policies:
  - name: "block-public-access"
    resource: rds
    description: |
      This Enforcement blocks public access for RDS instances.
    mode:
      type: cloudtrail
      events:
        - event: CreateDBInstance # Create RDS instance cloudtrail event
          source: rds.amazonaws.com
          ids: requestParameters.dBInstanceIdentifier
      role: arn:aws:iam::1234567890:role/Custodian-compliance-role
    filters:
      - type: event
        key: 'detail.requestParameters.publiclyAccessible'
        value: true
    actions:
      - type: set-public-access
        state: false
```

**c7n 資源 rds.py 檔案**

```
@actions.register('set-public-access')
 class RDSSetPublicAvailability(BaseAction):
 
     schema = type_schema(
         "set-public-access",
         state={'type': 'boolean'})
     permissions = ('rds:ModifyDBInstance',)
 
     def set_accessibility(self, r):
         client = local_session(self.manager.session_factory).client('rds')
         waiter = client.get_waiter('db_instance_available')
         waiter.wait(DBInstanceIdentifier=r['DBInstanceIdentifier'])
         client.modify_db_instance(
             DBInstanceIdentifier=r['DBInstanceIdentifier'],
             PubliclyAccessible=self.data.get('state', False))
 
 
     def process(self, rds):
         with self.executor_factory(max_workers=2) as w:
             futures = {w.submit(self.set_accessibility, r): r for r in rds}
             for f in as_completed(futures):
                 if f.exception():
                     self.log.error(
                         "Exception setting public access on %s  \n %s",
                         futures[f]['DBInstanceIdentifier'], f.exception())
         return rds
```

**Security Hub CSPM 整合**

雲端託管人可與 整合[AWS Security Hub CSPM](https://aws.amazon.com/security-hub/)，以傳送安全調查結果並嘗試修復動作。如需詳細資訊，請參閱[與 宣布雲端託管整合 AWS Security Hub CSPM](https://aws.amazon.com/blogs/opensource/announcing-cloud-custodian-integration-aws-security-hub/)。

# 使用 設定 Amazon RDS for Microsoft SQL Server 的 Windows 身分驗證 AWS Managed Microsoft AD
<a name="configure-windows-authentication-for-amazon-rds-using-microsoft-ad"></a>

*Ramesh Babu Donti，Amazon Web Services*

## 總結
<a name="configure-windows-authentication-for-amazon-rds-using-microsoft-ad-summary"></a>

此模式示範如何使用 AWS Directory Service for Microsoft Active Directory () 為 SQL Server 執行個體的 Amazon Relational Database Service (Amazon RDS) 設定 Windows 身分驗證AWS Managed Microsoft AD。Windows 身分驗證允許使用者使用其網域登入資料來連線至 RDS 執行個體，而不是資料庫特定的使用者名稱和密碼。

您可以在建立新的 RDS SQL Server 資料庫時啟用 Windows 身分驗證，或將其新增至現有的資料庫執行個體。資料庫執行個體與 整合 AWS Managed Microsoft AD ，為存取 SQL Server 資料庫的網域使用者提供集中式身分驗證和授權。

此組態透過利用現有的 Active Directory 基礎設施來增強安全性，無需為網域使用者管理單獨的資料庫登入資料。

## 先決條件和限制
<a name="configure-windows-authentication-for-amazon-rds-using-microsoft-ad-prereqs"></a>

**先決條件**
+  AWS 帳戶 具有適當許可的作用中
+ 具有下列項目的虛擬私有雲端 (VPC)：
  + 設定的網際網路閘道和路由表
  + 公有子網路中的 NAT 閘道 （如果執行個體需要網際網路存取）
+ AWS Identity and Access Management (IAM) 角色：
  + 具有下列 AWS 受管政策的網域角色：
    + `AmazonSSMManagedInstanceCore` 以啟用 AWS Systems Manager
    + `AmazonSSMDirectoryServiceAccess` 提供將執行個體加入目錄的許可
  + RDS 增強型監控角色 （如果已啟用增強型監控）
+ 安全群組：
  + 目錄服務安全群組，以允許 Active Directory 通訊連接埠
  + Amazon Elastic Compute Cloud (Amazon EC2) 安全群組，允許 RDP `3389`和網域通訊
  + 允許`1433`來自授權來源之 SQL Server 連接埠的 RDS 安全群組
+ 網路連接：
  + 子網路之間的適當 DNS 解析和網路連線

**限制**
+ 如需 AWS Managed Microsoft AD RDS for SQL Server AWS 區域 支援的相關資訊，請參閱 [區域和版本可用性](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_SQLServerWinAuth.html#USER_SQLServerWinAuth.RegionVersionAvailability)。
+ 有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

## Architecture
<a name="configure-windows-authentication-for-amazon-rds-using-microsoft-ad-architecture"></a>

**來源技術堆疊**
+ 內部部署 Active Directory 或 AWS Managed Microsoft AD

**目標技術堆疊**
+ Amazon EC2
+ Amazon RDS for Microsoft SQL Server
+ AWS Managed Microsoft AD

**目標架構**

![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/e02f6059-6631-46f6-819c-5961af7ba4ae/images/1aa50e3b-b4f6-4d44-9f9e-6cbb248a159c.png)


架構包含下列項目：
+ 將 Amazon EC2 執行個體加入 AWS Managed Microsoft AD 網域的 IAM 角色。
+ 用於資料庫管理和測試的 Amazon EC2 Windows 執行個體。
+ 具有私有子網路的 Amazon VPC，可跨可用區域託管 Amazon RDS 執行個體和內部資源。
+ 網路存取控制的安全群組：
  + Amazon RDS 安全群組，用於控制`1433`從授權來源對 SQL Server 連接埠的傳入存取。
  + 透過連接埠`3389`和網域通訊連接埠管理 RDP 存取的 Amazon EC2 安全群組。
  + 透過連接埠 `53`、`389`、 `88`和 進行 Active Directory 通訊的 Directory Services 安全群組`445`。
+ AWS Managed Microsoft AD 為 Windows 資源提供集中式身分驗證和授權服務。
+ 啟用 Windows 身分驗證之私有子網路中的 Amazon RDS for SQL Server 資料庫執行個體。

## 工具
<a name="configure-windows-authentication-for-amazon-rds-using-microsoft-ad-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ Amazon Relational Database Service (Amazon RDS) 可協助您在 中設定、操作和擴展關聯式資料庫 AWS 雲端。
+ [AWS Directory Service](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/what_is.html) 提供多種搭配其他 使用 Microsoft Active Directory (AD) 的方式， AWS 服務 例如 Amazon Elastic Compute Cloud (Amazon EC2)、適用於 SQL Server 的 Amazon Relational Database Service (Amazon RDS) 和適用於 Windows File Server 的 Amazon FSx。
+ [AWS Directory Service for Microsoft Active Directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html) 可讓您的目錄感知工作負載 AWS 和資源在 中使用 Microsoft Active Directory AWS 雲端。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。

**其他服務**
+ [Microsoft SQL Server Management Studio (SSMS)](https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms) 是一種用於管理 SQL Server 的工具，包括存取、設定和管理 SQL Server 元件。

## 最佳實務
<a name="configure-windows-authentication-for-amazon-rds-using-microsoft-ad-best-practices"></a>
+ 如需一般最佳實務，請參閱 [Amazon RDS 的最佳實務](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_BestPractices.html)。

## 史詩
<a name="configure-windows-authentication-for-amazon-rds-using-microsoft-ad-epics"></a>

### 設定 AWS Managed Microsoft AD
<a name="configure-managed-ad"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定目錄類型。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 設定目錄資訊。 | 在**目錄資訊**區段中，輸入必要資訊，並保留選用值：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 設定 VPC 和子網路。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 檢閱並建立 目錄。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 

### 建立和設定 Amazon EC2 執行個體
<a name="create-and-configure-an-ec2-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定適用於 Windows 的 AMI。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 設定網路設定。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 設定儲存體。 | 視需要設定 Amazon EBS 磁碟區。 | DBA，DevOps 工程師 | 
| 設定進階詳細資訊並啟動執行個體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 

### 使用 Windows 身分驗證建立和設定 RDS for SQL Server
<a name="create-and-configure-rds-for-sql-server-with-windows-authentication"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立資料庫並設定引擎選項。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 選擇一個範本。 | 選擇符合您需求的範例範本。 | DBA，DevOps 工程師 | 
| 設定資料庫設定。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 設定執行個體。 | 在**執行個體組態**區段的**資料庫執行個體類別**下，選取符合您需求的執行個體大小。 | DBA，DevOps 工程師 | 
| 設定儲存體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 設定連線。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 設定 Windows 身分驗證。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 設定監控。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html)注意：當您想要查看不同的程序或執行緒如何使用 CPU 時， 指標很有用。如果啟用錯誤日誌，您也可以將**錯誤日誌**匯出至 Amazon CloudWatch。 | DBA，DevOps 工程師 | 
| 設定其他設定。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 檢閱成本並建立資料庫。 | 檢閱**預估每月成本**區段，然後選擇**建立資料庫**。 | DBA，DevOps 工程師 | 

### 設定資料庫存取和測試連線
<a name="configure-database-access-and-test-connections"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 連線至 Windows 機器。 | 連接至 Windows 機器並啟動 SQL Server Management Studio。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 設定 SSMS 連線。 | 使用 Windows 身分驗證設定資料庫連線。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 設定安全設定。 | 設定 SSMS 第 20 版或更新版本的必要安全參數。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 
| 建立 Windows 登入。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html)<pre>CREATE LOGIN [<domainName>\<user_name>] FROM WINDOWS;<br />GO</pre> | DBA，DevOps 工程師 | 
| 測試 Windows 身分驗證。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-windows-authentication-for-amazon-rds-using-microsoft-ad.html) | DBA，DevOps 工程師 | 

## 相關資源
<a name="configure-windows-authentication-for-amazon-rds-using-microsoft-ad-resources"></a>
+ [建立您的 AWS Managed Microsoft AD](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_getting_started_create_directory.html)
+ [將 Amazon EC2 Windows 執行個體加入您的 AWS Managed Microsoft AD](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/launching_instance.html)
+ [Amazon RDS 中 Kerberos 身分驗證支援的區域和資料庫引擎](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RDS_Fea_Regions_DB-eng.Feature.KerberosAuthentication.html)
+ [什麼是 SQL Server Management Studio (SSMS)？](https://learn.microsoft.com/en-us/ssms/sql-server-management-studio-ssms)

# 設定對 Amazon DynamoDB 的跨帳戶存取權
<a name="configure-cross-account-access-to-amazon-dynamodb"></a>

*Shashi Dalmia、Imhoertha Ojior 和 Esteban Serna Parra，Amazon Web Services*

## 總結
<a name="configure-cross-account-access-to-amazon-dynamodb-summary"></a>

此模式說明使用資源型政策設定 Amazon DynamoDB 跨帳戶存取的步驟。對於使用 DynamoDB 的工作負載，使用[工作負載隔離策略](https://aws.amazon.com/solutions/guidance/workload-isolation-on-aws/?did=sl_card&trk=sl_card)將安全威脅降至最低並符合合規要求變得越來越常見。實作工作負載隔離策略通常需要跨帳戶和跨區域存取 DynamoDB 資源，方法是使用 AWS Identity and Access Management (IAM) 身分型政策。這包括設定 IAM 許可，以及在 之間建立信任關係 AWS 帳戶。

[DynamoDB 的資源型政策](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/access-control-resource-based.html)可大幅簡化跨帳戶工作負載的安全狀態。此模式提供步驟和範例程式碼，示範如何在一個 中設定 AWS Lambda 函數 AWS 帳戶 ，以將資料寫入不同帳戶中的 DynamoDB 資料庫資料表。

## 先決條件和限制
<a name="configure-cross-account-access-to-amazon-dynamodb-prereqs"></a>

**先決條件**
+ 兩個作用中 AWS 帳戶。此模式將這些帳戶稱為*帳戶 A *和*帳戶 B*。
+ AWS Command Line Interface (AWS CLI) [已安裝](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)並[設定為](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)存取帳戶 A，以建立 DynamoDB 資料表。此模式中的其他步驟提供使用 IAM、DynamoDB 和 Lambda 主控台的指示。如果您打算 AWS CLI 改用 ，請將其設定為存取這兩個帳戶。

**限制**
+ 有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

## Architecture
<a name="configure-cross-account-access-to-amazon-dynamodb-architecture"></a>

下圖顯示單一帳戶架構。 AWS Lambda、Amazon Elastic Compute Cloud (Amazon EC2) 和 DynamoDB 都位於同一個帳戶中。在此案例中，Lambda 函數和 Amazon EC2 執行個體可以存取 DynamoDB。若要授予 DynamoDB 資料表的存取權，您可以在 IAM 中建立身分型政策，也可以在 DynamoDB 中建立資源型政策。

![\[使用 IAM 許可來存取相同帳戶中的 DynamoDB 資料表。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/bfc32fe8-5db0-4cac-a30f-b870a1a82875/images/cbb009eb-422d-4833-a1bc-0c571d83c21f.png)


下圖顯示多帳戶架構。如果其中一個資源 AWS 帳戶 需要存取不同帳戶中的 DynamoDB 資料表，您需要在 DynamoDB 中設定資源型政策，以授予所需的存取權。例如，在下圖中，帳戶 A 中 DynamoDB 資料表的存取權是透過使用資源型政策授予帳戶 B 中 Lambda 函數的。

![\[使用資源型政策來存取不同帳戶中的 DynamoDB 資料表。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/bfc32fe8-5db0-4cac-a30f-b870a1a82875/images/9f9165a8-b767-4427-a2ae-31b5b8c83326.png)


此模式描述 Lambda 和 DynamoDB 之間的跨帳戶存取。 AWS 服務 如果兩個帳戶都設定了適當的許可，則可以對其他帳戶使用類似的步驟。例如，如果您想要提供 Lambda 函數存取帳戶 A 中的 Amazon Simple Storage Service (Amazon S3) 儲存貯體，您可以在 Amazon S3 中建立[資源型政策](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-policies.html)，並將許可新增至帳戶 B 中的 [Lambda 執行角色](https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html)。

## 工具
<a name="configure-cross-account-access-to-amazon-dynamodb-tools"></a>

**AWS 服務**
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) 是一項全受管 NoSQL 資料庫服務，可提供快速、可預期且可擴展的效能。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一項運算服務，可協助您執行程式碼，無需佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需支付使用的運算時間。

**Code**

此模式包含[額外資訊](#configure-cross-account-access-to-amazon-dynamodb-additional)區段中的範例程式碼，示範如何在帳戶 B 中設定 Lambda 函數，以寫入帳戶 A 中的 DynamoDB 資料表。此程式碼僅供說明和測試之用。如果您要在生產環境中實作此模式，請使用程式碼做為參考，並針對您自己的環境進行自訂。

## 最佳實務
<a name="configure-cross-account-access-to-amazon-dynamodb-best-practices"></a>
+ 遵循 DynamoDB 文件中[資源型政策的最佳實務](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/rbac-best-practices.html)。
+ 遵循最低權限原則，並授予執行任務所需的最低許可。如需詳細資訊，請參閱 IAM 文件中的[授予最低權限](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#grant-least-priv)和[安全最佳實務](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)。

## 史詩
<a name="configure-cross-account-access-to-amazon-dynamodb-epics"></a>

### 在帳戶 B 中為 Lambda 函數建立 IAM 政策和角色
<a name="create-an-iam-policy-and-role-for-the-lam-function-in-account-b"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在帳戶 B 中建立政策。 | 此 IAM 政策允許帳戶 A 中 DynamoDB 資料表的 [PutItem](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_PutItem.html) 動作。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-cross-account-access-to-amazon-dynamodb.html) | 一般 AWS | 
| 在帳戶 B 中建立角色。 | 帳戶 B 中的 Lambda 函數使用此 IAM 角色來存取帳戶 A 中的 DynamoDB 資料表。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-cross-account-access-to-amazon-dynamodb.html)如需建立角色的詳細資訊，請參閱 [IAM 文件](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html)。 | 一般 AWS | 
| 請記下 角色 ARN。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-cross-account-access-to-amazon-dynamodb.html) | 一般 AWS | 

### 在帳戶 A 中建立 DynamoDB 資料表
<a name="create-a-ddb-table-in-account-a"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 DynamoDB 資料表。 | 使用下列 AWS CLI 命令來建立 DynamoDB 資料表。<pre> aws dynamodb create-table \<br />    --table-name Table-Account-A \<br />    --attribute-definitions \<br />      AttributeName=category,AttributeType=S \<br />      AttributeName=item,AttributeType=S \<br />    --key-schema \<br />      AttributeName=category,KeyType=HASH \<br />      AttributeName=item,KeyType=RANGE \<br />    --provisioned-throughput \<br />      ReadCapacityUnits=5,WriteCapacityUnits=5 \<br />    --resource-policy \<br />      '{         <br />          "Version": "2012-10-17",		 	 	 <br />          "Statement": [<br />            {                    <br />               "Sid": "Statement1",<br />               "Effect": "Allow",<br />               "Principal": {<br />                  "AWS": "arn:aws:iam::<Account-B-ID>:role/<Role-Name>"<br />               },<br />               "Action": "dynamodb:PutItem",<br />               "Resource": "arn:aws:dynamodb:<Region>:<Account-A-ID>:table/Table-Account-A"<br />            }            <br />         ]<br />      }'</pre>取代此程式碼範例中的以下內容：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-cross-account-access-to-amazon-dynamodb.html)您可以使用 `--resource-policy`旗標，在 `create-table`陳述式中指定資源型政策組態。此政策是指帳戶 A 中 DynamoDB 資料表的 ARN。如需建立資料表的詳細資訊，請參閱 [DynamoDB 文件](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStartedDynamoDB.html)。 | 一般 AWS | 

### 在帳戶 B 中建立 Lambda 函數
<a name="create-a-lam-function-in-account-b"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Lambda 函數以將資料寫入 DynamoDB。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-cross-account-access-to-amazon-dynamodb.html)如需建立 Lambda 函數的詳細資訊，請參閱 [Lambda 文件](https://docs.aws.amazon.com/lambda/latest/dg/getting-started-create-function.html)。 | 一般 AWS | 

### 清除
<a name="clean-up"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 刪除 資源。 | 若要避免產生與此模式中建立的資源相關的成本，請執行下列動作來刪除這些資源：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-cross-account-access-to-amazon-dynamodb.html) | 一般 AWS | 

## 疑難排解
<a name="configure-cross-account-access-to-amazon-dynamodb-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 建立 Lambda 函數時，您會收到`ResourceNotFoundException`錯誤。 | 確認您已正確輸入帳戶 A 的 AWS 區域 和 ID。這些是 DynamoDB 資料表 ARN 的一部分。 | 

## 相關資源
<a name="configure-cross-account-access-to-amazon-dynamodb-resources"></a>
+ [DynamoDB 入門](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStartedDynamoDB.html) (DynamoDB 文件）
+ [Lambda 入門 ](https://docs.aws.amazon.com/lambda/latest/dg/getting-started.html)(Lambda 文件）
+ [使用 DynamoDB 的資源型政策 ](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/access-control-resource-based.html)(DynamoDB 文件）
+ [建立 IAM 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html) (IAM 文件）
+ [跨帳戶政策評估邏輯 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic-cross-account.html)(IAM 文件）
+ [IAM JSON 政策元素參考](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html) (IAM 文件）

## 其他資訊
<a name="configure-cross-account-access-to-amazon-dynamodb-additional"></a>

*範例程式碼*

```
import boto3
from datetime import datetime

dynamodb_client = boto3.client('dynamodb')

def lambda_handler(event, context):
     now = datetime.now().isoformat()
     data = dynamodb_client.put_item(TableName='arn:aws:dynamodb:<Region>:<Account-A-ID>:table/Table-Account-A', Item={"category": {"S": "Fruit"},"item": {"S": "Apple"},"time": {"S": now}})
     return data
```

**注意**  
執行個體化 DynamoDB 用戶端時，會提供 DynamoDB 資料表的 ARN，而不是資料表名稱。這是必要的，以便 Lambda 函數在執行時連接到正確的 DynamoDB 資料表。

# 在 AWS 上 SQL Server 的 Always On 可用性群組中設定唯讀路由
<a name="configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws"></a>

*Subhani Shaik，Amazon Web Services*

## 總結
<a name="configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws-summary"></a>

此模式涵蓋如何在 SQL Server Always On 中使用待命次要複本，方法是將唯讀工作負載從主要複本卸載至次要複本。

資料庫鏡像具有one-to-one映射。您無法直接讀取次要資料庫，因此您必須建立快照。Always On 可用性群組功能已在 Microsoft SQL Server 2012 中推出。在較新版本中，已引進主要功能，包括唯讀路由。在 Always On 可用性群組中，您可以將複本模式變更為唯讀，以直接從次要複本讀取資料。

Always On 可用性群組解決方案支援高可用性 (HA)、災難復原 (DR)，以及資料庫鏡像的替代方案。Always On 可用性群組可在資料庫層級運作，並將一組使用者資料庫的可用性最大化。

SQL Server 使用唯讀路由機制，將傳入的唯讀連線重新導向至次要僅供讀取複本。若要達成此目的，您應該在連線字串中新增下列參數和值：
+ `ApplicationIntent=ReadOnly`
+ `Initial Catalog=<database name>`

## 先決條件和限制
<a name="configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws-prereqs"></a>

**先決條件**
+ 具有虛擬私有雲端 (VPC)、兩個可用區域、私有子網路和安全群組的作用中 AWS 帳戶
+ 兩部 Amazon Elastic Compute Cloud (Amazon EC2) 機器，具有在執行個體層級設定的 [SQL Server 2019 Enterprise Edition Amazon Machine Image](https://aws.amazon.com/marketplace/pp/prodview-btjcozd246p6w) with [Windows Server 容錯移轉叢集 (WSFC)](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-sql-server/ec2-fci.html)，以及在主要節點 () 和次要節點 (`WSFCNODE1`) 之間的 SQL Server 層級設定的 Always On 可用性群組`WSFCNODE2`，這是名為 AWS Directory Service for Microsoft Active Directory 目錄的一部分 `tagechtalk.com`
+ 在次要複本`read-only`中設定為接受的一或多個節點
+ 名為 Always On 可用性群組`SQLAG1`的接聽程式
+ 在兩個節點上使用相同服務帳戶執行的 SQL Server Database Engine
+ SQL Server Management Studio (SSMS)
+ 名為 的測試資料庫 `test`

**產品版本**
+ SQL Server 2014 及更新版本

## Architecture
<a name="configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws-architecture"></a>

**目標技術堆疊**
+ Amazon EC2
+ AWS 受管 Microsoft AD
+ Amazon FSx

**目標架構**

下圖顯示 Always On 可用性群組 (AG) 接聽程式如何將連線中包含 `ApplicationIntent` 參數的查詢重新導向至適當的次要節點。

![\[節點 1 WSFC 和節點 2 WSFC 與 Amazon EFS 的兩個可用區域之間的三個步驟程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/19b5937b-da10-4c74-8619-fdcb758f2211/images/f9ba0f89-7dc2-4f4c-8eee-bef56968ad2d.png)


1. 請求會傳送至 Always On 可用性群組接聽程式。

1. 如果連線字串沒有 `ApplicationIntent` 參數，請求會傳送至主要執行個體。

1. 如果連線字串包含 `ApplicationIntent=ReadOnly`，則請求會傳送至具有唯讀路由組態 的次要執行個體，這是具有 Always On 可用性群組的 WSFC。

## 工具
<a name="configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws-tools"></a>

**AWS 服務**
+ [AWS Directory Service for Microsoft Active Directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html) 可讓您的目錄感知工作負載和 AWS 資源在 AWS 雲端中使用 Microsoft Active Directory。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Amazon FSx](https://docs.aws.amazon.com/fsx/?id=docs_gateway) 提供支援業界標準連線通訊協定的檔案系統，並跨 AWS 區域提供高可用性和複寫功能。

**其他服務**
+ SQL Server Management Studio (SSMS) 是一種用於連接、管理和管理 SQL Server 執行個體的工具。
+ sqlcmd 是命令列公用程式。

## 最佳實務
<a name="configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws-best-practices"></a>

如需 Always On 可用性群組的詳細資訊，請參閱 [SQL Server 文件](https://learn.microsoft.com/en-us/sql/database-engine/availability-groups/windows/always-on-availability-groups-sql-server?view=sql-server-ver16)。

## 史詩
<a name="configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws-epics"></a>

### 設定唯讀路由
<a name="set-up-read-only-routing"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將複本更新為唯讀。 | 若要同時將主要複本和次要複本更新為唯讀，請從 SSMS 連線至主要複本，然後從*其他資訊*區段執行*步驟 1* 程式碼。 | DBA | 
| 建立路由 URL。 | 若要建立兩個複本的路由 URL，請從*其他資訊*區段執行*步驟 2* 程式碼。在此程式碼中， `tagechtalk.com`是 AWS Managed Microsoft AD 目錄的名稱。 | DBA | 
| 建立路由清單。 | 若要建立兩個複本的路由清單，請從*其他資訊*區段執行步驟 3 程式碼。 | DBA | 
| 驗證路由清單。 | 從 SQL Server Management Studio 連線至主要執行個體，並從*其他資訊*區段執行*步驟 4* 程式碼，以驗證路由清單。 | DBA | 

### 測試唯讀路由
<a name="test-the-read-only-routing"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 ApplicationIntent 參數進行連線。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws.html) | DBA | 
| 執行容錯移轉。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws.html) | DBA | 

### 使用 sqlcmd 命令列公用程式進行連線
<a name="connect-by-using-the-sqlcmd-command-line-utility"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 sqlcmd 連線。 | 若要從 sqlcmd 連線，請從命令提示字元*的其他資訊*區段執行*步驟 5* 程式碼。連線後，請執行下列命令以顯示連線的伺服器名稱。<pre>SELECT SERVERPROPERTY('ComputernamePhysicalNetBios') .</pre>輸出會顯示目前的次要複本名稱 (`WSFCNODE1`)。 | DBA | 

## 疑難排解
<a name="configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 建立接聽程式失敗，並顯示「WSFC 叢集無法讓網路名稱資源上線」訊息。 | 如需詳細資訊，請參閱 Microsoft 部落格文章 [Create Listener Fails with Message 'WSFC 叢集無法讓網路名稱資源上線'](https://techcommunity.microsoft.com/t5/sql-server-support-blog/create-listener-fails-with-message-the-wsfc-cluster-could-not/ba-p/318235)。 | 
| 潛在問題，包括其他接聽程式問題或網路存取問題。 | 請參閱 Microsoft 文件中的 [Always On 可用性群組組態 (SQL Server) 故障診斷](https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/troubleshoot-always-on-availability-groups-configuration-sql-server?view=sql-server-ver16)。 | 

## 相關資源
<a name="configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws-resources"></a>
+ [設定 Always On 可用性群組的唯讀路由](https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/configure-read-only-routing-for-an-availability-group-sql-server?view=sql-server-ver16)
+ [故障診斷 Always On 可用性群組組態 (SQL Server)](https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/troubleshoot-always-on-availability-groups-configuration-sql-server?view=sql-server-ver16)

## 其他資訊
<a name="configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws-additional"></a>

**步驟 1. 將複本更新為唯讀**

```
ALTER AVAILABILITY GROUP [SQLAG1] MODIFY REPLICA ON N'WSFCNODE1' WITH (SECONDARY_ROLE (ALLOW_CONNECTIONS = READ_ONLY))
GO
ALTER AVAILABILITY GROUP [SQLAG1] MODIFY REPLICA ON N'WSFCNODE2' WITH (SECONDARY_ROLE (ALLOW_CONNECTIONS = READ_ONLY))
GO
```

**步驟 2. 建立路由 URL**

```
ALTER AVAILABILITY GROUP [SQLAG1] MODIFY REPLICA ON N'WSFCNODE1' WITH (SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'TCP://WSFCNode1.tagechtalk.com:1433'))
GO
ALTER AVAILABILITY GROUP [SQLAG1] MODIFY REPLICA ON N'WSFCNODE2' WITH (SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'TCP://WSFCNode2.tagechtalk.com:1433'))
GO
```

**步驟 3. 建立路由清單**

```
ALTER AVAILABILITY GROUP [SQLAG1] MODIFY REPLICA ON N'WSFCNODE1' WITH (PRIMARY_ROLE(READ_ONLY_ROUTING_LIST=('WSFCNODE2','WSFCNODE1')));
GO
ALTER AVAILABILITY GROUP [SQLAG1] MODIFY REPLICA ON N'WSFCNODE2' WITH (PRIMARY_ROLE (READ_ONLY_ROUTING_LIST=('WSFCNODE1','WSFCNODE2')));
GO
```

**步驟 4. 驗證路由清單**

```
SELECT AGSrc.replica_server_name AS PrimaryReplica, AGRepl.replica_server_name AS ReadOnlyReplica, AGRepl.read_only_routing_url AS RoutingURL , AGRL.routing_priority AS RoutingPriority FROM sys.availability_read_only_routing_lists AGRL INNER JOIN sys.availability_replicas AGSrc ON AGRL.replica_id = AGSrc.replica_id INNER JOIN sys.availability_replicas AGRepl ON AGRL.read_only_replica_id = AGRepl.replica_id INNER JOIN sys.availability_groups AV ON AV.group_id = AGSrc.group_id ORDER BY PrimaryReplica
```

**步驟 5. SQL 命令公用程式**

```
sqlcmd -S SQLAG1,1433 -E -d test -K ReadOnly
```

# 在 pgAdmin 中使用 SSH 通道進行連線
<a name="connect-by-using-an-ssh-tunnel-in-pgadmin"></a>

*Jeevan Shetty 和 Bhanu Ganesh Gudivada，Amazon Web Services*

## 總結
<a name="connect-by-using-an-ssh-tunnel-in-pgadmin-summary"></a>

基於安全考量，將資料庫放置在私有子網路中一律是不錯的做法。透過 Amazon Web Services (AWS) 雲端上的公有子網路中的 Amazon Elastic Compute Cloud (Amazon EC2) 堡壘主機，可以對資料庫執行查詢。這需要在 Amazon EC2 主機上安裝開發人員或資料庫管理員常用的軟體，例如 pgAdmin 或 DBeaver。

在 Linux 伺服器上執行 pgAdmin 並透過 Web 瀏覽器存取，需要安裝其他相依性、許可設定和組態。

做為替代解決方案，開發人員或資料庫管理員可以使用 pgAdmin 從本機系統啟用 SSH 通道，以連線至 PostgreSQL 資料庫。在此方法中，pgAdmin 會在連線至資料庫之前，使用公有子網路中的 Amazon EC2 主機做為中介主機。*架構*區段中的圖表顯示設定。

**注意**  
確定連接至 PostgreSQL 資料庫的安全群組允許從 Amazon EC2 主機連線連接埠 5432。

## 先決條件和限制
<a name="connect-by-using-an-ssh-tunnel-in-pgadmin-prereqs"></a>

**先決條件**
+ 現有的 AWS 帳戶
+ 具有公有子網路和私有子網路的虛擬私有雲端 (VPC)
+ 連接安全群組的 EC2 執行個體
+ 連接安全群組的 Amazon Aurora PostgreSQL 相容版本資料庫
+ 用於設定通道的安全殼層 (SSH) 金鑰對

**產品版本**
+ pgAdmin 6.2\$1 版
+ Amazon Aurora PostgreSQL 相容版本 12.7\$1

## Architecture
<a name="connect-by-using-an-ssh-tunnel-in-pgadmin-architecture"></a>

**目標技術堆疊**
+ Amazon EC2
+ Amazon Aurora PostgreSQL 相容

**目標架構**

下圖顯示搭配 SSH 通道使用 pgAdmin 來透過網際網路閘道連線至 EC2 執行個體，而 EC2 執行個體會連線至資料庫。

![\[pgAdmin 搭配 SSH 通道會透過網際網路閘道連線至連線至資料庫的 EC2 執行個體。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/7d25d570-5685-4f1a-bef0-212e257cb589/images/4556d930-f9b3-4b65-be5d-d40dd9437d5a.png)


## 工具
<a name="connect-by-using-an-ssh-tunnel-in-pgadmin-tools"></a>

**AWS 服務**
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。

**其他服務**
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。

## 史詩
<a name="connect-by-using-an-ssh-tunnel-in-pgadmin-epics"></a>

### 建立連線
<a name="create-the-connection"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立伺服器。 | 在 pgAdmin 中，選擇**建立**，然後選擇**伺服器**。如需設定 pgAdmin 以註冊伺服器、設定連線，以及使用伺服器對話方塊透過 SSH 通道連線的其他說明，請參閱*相關資源*一節中的連結。 | DBA | 
| 提供伺服器的名稱。 | 在**一般**索引標籤上，輸入名稱。 | DBA | 
| 輸入資料庫詳細資訊。 | 在**連線**索引標籤上，輸入下列項目的值：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/connect-by-using-an-ssh-tunnel-in-pgadmin.html) | DBA | 
| 輸入 Amazon EC2 伺服器詳細資訊。 | 在 **SSH 通道**索引標籤上，提供公有子網路中 Amazon EC2 執行個體的詳細資訊。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/connect-by-using-an-ssh-tunnel-in-pgadmin.html) | DBA | 
| 儲存並連線。 | 選擇**儲存**以完成設定，並使用 SSH 通道連線至 Aurora PostgreSQL 相容資料庫。 | DBA | 

## 相關資源
<a name="connect-by-using-an-ssh-tunnel-in-pgadmin-resources"></a>
+ [伺服器對話方塊](https://www.pgadmin.org/docs/pgadmin4/latest/server_dialog.html)
+ [連線至伺服器](https://www.pgadmin.org/docs/pgadmin4/latest/connect_to_server.html)

# 將 JSON Oracle 查詢轉換為 PostgreSQL 資料庫 SQL
<a name="convert-json-oracle-queries-into-postgresql-database-sql"></a>

*Pinesh Singal 和 Lokesh Gurram，Amazon Web Services*

## 總結
<a name="convert-json-oracle-queries-into-postgresql-database-sql-summary"></a>

此從內部部署移至 Amazon Web Services (AWS) Cloud 的遷移程序會使用 AWS Schema Conversion Tool (AWS SCT)，將程式碼從 Oracle 資料庫轉換為 PostgreSQL 資料庫。AWS SCT 會自動轉換大部分的程式碼。不過，JSON 相關的 Oracle 查詢不會自動轉換。

從 Oracle 12.2 版本開始，Oracle Database 支援各種 JSON 函數，可協助將 JSON 型資料轉換為 ROW 型資料。不過，AWS SCT 不會自動將 JSON 型資料轉換為 PostgreSQL 支援的語言。

此遷移模式主要著重於使用 `JSON_OBJECT`、 `JSON_ARRAYAGG`和 等函數，將 JSON 相關的 Oracle 查詢`JSON_TABLE`從 Oracle 資料庫手動轉換為 PostgreSQL 資料庫。

## 先決條件和限制
<a name="convert-json-oracle-queries-into-postgresql-database-sql-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署 Oracle 資料庫執行個體 （啟動和執行中）
+ 適用於 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS) 或 Amazon Aurora PostgreSQL 相容版本資料庫執行個體 （啟動和執行中）

**限制**
+ JSON 相關查詢需要固定的 `KEY`和 `VALUE` 格式。不使用該格式會傳回錯誤的結果。
+ 如果 JSON 結構中的任何變更在結果區段中新增新的 `KEY`和 `VALUE`對，則必須在 SQL 查詢中變更對應的程序或函數。
+ 舊版 Oracle 和 PostgreSQL 支援某些 JSON 相關函數，但功能較少。

**產品版本**
+ Oracle 資料庫 12.2 版及更新版本
+ Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容 9.5 版及更新版本
+ AWS SCT 最新版本 （使用 1.0.664 版測試） 

## Architecture
<a name="convert-json-oracle-queries-into-postgresql-database-sql-architecture"></a>

**來源技術堆疊**
+ 版本為 19c 的 Oracle 資料庫執行個體

**目標技術堆疊**
+ 版本為 13 的 Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容資料庫執行個體

**目標架構**

![\[描述遵循圖表。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5e2c3b07-9ef5-417f-b049-bcea58f2c3ec/images/2ff8b00b-8849-4ef1-9be1-579f7b51be10.png)


1. 使用 AWS SCT 搭配 JSON 函數程式碼，將原始程式碼從 Oracle 轉換為 PostgreSQL。

1. 轉換會產生 PostgreSQL 支援的遷移 .sql 檔案。

1. 手動將非轉換的 Oracle JSON 函數程式碼轉換為 PostgreSQL JSON 函數程式碼。

1. 在目標 Aurora PostgreSQL 相容資料庫執行個體上執行 .sql 檔案。

## 工具
<a name="convert-json-oracle-queries-into-postgresql-database-sql-tools"></a>

**AWS 服務**
+ [Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html) 是一種全受管關聯式資料庫引擎，專為雲端而建置，並與 MySQL 和 PostgreSQL 相容。
+ [適用於 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html) 可協助您在 AWS 雲端中設定、操作和擴展 PostgreSQL 關聯式資料庫。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 會自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，以支援異質資料庫遷移。

**其他服務**
+ [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) 是一種整合的開發環境，可簡化傳統和雲端部署中 Oracle 資料庫的開發和管理。
+ pgAdmin 或 DBeaver。[pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。[DBeaver](https://dbeaver.io/) 是一種通用資料庫工具。

## 最佳實務
<a name="convert-json-oracle-queries-into-postgresql-database-sql-best-practices"></a>

使用 `JSON_TABLE`函數時，Oracle 查詢的預設`CAST`類型為 。最佳實務也是在 PostgreSQL `CAST`中使用，使用兩倍大於字元 (`>>`)。

如需詳細資訊，請參閱*其他資訊*區段中的 *Postgres\$1SQL\$1Read\$1JSON*。

## 史詩
<a name="convert-json-oracle-queries-into-postgresql-database-sql-epics"></a>

### 在 Oracle 和 PostgreSQL 資料庫中產生 JSON 資料
<a name="generate-the-json-data-in-the-oracle-and-postgresql-databases"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 JSON 資料存放在 Oracle 資料庫中。 | 在 Oracle 資料庫中建立資料表，並將 JSON 資料存放在 `CLOB`欄中。 使用*額外資訊*區段中的 *Oracle\$1Table\$1Creation\$1Insert\$1Script*。 | 遷移工程師 | 
| 將 JSON 資料存放在 PostgreSQL 資料庫中。 | 在 PostgreSQL 資料庫中建立資料表，並將 JSON 資料存放在 `TEXT`欄中。使用*其他資訊*區段中的 *Postgres\$1Table\$1Creation\$1Insert\$1Script*。 | 遷移工程師 | 

### 將 JSON 轉換為 ROW 格式
<a name="convert-the-json-into-row-format"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 轉換 Oracle 資料庫上的 JSON 資料。 | 撰寫 Oracle SQL 查詢，以 ROW 格式讀取 JSON 資料。如需詳細資訊和語法範例，請參閱*其他資訊*區段中的 *Oracle\$1SQL\$1Read\$1JSON*。 | 遷移工程師 | 
| 轉換 PostgreSQL 資料庫上的 JSON 資料。 | 撰寫 PostgreSQL 查詢，以 ROW 格式讀取 JSON 資料。如需詳細資訊和語法範例，請參閱*其他資訊*區段中的 *Postgres\$1SQL\$1Read\$1JSON*。 | 遷移工程師 | 

### 使用 SQL 查詢手動轉換 JSON 資料，並以 JSON 格式報告輸出
<a name="manually-convert-the-json-data-using-the-sql-query-and-report-the-output-in-json-format"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Oracle SQL 查詢上執行彙總和驗證。 | 若要手動轉換 JSON 資料，請對 Oracle SQL 查詢執行聯結、彙總和驗證，並以 JSON 格式報告輸出。在*其他資訊*區段中的 *Oracle\$1SQL\$1JSON\$1Aggregation\$1Join* 下使用程式碼。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-json-oracle-queries-into-postgresql-database-sql.html) | 遷移工程師 | 
| 在 Postgres SQL 查詢上執行彙總和驗證。 | 若要手動轉換 JSON 資料，請對 PostgreSQL 查詢執行聯結、彙總和驗證，並以 JSON 格式報告輸出。在*其他資訊*區段的 *Postgres\$1SQL\$1JSON\$1Aggregation\$1Join* 下使用程式碼。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/convert-json-oracle-queries-into-postgresql-database-sql.html) | 遷移工程師 | 

### 將 Oracle 程序轉換為包含 JSON 查詢的 PostgreSQL 函數
<a name="convert-the-oracle-procedure-into-a-postgresql-function-that-contains-json-queries"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 Oracle 程序中的 JSON 查詢轉換為資料列。 | 如需 Oracle 程序範例，請使用上一個 Oracle 查詢，以及*其他資訊*區段中的代碼 under*Oracle\$1procedure\$1with\$1JSON\$1Query*。 | 遷移工程師 | 
| 將具有 JSON 查詢的 PostgreSQL 函數轉換為資料列型資料。 | 如需 PostgreSQL 函數範例，請使用先前的 PostgreSQL 查詢，以及*其他資訊*區段中 *Postgres\$1function\$1with\$1JSON\$1Query* 下的程式碼。 | 遷移工程師 | 

## 相關資源
<a name="convert-json-oracle-queries-into-postgresql-database-sql-resources"></a>
+ [Oracle JSON 函數](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/adjsn/generation.html)
+ [PostgreSQL JSON 函數](https://www.postgresql.org/docs/13/functions-json.html)
+ [Oracle JSON 函數範例](https://oracle-base.com/articles/12c/sql-json-functions-12cr2)
+ [PostgreSQL JSON 函數範例](https://dba.stackexchange.com/questions/69655/select-columns-inside-json-agg)
+ [AWS Schema Conversion Tool](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)

## 其他資訊
<a name="convert-json-oracle-queries-into-postgresql-database-sql-additional"></a>

若要將 JSON 程式碼從 Oracle 資料庫轉換為 PostgreSQL 資料庫，請依序使用下列指令碼。

**1。Oracle\$1Table\$1Creation\$1Insert\$1Script**

```
create table aws_test_table(id number,created_on date default sysdate,modified_on date,json_doc clob);

REM INSERTING into EXPORT_TABLE
SET DEFINE OFF;
Insert into aws_test_table (ID,CREATED_ON,MODIFIED_ON,json_doc)
values (1,to_date('02-AUG-2022 12:30:14','DD-MON-YYYY HH24:MI:SS'),to_date('02-AUG-2022 12:30:14','DD-MON-YYYY HH24:MI:SS'),TO_CLOB(q'[{
  "metadata" : {
    "upperLastNameFirstName" : "ABC XYZ",
    "upperEmailAddress" : "abc@gmail.com",
    "profileType" : "P"
  },
  "data" : {
    "onlineContactId" : "032323323",
    "displayName" : "Abc, Xyz",
    "firstName" : "Xyz",
    "lastName" : "Abc",
    "emailAddress" : "abc@gmail.com",
    "productRegistrationStatus" : "Not registered",
    "positionId" : "0100",
    "arrayPattern" : " -'",
    "a]')
|| TO_CLOB(q'[ccount" : {
      "companyId" : "SMGE",
      "businessUnitId" : 7,
      "accountNumber" : 42000,
      "parentAccountNumber" : 32000,
      "firstName" : "john",
      "lastName" : "doe",
      "street1" : "retOdertcaShr ",
      "city" : "new york",
      "postalcode" : "XY ABC",
      "country" : "United States"
    },
    "products" : [
      {
        "appUserGuid" : "i0acc4450000001823fbad478e2eab8a0",
        "id" : "0000000046",
]')
|| TO_CLOB(q'[        "name" : "ProView",
        "domain" : "EREADER",
        "registrationStatus" : false,
        "status" : "11"
      }
    ]
  }
}]'));
Insert into aws_test_table (ID,CREATED_ON,MODIFIED_ON,json_doc) values (2,to_date('02-AUG-2022 12:30:14','DD-MON-YYYY HH24:MI:SS'),to_date('02-AUG-2022 12:30:14','DD-MON-YYYY HH24:MI:SS'),TO_CLOB(q'[{
  "metadata" : {
    "upperLastNameFirstName" : "PQR XYZ",
    "upperEmailAddress" : "pqr@gmail.com",
    "profileType" : "P"
  },
  "data" : {
    "onlineContactId" : "54534343",
    "displayName" : "Xyz, pqr",
    "firstName" : "pqr",
    "lastName" : "Xyz",
    "emailAddress" : "pqr@gmail.com",
    "productRegistrationStatus" : "Not registered",
    "positionId" : "0090",
    "arrayPattern" : " -'",
    "account" : {
      "companyId" : "CARS",
      "busin]')
|| TO_CLOB(q'[essUnitId" : 6,
      "accountNumber" : 42001,
      "parentAccountNumber" : 32001,
      "firstName" : "terry",
      "lastName" : "whitlock",
      "street1" : "UO  123",
      "city" : "TOTORON",
      "region" : "NO",
      "postalcode" : "LKM 111",
      "country" : "Canada"
    },
    "products" : [
      {
        "appUserGuid" : "ia744d7790000016899f8cf3f417d6df6",
        "id" : "0000000014",
        "name" : "ProView eLooseleaf",
      ]')
|| TO_CLOB(q'[  "domain" : "EREADER",
        "registrationStatus" : false,
        "status" : "11"
      }
    ]
  }
}]'));

commit;
```

**2. Postgres\$1Table\$1Creation\$1Insert\$1Script**

```
create table aws_test_pg_table(id int,created_on date ,modified_on date,json_doc text);
insert into aws_test_pg_table(id,created_on,modified_on,json_doc)
values(1,now(),now(),'{
  "metadata" : {
    "upperLastNameFirstName" : "ABC XYZ",
    "upperEmailAddress" : "abc@gmail.com",
    "profileType" : "P"
  },
  "data" : {
    "onlineContactId" : "032323323",
    "displayName" : "Abc, Xyz",
    "firstName" : "Xyz",
    "lastName" : "Abc",
    "emailAddress" : "abc@gmail.com",
    "productRegistrationStatus" : "Not registered",
    "positionId" : "0100",
    "arrayPattern" : " -",
    "account" : {
      "companyId" : "SMGE",
      "businessUnitId" : 7,
      "accountNumber" : 42000,
      "parentAccountNumber" : 32000,
      "firstName" : "john",
      "lastName" : "doe",
      "street1" : "retOdertcaShr ",
      "city" : "new york",
      "postalcode" : "XY ABC",
      "country" : "United States"
    },
    "products" : [
      {
        "appUserGuid" : "i0acc4450000001823fbad478e2eab8a0",
        "id" : "0000000046",
        "name" : "ProView",
        "domain" : "EREADER",
        "registrationStatus" : false,
        "status" : "11"
      }
    ]
  }
}');


insert into aws_test_pg_table(id,created_on,modified_on,json_doc)
values(2,now(),now(),'{
  "metadata" : {
    "upperLastNameFirstName" : "PQR XYZ",
    "upperEmailAddress" : "pqr@gmail.com",
    "profileType" : "P"
  },
  "data" : {
    "onlineContactId" : "54534343",
    "displayName" : "Xyz, pqr",
    "firstName" : "pqr",
    "lastName" : "Xyz",
    "emailAddress" : "a*b**@h**.k**",
    "productRegistrationStatus" : "Not registered",
    "positionId" : "0090",
    "arrayPattern" : " -",
    "account" : {
      "companyId" : "CARS",
      "businessUnitId" : 6,
      "accountNumber" : 42001,
      "parentAccountNumber" : 32001,
      "firstName" : "terry",
      "lastName" : "whitlock",
      "street1" : "UO  123",
      "city" : "TOTORON",
      "region" : "NO",
      "postalcode" : "LKM 111",
      "country" : "Canada"
    },
    "products" : [
      {
        "appUserGuid" : "ia744d7790000016899f8cf3f417d6df6",
        "id" : "0000000014",
        "name" : "ProView eLooseleaf",
        "domain" : "EREADER",
        "registrationStatus" : false,
        "status" : "11"
      }
    ]
  }
}');
```

**3. Oracle\$1SQL\$1Read\$1JSON**

下列程式碼區塊顯示如何將 Oracle JSON 資料轉換為資料列格式。

*查詢和語法範例*

```
SELECT   JSON_OBJECT( 
 'accountCounts' VALUE JSON_ARRAYAGG( 
            JSON_OBJECT( 
                'businessUnitId' VALUE business_unit_id, 
                        'parentAccountNumber' VALUE parent_account_number, 
                        'accountNumber' VALUE account_number, 
                        'totalOnlineContactsCount' VALUE online_contacts_count, 
                        'countByPosition' VALUE 
                    JSON_OBJECT( 
                        'taxProfessionalCount' VALUE tax_count, 
                        'attorneyCount' VALUE attorney_count,
                        'nonAttorneyCount' VALUE non_attorney_count, 
                        'clerkCount' VALUE clerk_count
                               ) ) ) ) FROM 
    (SELECT   tab_data.business_unit_id, 
            tab_data.parent_account_number, 
            tab_data.account_number, 
            SUM(1) online_contacts_count, 
            SUM(CASE WHEN tab_data.position_id = '0095' THEN  1 ELSE 0 END) tax_count, 
            SUM(CASE    WHEN tab_data.position_id = '0100' THEN 1 ELSE 0 END) attorney_count, 
            SUM(CASE    WHEN tab_data.position_id = '0090' THEN 1 ELSE 0 END) non_attorney_count,                                       
            SUM(CASE    WHEN tab_data.position_id = '0050' THEN 1 ELSE 0 END) clerk_count 
        FROM aws_test_table scco,JSON_TABLE ( json_doc, '$' ERROR ON ERROR         COLUMNS ( 
          parent_account_number NUMBER PATH
           '$.data.account.parentAccountNumber',
            account_number NUMBER PATH '$.data.account.accountNumber',
            business_unit_id NUMBER PATH '$.data.account.businessUnitId',
            position_id VARCHAR2 ( 4 ) PATH '$.data.positionId'    )
            ) AS tab_data 
            INNER JOIN JSON_TABLE ( '{ 
        "accounts": [{ 
          "accountNumber": 42000, 
          "parentAccountNumber": 32000, 
          "businessUnitId": 7 
        }, { 
          "accountNumber": 42001, 
          "parentAccountNumber": 32001, 
          "businessUnitId": 6 
        }] 
      }', '$.accounts[*]' ERROR ON ERROR 
      COLUMNS (
      parent_account_number PATH '$.parentAccountNumber',
      account_number PATH '$.accountNumber',
      business_unit_id PATH '$.businessUnitId')
      ) static_data 
      ON ( static_data.parent_account_number = tab_data.parent_account_number 
           AND static_data.account_number = tab_data.account_number  
           AND static_data.business_unit_id = tab_data.business_unit_id ) 
        GROUP BY 
            tab_data.business_unit_id, 
            tab_data.parent_account_number, 
            tab_data.account_number );
```

JSON 文件會將資料儲存為集合。每個集合都可以有 `KEY`和 `VALUE`對。每個 `VALUE`都可以有巢狀 `KEY`和 `VALUE`對。下表提供`VALUE`從 JSON 文件讀取特定 的相關資訊。


| 
| 
| KEY | 用來取得 VALUE 的 HIERARCHY 或 PATH | VALUE | 
| --- |--- |--- |
| `profileType` | `metadata` -> `profileType` | "P" | 
| `positionId` | `data` -> `positionId` | "0100" | 
| `accountNumber` | `data` -> 帳戶 -> `accountNumber` | 42000 | 

在上表中， `KEY``profileType`是 `metadata` `VALUE`的 `KEY`。`KEY` `positionId` 是 `VALUE`的 `data` `KEY`。`KEY` `accountNumber` 是 `VALUE`的 `account` `KEY`，而 `account``KEY`是 `VALUE`的 `data` `KEY`。

*範例 JSON 文件*

```
{
  "metadata" : {
    "upperLastNameFirstName" : "ABC XYZ",
    "upperEmailAddress" : "abc@gmail.com",
"profileType" : "P"
  },
  "data" : {
    "onlineContactId" : "032323323",
    "displayName" : "Abc, Xyz",
    "firstName" : "Xyz",
    "lastName" : "Abc",
    "emailAddress" : "abc@gmail.com",
    "productRegistrationStatus" : "Not registered",
"positionId" : "0100",
    "arrayPattern" : " -",
    "account" : {
      "companyId" : "SMGE",
      "businessUnitId" : 7,
"accountNumber" : 42000,
      "parentAccountNumber" : 32000,
      "firstName" : "john",
      "lastName" : "doe",
      "street1" : "retOdertcaShr ",
      "city" : "new york",
      "postalcode" : "XY ABC",
      "country" : "United States"
    },
    "products" : [
      {
        "appUserGuid" : "i0acc4450000001823fbad478e2eab8a0",
        "id" : "0000000046",
        "name" : "ProView",
        "domain" : "EREADER",
        "registrationStatus" : false,
        "status" : "11"
      }
    ]
  }
}
```

*用於從 JSON 文件取得所選欄位的 SQL 查詢*

```
select parent_account_number,account_number,business_unit_id,position_id from aws_test_table aws,JSON_TABLE ( json_doc, '$' ERROR ON ERROR
COLUMNS (
parent_account_number NUMBER PATH '$.data.account.parentAccountNumber',
account_number NUMBER PATH '$.data.account.accountNumber',
business_unit_id NUMBER PATH '$.data.account.businessUnitId',
position_id VARCHAR2 ( 4 ) PATH '$.data.positionId'
)) as sc
```

在先前的查詢中， `JSON_TABLE` 是 Oracle 中的內建函數，可將 JSON 資料轉換為資料列格式。JSON\$1TABLE 函數預期 JSON 格式的參數。

中的每個項目`COLUMNS`都有預先定義的 `PATH`，並且會以資料列格式`KEY`傳回`VALUE`適合給定的項目。

*上一個查詢的結果*


| 
| 
| PARENT\$1ACCOUNT\$1NUMBER | ACCOUNT\$1NUMBER | BUSINESS\$1UNIT\$1ID | POSITION\$1ID | 
| --- |--- |--- |--- |
| 32000 | 42000 | 7 | 0100 | 
| 32001 | 42001 | 6 | 0090 | 

**4. Postgres\$1SQL\$1Read\$1JSON**

** ***查詢和語法範例*

```
select *
from ( 
select (json_doc::json->'data'->'account'->>'parentAccountNumber')::INTEGER as parentAccountNumber, 
(json_doc::json->'data'->'account'->>'accountNumber')::INTEGER as accountNumber, 
(json_doc::json->'data'->'account'->>'businessUnitId')::INTEGER as businessUnitId, 
(json_doc::json->'data'->>'positionId')::VARCHAR as positionId 
from aws_test_pg_table) d ;
```

在 Oracle 中， `PATH` 用於識別特定 `KEY`和 `VALUE`。不過，PostgreSQL 會使用`HIERARCHY`模型`VALUE`從 JSON 讀取 `KEY` 和 。以下範例`Oracle_SQL_Read_JSON`使用 所述的相同 JSON 資料。

*不允許類型為 CAST 的 SQL 查詢*

（如果您強制輸入 `CAST`，查詢會失敗並出現語法錯誤。)

```
select *
from ( 
select (json_doc::json->'data'->'account'->'parentAccountNumber') as parentAccountNumber, 
(json_doc::json->'data'->'account'->'accountNumber')as accountNumber, 
(json_doc::json->'data'->'account'->'businessUnitId') as businessUnitId, 
(json_doc::json->'data'->'positionId')as positionId 
from aws_test_pg_table) d ;
```

使用單一大於運算子 (`>`) 將傳回為該 `VALUE`定義的 `KEY`。例如，`KEY`： `positionId`和 `VALUE`：`"0100"`。

當您使用單一大於運算子 () 時，`CAST`不允許輸入 `>`。

*允許類型為 CAST 的 SQL 查詢*

```
select *
from ( 
select (json_doc::json->'data'->'account'->>'parentAccountNumber')::INTEGER as parentAccountNumber, 
(json_doc::json->'data'->'account'->>'accountNumber')::INTEGER as accountNumber, 
(json_doc::json->'data'->'account'->>'businessUnitId')::INTEGER as businessUnitId, 
(json_doc::json->'data'->>'positionId')::varchar as positionId 
from aws_test_pg_table) d ;
```

若要使用類型 `CAST`，您必須使用雙大於運算子。如果您使用單一大於運算子，查詢會傳回`VALUE`已定義的 （例如 `KEY`： `positionId`和 `VALUE`：`"0100"`)。使用雙大於運算子 (`>>`) 將傳回為該值定義的實際值 `KEY`（例如 `KEY`： `positionId`和 `VALUE`：`0100`，不含雙引號）。

在上述情況下， `parentAccountNumber` 是 `CAST`的類型`INT`， `accountNumber` 是 `CAST`的類型`INT`， `businessUnitId` 是 `CAST`的類型`INT`， `positionId`是 的類型， 是 `CAST`的類型`VARCHAR`。

下表顯示查詢結果，說明單一大於運算子 (`>`) 和雙大於運算子 () 的角色`>>`。

在第一個資料表中，查詢使用單一大於運算子 (`>`)。每個資料欄都是 JSON 類型，無法轉換為其他資料類型。


| 
| 
| parentAccountNumber | accountNumber | businessUnitId | positionId | 
| --- |--- |--- |--- |
| 2003565430 | 2003564830 | 7 | "0100" | 
| 2005284042 | 2005284042 | 6 | "0090" | 
| 2000272719 | 2000272719 | 1 | "0100" | 

在第二個資料表中，查詢使用大於運算子的兩倍 (`>>`)。每個資料欄都支援`CAST`以資料欄值為基礎的類型。例如，在此內容`INTEGER`中。


| 
| 
| parentAccountNumber | accountNumber | businessUnitId | positionId | 
| --- |--- |--- |--- |
| 2003565430 | 2003564830 | 7 | 0100 | 
| 2005284042 | 2005284042 | 6 | 0090 | 
| 2000272719 | 2000272719 | 1 | 0100 | 

**5. Oracle\$1SQL\$1JSON\$1Aggregation\$1Join**

*查詢範例*

```
SELECT 
    JSON_OBJECT( 
        'accountCounts' VALUE JSON_ARRAYAGG( 
            JSON_OBJECT( 
                'businessUnitId' VALUE business_unit_id, 
                        'parentAccountNumber' VALUE parent_account_number, 
                        'accountNumber' VALUE account_number, 
                        'totalOnlineContactsCount' VALUE online_contacts_count, 
                        'countByPosition' VALUE 
                    JSON_OBJECT( 
                        'taxProfessionalCount' VALUE tax_count, 
                        'attorneyCount' VALUE attorney_count, 
                        'nonAttorneyCount' VALUE non_attorney_count, 
                        'clerkCount' VALUE clerk_count
                               ) ) ) ) 
FROM 
    (SELECT 
            tab_data.business_unit_id, 
            tab_data.parent_account_number, 
            tab_data.account_number, 
            SUM(1) online_contacts_count, 
            SUM(CASE WHEN tab_data.position_id = '0095' THEN  1 ELSE 0 END) tax_count, 
            SUM(CASE    WHEN tab_data.position_id = '0100' THEN 1 ELSE 0 END) attorney_count,                                                       
            SUM(CASE    WHEN tab_data.position_id = '0090' THEN 1 ELSE 0 END) non_attorney_count,                                                   
            SUM(CASE    WHEN tab_data.position_id = '0050' THEN 1 ELSE 0 END) clerk_count                                                           
        FROM aws_test_table scco,JSON_TABLE ( json_doc, '$' ERROR ON ERROR         COLUMNS ( 
          parent_account_number NUMBER PATH
           '$.data.account.parentAccountNumber',
            account_number NUMBER PATH '$.data.account.accountNumber',
            business_unit_id NUMBER PATH '$.data.account.businessUnitId',
            position_id VARCHAR2 ( 4 ) PATH '$.data.positionId'    )
            ) AS tab_data 
            INNER JOIN JSON_TABLE ( '{ 
        "accounts": [{ 
          "accountNumber": 42000, 
          "parentAccountNumber": 32000, 
          "businessUnitId": 7 
        }, { 
          "accountNumber": 42001, 
          "parentAccountNumber": 32001, 
          "businessUnitId": 6 
        }] 
      }', '$.accounts[*]' ERROR ON ERROR    
      COLUMNS (
      parent_account_number PATH '$.parentAccountNumber',
      account_number PATH '$.accountNumber',
      business_unit_id PATH '$.businessUnitId')
      ) static_data 
      ON ( static_data.parent_account_number = tab_data.parent_account_number 
           AND static_data.account_number = tab_data.account_number                
           AND static_data.business_unit_id = tab_data.business_unit_id ) 
        GROUP BY 
            tab_data.business_unit_id, 
            tab_data.parent_account_number, 
            tab_data.account_number 
    );
```

若要將資料列層級資料轉換為 JSON 格式，Oracle 具有內建函數，例如 `JSON_OBJECT`、`JSON_OBJECTAGG`、 `JSON_ARRAY`和 `JSON_ARRAYAGG`。
+ `JSON_OBJECT` 接受兩個參數： `KEY`和 `VALUE`。參數`KEY`本質上應為硬式編碼或靜態。`VALUE` 參數衍生自資料表輸出。
+ `JSON_ARRAYAGG` 接受 `JSON_OBJECT` 做為參數。這有助於將一組`JSON_OBJECT`元素分組為清單。例如，如果您的 `JSON_OBJECT` 元素有多個記錄 （資料集中的多個 `KEY`和 `VALUE`對）， 會`JSON_ARRAYAGG`附加資料集並建立清單。根據資料結構語言， `LIST`是元素群組。在此內容中， `LIST`是一組`JSON_OBJECT`元素。

下列範例顯示一個 `JSON_OBJECT` 元素。

```
{
   "taxProfessionalCount": 0,
   "attorneyCount": 0,
   "nonAttorneyCount": 1,
   "clerkCount": 0
}
```

下一個範例顯示兩個`JSON_OBJECT`元素，以方括號 () `LIST`表示`[ ]`。

```
[ 
    {
        "taxProfessionalCount": 0,
        "attorneyCount": 0,
        "nonAttorneyCount": 1,
        "clerkCount": 0
      }
,
    {
        "taxProfessionalCount": 2,
        "attorneyCount": 1,
        "nonAttorneyCount": 3,
        "clerkCount":4
      }
]
```

*SQL 查詢範例*

```
SELECT 
    JSON_OBJECT( 
        'accountCounts' VALUE JSON_ARRAYAGG( 
            JSON_OBJECT( 
                'businessUnitId' VALUE business_unit_id, 
                        'parentAccountNumber' VALUE parent_account_number, 
                        'accountNumber' VALUE account_number, 
                        'totalOnlineContactsCount' VALUE online_contacts_count, 
                        'countByPosition' VALUE 
                    JSON_OBJECT( 
                        'taxProfessionalCount' VALUE tax_count, 
                        'attorneyCount' VALUE attorney_count, 
                        'nonAttorneyCount' VALUE non_attorney_count, 
                        'clerkCount' VALUE clerk_count
                               ) 
                        ) 
                                           ) 
              ) 
FROM 
    (SELECT 
            tab_data.business_unit_id, 
            tab_data.parent_account_number, 
            tab_data.account_number, 
            SUM(1) online_contacts_count, 
            SUM(CASE WHEN tab_data.position_id = '0095' THEN  1 ELSE   0 END 
            )      tax_count, 
            SUM(CASE    WHEN tab_data.position_id = '0100' THEN        1    ELSE        0 END 
            )      attorney_count,                                                       
            SUM(CASE    WHEN tab_data.position_id = '0090' THEN        1    ELSE        0 END 
            )      non_attorney_count,                                                   
            SUM(CASE    WHEN tab_data.position_id = '0050' THEN        1    ELSE        0 END 
            )      clerk_count                                                           
        FROM 
            aws_test_table scco,  JSON_TABLE ( json_doc, '$' ERROR ON ERROR    
            COLUMNS ( 
            parent_account_number NUMBER PATH '$.data.account.parentAccountNumber',
            account_number NUMBER PATH '$.data.account.accountNumber',
            business_unit_id NUMBER PATH '$.data.account.businessUnitId',
            position_id VARCHAR2 ( 4 ) PATH '$.data.positionId'    )
            ) AS tab_data 
            INNER JOIN JSON_TABLE ( '{ 
        "accounts": [{ 
          "accountNumber": 42000, 
          "parentAccountNumber": 32000, 
          "businessUnitId": 7 
        }, { 
          "accountNumber": 42001, 
          "parentAccountNumber": 32001, 
          "businessUnitId": 6 
        }] 
      }', '$.accounts[*]' ERROR ON ERROR    
      COLUMNS (
      parent_account_number PATH '$.parentAccountNumber',
      account_number PATH '$.accountNumber',
      business_unit_id PATH '$.businessUnitId')
      ) static_data ON ( static_data.parent_account_number = tab_data.parent_account_number 
                         AND static_data.account_number = tab_data.account_number                
                         AND static_data.business_unit_id = tab_data.business_unit_id ) 
        GROUP BY 
            tab_data.business_unit_id, 
            tab_data.parent_account_number, 
            tab_data.account_number 
    );
```

*上一個 SQL 查詢的範例輸出*

```
{
  "accountCounts": [
    {
      "businessUnitId": 6,
      "parentAccountNumber": 32001,
      "accountNumber": 42001,
      "totalOnlineContactsCount": 1,
      "countByPosition": {
        "taxProfessionalCount": 0,
        "attorneyCount": 0,
        "nonAttorneyCount": 1,
        "clerkCount": 0
      }
    },
    {
      "businessUnitId": 7,
      "parentAccountNumber": 32000,
      "accountNumber": 42000,
      "totalOnlineContactsCount": 1,
      "countByPosition": {
        "taxProfessionalCount": 0,
        "attorneyCount": 1,
        "nonAttorneyCount": 0,
        "clerkCount": 0
      }
    }
  ]
}
```

**6.  Postgres\$1SQL\$1JSON\$1Aggregation\$1Join**

PostgreSQL 內建函數，`JSON_BUILD_OBJECT`並將 ROW 層級資料`JSON_AGG`轉換為 JSON 格式。 PostgreSQL `JSON_BUILD_OBJECT`和 `JSON_AGG` 相當於 Oracle `JSON_OBJECT`和 `JSON_ARRAYAGG`。

*查詢範例*

```
select    
JSON_BUILD_OBJECT ('accountCounts', 
    JSON_AGG( 
        JSON_BUILD_OBJECT ('businessUnitId',businessUnitId 
        ,'parentAccountNumber',parentAccountNumber 
        ,'accountNumber',accountNumber 
        ,'totalOnlineContactsCount',online_contacts_count, 
        'countByPosition',
            JSON_BUILD_OBJECT (
            'taxProfessionalCount',tax_professional_count 
            ,'attorneyCount',attorney_count 
            ,'nonAttorneyCount',non_attorney_count 
            ,'clerkCount',clerk_count 
            ) 
        )  
    ) 
) 
from ( 
with tab as (select * from ( 
select (json_doc::json->'data'->'account'->>'parentAccountNumber')::INTEGER as parentAccountNumber, 
(json_doc::json->'data'->'account'->>'accountNumber')::INTEGER as accountNumber, 
(json_doc::json->'data'->'account'->>'businessUnitId')::INTEGER as businessUnitId, 
(json_doc::json->'data'->>'positionId')::varchar as positionId 
from aws_test_pg_table) a ) , 
tab1 as ( select   
(json_array_elements(b.jc -> 'accounts') ->> 'accountNumber')::integer accountNumber, 
(json_array_elements(b.jc -> 'accounts') ->> 'businessUnitId')::integer businessUnitId, 
(json_array_elements(b.jc -> 'accounts') ->> 'parentAccountNumber')::integer parentAccountNumber 
from ( 
select '{ 
        "accounts": [{ 
          "accountNumber": 42001, 
          "parentAccountNumber": 32001, 
          "businessUnitId": 6 
        }, { 
          "accountNumber": 42000, 
          "parentAccountNumber": 32000, 
          "businessUnitId": 7 
        }] 
      }'::json as jc) b) 
select  
tab.businessUnitId::text, 
tab.parentAccountNumber::text, 
tab.accountNumber::text, 
SUM(1) online_contacts_count, 
SUM(CASE WHEN tab.positionId::text = '0095' THEN 1 ELSE 0  END)      tax_professional_count,  
SUM(CASE WHEN tab.positionId::text = '0100' THEN 1 ELSE 0  END)      attorney_count, 
SUM(CASE  WHEN tab.positionId::text = '0090' THEN      1  ELSE      0 END)      non_attorney_count, 
SUM(CASE  WHEN tab.positionId::text = '0050' THEN      1  ELSE      0 END)      clerk_count
from tab1,tab  
where tab.parentAccountNumber::INTEGER=tab1.parentAccountNumber::INTEGER  
and tab.accountNumber::INTEGER=tab1.accountNumber::INTEGER 
and tab.businessUnitId::INTEGER=tab1.businessUnitId::INTEGER 
GROUP BY      tab.businessUnitId::text, 
            tab.parentAccountNumber::text, 
            tab.accountNumber::text) a;
```

*上述查詢的範例輸出*

Oracle 和 PostgreSQL 的輸出完全相同。

```
{
  "accountCounts": [
    {
      "businessUnitId": 6,
      "parentAccountNumber": 32001,
      "accountNumber": 42001,
      "totalOnlineContactsCount": 1,
      "countByPosition": {
        "taxProfessionalCount": 0,
        "attorneyCount": 0,
        "nonAttorneyCount": 1,
        "clerkCount": 0
      }
    },
    {
      "businessUnitId": 7,
      "parentAccountNumber": 32000,
      "accountNumber": 42000,
      "totalOnlineContactsCount": 1,
      "countByPosition": {
        "taxProfessionalCount": 0,
        "attorneyCount": 1,
        "nonAttorneyCount": 0,
        "clerkCount": 0
      }
    }
  ]
}
```

**7.Oracle\$1procedure\$1with\$1JSON\$1Query**

此程式碼會將 Oracle 程序轉換為具有 JSON SQL 查詢的 PostgreSQL 函數。它顯示查詢如何將 JSON 轉換為資料列和反向。

```
CREATE OR REPLACE PROCEDURE p_json_test(p_in_accounts_json IN varchar2,   p_out_accunts_json  OUT varchar2)
IS
BEGIN
/*
p_in_accounts_json paramter should have following format:
       { 
        "accounts": [{ 
          "accountNumber": 42000, 
          "parentAccountNumber": 32000, 
          "businessUnitId": 7 
        }, { 
          "accountNumber": 42001, 
          "parentAccountNumber": 32001, 
          "businessUnitId": 6 
        }] 
      }
*/
SELECT 
    JSON_OBJECT( 
        'accountCounts' VALUE JSON_ARRAYAGG( 
            JSON_OBJECT( 
                'businessUnitId' VALUE business_unit_id, 
                        'parentAccountNumber' VALUE parent_account_number, 
                        'accountNumber' VALUE account_number, 
                        'totalOnlineContactsCount' VALUE online_contacts_count, 
                        'countByPosition' VALUE 
                    JSON_OBJECT( 
                        'taxProfessionalCount' VALUE tax_count, 
                        'attorneyCount' VALUE attorney_count, 
                        'nonAttorneyCount' VALUE non_attorney_count, 
                        'clerkCount' VALUE clerk_count
                               ) ) ) ) 
into p_out_accunts_json
FROM 
    (SELECT 
            tab_data.business_unit_id, 
            tab_data.parent_account_number, 
            tab_data.account_number, 
            SUM(1) online_contacts_count, 
            SUM(CASE WHEN tab_data.position_id = '0095' THEN  1 ELSE 0 END) tax_count, 
            SUM(CASE    WHEN tab_data.position_id = '0100' THEN 1 ELSE 0 END) attorney_count,                                                       
            SUM(CASE    WHEN tab_data.position_id = '0090' THEN 1 ELSE 0 END) non_attorney_count,                                                   
            SUM(CASE    WHEN tab_data.position_id = '0050' THEN 1 ELSE 0 END) clerk_count                                                           
        FROM aws_test_table scco,JSON_TABLE ( json_doc, '$' ERROR ON ERROR    
            COLUMNS ( 
            parent_account_number NUMBER PATH '$.data.account.parentAccountNumber',
            account_number NUMBER PATH '$.data.account.accountNumber',
            business_unit_id NUMBER PATH '$.data.account.businessUnitId',
            position_id VARCHAR2 ( 4 ) PATH '$.data.positionId'    )
            ) AS tab_data 
            INNER JOIN JSON_TABLE ( p_in_accounts_json, '$.accounts[*]' ERROR ON ERROR    
      COLUMNS (
      parent_account_number PATH '$.parentAccountNumber',
      account_number PATH '$.accountNumber',
      business_unit_id PATH '$.businessUnitId')
      ) static_data 
      ON ( static_data.parent_account_number = tab_data.parent_account_number 
           AND static_data.account_number = tab_data.account_number                
           AND static_data.business_unit_id = tab_data.business_unit_id ) 
        GROUP BY 
            tab_data.business_unit_id, 
            tab_data.parent_account_number, 
            tab_data.account_number 
    ); 
EXCEPTION 
WHEN OTHERS THEN
   raise_application_error(-20001,'Error while running the JSON query');
END;
/
```

*執行程序*

下列程式碼區塊說明如何使用程序的範例 JSON 輸入來執行先前建立的 Oracle 程序。它也會提供您此程序的結果或輸出。

```
set serveroutput on;
declare
v_out varchar2(30000);
v_in varchar2(30000):= '{ 
        "accounts": [{ 
          "accountNumber": 42000, 
          "parentAccountNumber": 32000, 
          "businessUnitId": 7 
        }, { 
          "accountNumber": 42001, 
          "parentAccountNumber": 32001, 
          "businessUnitId": 6 
        }] 
      }';
begin
  p_json_test(v_in,v_out);
  dbms_output.put_line(v_out);
end;
/
```

*程序輸出*

```
{
  "accountCounts": [
    {
      "businessUnitId": 6,
      "parentAccountNumber": 32001,
      "accountNumber": 42001,
      "totalOnlineContactsCount": 1,
      "countByPosition": {
        "taxProfessionalCount": 0,
        "attorneyCount": 0,
        "nonAttorneyCount": 1,
        "clerkCount": 0
      }
    },
    {
      "businessUnitId": 7,
      "parentAccountNumber": 32000,
      "accountNumber": 42000,
      "totalOnlineContactsCount": 1,
      "countByPosition": {
        "taxProfessionalCount": 0,
        "attorneyCount": 1,
        "nonAttorneyCount": 0,
        "clerkCount": 0
      }
    }
  ]
}
```

**8.Postgres\$1function\$1with\$1JSON\$1Query**

*範例函數*

```
CREATE OR REPLACE  FUNCTION f_pg_json_test(p_in_accounts_json  text)
RETURNS text  
LANGUAGE plpgsql  
AS  
$$  
DECLARE  
 v_out_accunts_json   text;  
BEGIN  
SELECT    
JSON_BUILD_OBJECT ('accountCounts',
    JSON_AGG(
        JSON_BUILD_OBJECT ('businessUnitId',businessUnitId
        ,'parentAccountNumber',parentAccountNumber
        ,'accountNumber',accountNumber
        ,'totalOnlineContactsCount',online_contacts_count,
        'countByPosition',
            JSON_BUILD_OBJECT (
            'taxProfessionalCount',tax_professional_count
            ,'attorneyCount',attorney_count
            ,'nonAttorneyCount',non_attorney_count
            ,'clerkCount',clerk_count
            ))))
INTO v_out_accunts_json
FROM (
WITH tab AS (SELECT * FROM (
SELECT (json_doc::json->'data'->'account'->>'parentAccountNumber')::INTEGER AS parentAccountNumber,
(json_doc::json->'data'->'account'->>'accountNumber')::INTEGER AS accountNumber,
(json_doc::json->'data'->'account'->>'businessUnitId')::INTEGER AS businessUnitId,
(json_doc::json->'data'->>'positionId')::varchar AS positionId
FROM aws_test_pg_table) a ) ,
tab1 AS ( SELECT  
(json_array_elements(b.jc -> 'accounts') ->> 'accountNumber')::integer accountNumber,
(json_array_elements(b.jc -> 'accounts') ->> 'businessUnitId')::integer businessUnitId,
(json_array_elements(b.jc -> 'accounts') ->> 'parentAccountNumber')::integer parentAccountNumber
FROM (
SELECT p_in_accounts_json::json AS jc) b)
SELECT  
tab.businessUnitId::text,
tab.parentAccountNumber::text,
tab.accountNumber::text,
SUM(1) online_contacts_count,
SUM(CASE WHEN tab.positionId::text = '0095' THEN 1 ELSE 0  END)      tax_professional_count,  
SUM(CASE WHEN tab.positionId::text = '0100' THEN 1 ELSE 0  END)      attorney_count,
SUM(CASE  WHEN tab.positionId::text = '0090' THEN      1  ELSE      0 END)      non_attorney_count,
SUM(CASE  WHEN tab.positionId::text = '0050' THEN      1  ELSE      0 END)      clerk_count
FROM tab1,tab  
WHERE tab.parentAccountNumber::INTEGER=tab1.parentAccountNumber::INTEGER  
AND tab.accountNumber::INTEGER=tab1.accountNumber::INTEGER
AND tab.businessUnitId::INTEGER=tab1.businessUnitId::INTEGER
GROUP BY      tab.businessUnitId::text,
            tab.parentAccountNumber::text,
            tab.accountNumber::text) a;
RETURN v_out_accunts_json;          
END;  
$$;
```

*執行 函數*

```
select    f_pg_json_test('{ 
        "accounts": [{ 
          "accountNumber": 42001, 
          "parentAccountNumber": 32001, 
          "businessUnitId": 6 
        }, { 
          "accountNumber": 42000, 
          "parentAccountNumber": 32000, 
          "businessUnitId": 7 
        }] 
      }')   ;
```

*函數輸出 *

下列輸出類似於 Oracle 程序輸出。差別在於此輸出為文字格式。

```
{
  "accountCounts": [
    {
      "businessUnitId": "6",
      "parentAccountNumber": "32001",
      "accountNumber": "42001",
      "totalOnlineContactsCount": 1,
      "countByPosition": {
        "taxProfessionalCount": 0,
        "attorneyCount": 0,
        "nonAttorneyCount": 1,
        "clerkCount": 0
      }
    },
    {
      "businessUnitId": "7",
      "parentAccountNumber": "32000",
      "accountNumber": "42000",
      "totalOnlineContactsCount": 1,
      "countByPosition": {
        "taxProfessionalCount": 0,
        "attorneyCount": 1,
        "nonAttorneyCount": 0,
        "clerkCount": 0
      }
    }
  ]
}
```

# 使用 跨帳戶複製 Amazon DynamoDB 資料表 AWS Backup
<a name="copy-amazon-dynamodb-tables-across-accounts-using-aws-backup"></a>

*Ramkumar Ramanujam，Amazon Web Services*

## 總結
<a name="copy-amazon-dynamodb-tables-across-accounts-using-aws-backup-summary"></a>

在 上使用 Amazon DynamoDB 時 AWS，常見的使用案例是將開發、測試或預備環境中的 DynamoDB 資料表與生產環境中的資料表資料進行複製或同步。根據標準實務，每個環境都使用不同的 AWS 帳戶。 

AWS Backup 支援跨區域和跨帳戶備份和還原 DynamoDB、Amazon Simple Storage Service (Amazon S3) 和其他 的資料 AWS 服務。此模式提供使用 AWS Backup 跨帳戶備份和還原來複製 DynamoDB 資料表的步驟 AWS 帳戶。

## 先決條件和限制
<a name="copy-amazon-dynamodb-tables-across-accounts-using-aws-backup-prereqs"></a>

**先決條件**
+ 在 中 AWS 帳戶 屬於相同組織的兩個作用中 AWS Organizations
+ 在兩個帳戶中建立 DynamoDB 資料表的許可
+ AWS Identity and Access Management 建立和使用保存庫的 (IAM) AWS Backup 許可

**限制**
+ 來源和目標 AWS 帳戶 應該是 中相同組織的一部分 AWS Organizations。

## Architecture
<a name="copy-amazon-dynamodb-tables-across-accounts-using-aws-backup-architecture"></a>

**目標技術堆疊**
+ AWS Backup 
+ Amazon DynamoDB

**目標架構**

![\[在備份保存庫之間複製資料表的說明如下圖所示。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/ef6e7393-edb6-4744-be26-43f1cbff9de9/images/fa9f3f2f-7a01-4093-9bd5-fc355e57ba67.png)


1. 在來源帳戶中的備份文件庫中建立 DynamoDB 資料表 AWS Backup 備份。

1. 將備份複製到目標帳戶中的備份保存庫。

1. 使用目標帳戶中備份文件庫的備份來還原目標帳戶中的 DynamoDB 資料表。

**自動化和擴展**

您可以使用 AWS Backup 來排程以特定間隔執行備份。

## 工具
<a name="copy-amazon-dynamodb-tables-across-accounts-using-aws-backup-tools"></a>
+ [AWS Backup](https://docs.aws.amazon.com/aws-backup/latest/devguide/whatisbackup.html) 是一種全受管服務，可集中和自動化跨雲端、雲端和內部部署 AWS 服務的資料保護。使用此服務，您可以在 AWS 單一位置設定資源的備份政策並監控活動。它可讓您自動化和合併先前由 服務執行的備份任務，並不需要建立自訂指令碼和手動程序。
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) 是全受管的 NoSQL 資料庫服務，可提供快速且可預測的效能和無縫的可擴展性。

## 史詩
<a name="copy-amazon-dynamodb-tables-across-accounts-using-aws-backup-epics"></a>

### 開啟來源和目標帳戶中 AWS Backup 的功能
<a name="turn-on-bkp-features-in-the-source-and-target-accounts"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 開啟 DynamoDB 和跨帳戶備份的進階功能。 | 在來源和目標中 AWS 帳戶，執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-amazon-dynamodb-tables-across-accounts-using-aws-backup.html) | AWS DevOps，遷移工程師 | 

### 在來源和目標帳戶中建立備份保存庫
<a name="create-backup-vaults-in-the-source-and-target-accounts"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立備份保存庫。 | 在來源和目標中 AWS 帳戶，執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-amazon-dynamodb-tables-across-accounts-using-aws-backup.html)當您在來源和目標帳戶之間複製 DynamoDB 資料表備份時，將需要來源和目標備份文件庫的 ARNs。 | AWS DevOps，遷移工程師 | 

### 使用備份保存庫執行備份和還原
<a name="perform-backup-and-restore-using-backup-vaults"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在來源帳戶中，建立 DynamoDB 資料表備份。 | 若要為來源帳戶中的 DynamoDB 資料表建立備份，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-amazon-dynamodb-tables-across-accounts-using-aws-backup.html)建立新的備份任務。 若要監控備份任務的狀態，請在 AWS Backup **任務**頁面上，選擇**備份任務**索引標籤。所有作用中、進行中和已完成的備份任務都會列在此索引標籤上。 | AWS DevOps、DBA、遷移工程師 | 
| 將備份從來源帳戶複製到目標帳戶。 | 備份任務完成後，將 DynamoDB 資料表備份從來源帳戶中的備份保存庫複製到目標帳戶中的備份保存庫。若要複製備份保存庫，請在來源帳戶中執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-amazon-dynamodb-tables-across-accounts-using-aws-backup.html) | AWS DevOps，遷移工程師，DBA | 
| 還原目標帳戶中的備份。 | 在目標中 AWS 帳戶，執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-amazon-dynamodb-tables-across-accounts-using-aws-backup.html) | AWS DevOps、DBA、遷移工程師 | 

## 相關資源
<a name="copy-amazon-dynamodb-tables-across-accounts-using-aws-backup-resources"></a>
+ [AWS Backup 搭配 DynamoDB 使用](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/backuprestore_HowItWorksAWS.html)
+ [跨 建立備份複本 AWS 帳戶](https://docs.aws.amazon.com/aws-backup/latest/devguide/create-cross-account-backup.html)
+ [AWS Backup 定價](https://aws.amazon.com/backup/pricing/)

# 使用自訂實作跨帳戶複製 Amazon DynamoDB 資料表
<a name="copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation"></a>

*Ramkumar Ramanujam，Amazon Web Services*

## 總結
<a name="copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation-summary"></a>

在 Amazon Web Services (AWS) 上使用 Amazon DynamoDB 時，常見的使用案例是將開發、測試或預備環境中的 DynamoDB 資料表與生產環境中的資料表資料進行複製或同步。根據標準實務，每個環境都使用不同的 AWS 帳戶。

DynamoDB 現在支援使用 AWS Backup 的跨帳戶備份。如需使用 AWS Backup 時相關儲存成本的資訊，請參閱 [AWS Backup 定價](https://aws.amazon.com/backup/pricing/)。當您使用 AWS Backup 跨帳戶複製時，來源和目標帳戶必須是 AWS Organizations 組織的一部分。還有其他使用 AWS Glue 等 AWS 服務進行跨帳戶備份和還原的解決方案。不過，使用這些解決方案會增加應用程式足跡，因為要部署和維護的 AWS 服務更多。 

您也可以使用 Amazon DynamoDB Streams 擷取來源帳戶中的資料表變更。然後，您可以啟動 AWS Lambda 函數，並在目標帳戶中的目標資料表中進行對應的變更。但是，該解決方案適用於來源和目標資料表必須保持同步的使用案例。它可能不適用於頻繁更新資料的開發、測試和預備環境。

此模式提供實作自訂解決方案的步驟，將 Amazon DynamoDB 資料表從一個帳戶複製到另一個帳戶。此模式可以使用常見的程式設計語言實作，例如 C\$1、Java 和 Python。建議使用 [AWS 開發套件](https://aws.amazon.com/tools/)支援的語言。

## 先決條件和限制
<a name="copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation-prereqs"></a>

**先決條件**
+ 兩個作用中的 AWS 帳戶
+ 兩個帳戶中的 DynamoDB 資料表
+ 了解 AWS Identity and Access Management (IAM) 角色和政策
+ 了解如何使用任何常見的程式設計語言存取 Amazon DynamoDB 資料表，例如 C\$1、Java 或 Python

**限制**

此模式適用於大約 2 GB 或更小的 DynamoDB 資料表。透過額外的邏輯來處理連線或工作階段中斷、限流、故障和重試，它可用於較大的資料表。

DynamoDB 掃描操作會從來源資料表讀取項目，在單一呼叫中最多只能擷取 1 MB 的資料。對於大於 2 GB 的較大資料表，此限制可能會增加執行完整資料表複本的總時間。

## Architecture
<a name="copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation-architecture"></a>

下圖顯示來源和目標 AWS 帳戶之間的自訂實作。IAM 政策和安全字符會與自訂實作搭配使用。從來源帳戶中的 Amazon DynamoDB 讀取資料，並寫入目標帳戶中的 DynamoDB。

![\[使用自訂實作複製的來源和目標帳戶架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/ba8175be-9809-4c2e-b2d1-6b9180ed056c/images/d9d4c2c8-ff04-443f-9137-e37b8e23ccb5.png)


 

**自動化和擴展**

此模式適用於大小較小的 DynamoDB 資料表，約為 2 GB。 

若要將此模式套用至較大的資料表，請解決下列問題：
+ 在資料表複製操作期間，會使用不同的安全字符來維護兩個作用中工作階段。如果資料表複製操作花費的時間超過字符過期時間，您必須設定邏輯來重新整理安全字符。 
+ 如果未佈建足夠的讀取容量單位 RCUs) 和寫入容量單位 WCUs)，則來源或目標資料表上的讀取或寫入可能會受到調節。請務必擷取並處理這些例外狀況。 
+ 處理任何其他失敗或例外狀況，並設定重試機制，以便在複製操作失敗時重試或繼續。

## 工具
<a name="copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation-tools"></a>

**工具**
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) – Amazon DynamoDB 是全受管的 NoSQL 資料庫服務，可提供快速且可預測的效能和無縫的可擴展性。 
+ 所需的其他工具會根據您為實作選擇的程式設計語言而有所不同。例如，如果您使用 C\$1，您將需要 Microsoft Visual Studio 和下列 NuGet 套件：
  + `AWSSDK`
  + `AWSSDK.DynamoDBv2`

**Code**

下列 Python 程式碼片段會使用 Boto3 程式庫刪除並重新建立 DynamoDB 資料表。

請勿使用 `AWS_SECRET_ACCESS_KEY` IAM 使用者的 `AWS_ACCESS_KEY_ID`和 ，因為這些是長期登入資料，因此應該避免以程式設計方式存取 AWS 服務。如需暫時登入資料的詳細資訊，請參閱*最佳實務*一節。

下列程式碼片段`TEMPORARY_SESSION_TOKEN`中使用的 `AWS_ACCESS_KEY_ID``AWS_SECRET_ACCESS_KEY`、 和 是從 AWS Security Token Service (AWS STS) 擷取的暫時登入資料。

```
import boto3
import sys
import json

#args = input-parameters = GLOBAL_SEC_INDEXES_JSON_COLLECTION, ATTRIBUTES_JSON_COLLECTION, TARGET_DYNAMODB_NAME, TARGET_REGION, ...

#Input param: GLOBAL_SEC_INDEXES_JSON_COLLECTION
#[{"IndexName":"Test-index","KeySchema":[{"AttributeName":"AppId","KeyType":"HASH"},{"AttributeName":"AppType","KeyType":"RANGE"}],"Projection":{"ProjectionType":"INCLUDE","NonKeyAttributes":["PK","SK","OwnerName","AppVersion"]}}]

#Input param: ATTRIBUTES_JSON_COLLECTION
#[{"AttributeName":"PK","AttributeType":"S"},{"AttributeName":"SK","AttributeType":"S"},{"AttributeName":"AppId","AttributeType":"S"},{"AttributeName":"AppType","AttributeType":"N"}]

region = args['TARGET_REGION']
target_ddb_name = args['TARGET_DYNAMODB_NAME']

global_secondary_indexes = json.loads(args['GLOBAL_SEC_INDEXES_JSON_COLLECTION'])
attribute_definitions = json.loads(args['ATTRIBUTES_JSON_COLLECTION'])

# Drop and create target DynamoDB table
dynamodb_client = boto3.Session(
        aws_access_key_id=args['AWS_ACCESS_KEY_ID'],
        aws_secret_access_key=args['AWS_SECRET_ACCESS_KEY'],
        aws_session_token=args['TEMPORARY_SESSION_TOKEN'],
    ).client('dynamodb')
    
# Delete table
print('Deleting table: ' + target_ddb_name + ' ...')

try:
    dynamodb_client.delete_table(TableName=target_ddb_name)

    #Wait for table deletion to complete
    waiter = dynamodb_client.get_waiter('table_not_exists')
    waiter.wait(TableName=target_ddb_name)
    print('Table deleted.')
except dynamodb_client.exceptions.ResourceNotFoundException:
    print('Table already deleted / does not exist.')
    pass

print('Creating table: ' + target_ddb_name + ' ...')

table = dynamodb_client.create_table(
    TableName=target_ddb_name,
    KeySchema=[
        {
            'AttributeName': 'PK',
            'KeyType': 'HASH'  # Partition key
        },
        {
            'AttributeName': 'SK',
            'KeyType': 'RANGE'  # Sort key
        }
    ],
    AttributeDefinitions=attribute_definitions,
    GlobalSecondaryIndexes=global_secondary_indexes,
    BillingMode='PAY_PER_REQUEST'
)
    
waiter = dynamodb_client.get_waiter('table_exists')
waiter.wait(TableName=target_ddb_name)
    
print('Table created.')
```

## 最佳實務
<a name="copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation-best-practices"></a>

**臨時憑證**

作為安全最佳實務，以程式設計方式存取 AWS 服務時，請避免使用 `AWS_SECRET_ACCESS_KEY` IAM 使用者的 `AWS_ACCESS_KEY_ID`和 ，因為這些是長期憑證。一律嘗試使用臨時登入資料，以程式設計方式存取 AWS 服務。

例如，開發人員會在開發期間硬式編碼應用程式中 `AWS_SECRET_ACCESS_KEY` IAM 使用者的 `AWS_ACCESS_KEY_ID`和 ，但無法在將變更推送至程式碼儲存庫之前移除硬式編碼值。這些公開的登入資料可供非預期或惡意使用者使用，這可能會產生嚴重影響 （特別是當公開的登入資料具有管理員權限時）。這些公開的登入資料應該使用 IAM 主控台或 AWS Command Line Interface (AWS CLI) 立即停用或刪除。

若要取得以程式設計方式存取 AWS 服務的臨時登入資料，請使用 AWS STS。暫時登入資料僅在指定的時間內有效 （從 15 分鐘到 36 小時）。臨時登入資料的允許持續時間上限會根據角色設定和角色鏈結等因素而有所不同。如需 AWS STS 的詳細資訊，請參閱 [文件](https://docs.aws.amazon.com/STS/latest/APIReference/welcome.html)。

## 史詩
<a name="copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation-epics"></a>

### 設定 DynamoDB 資料表
<a name="set-up-dynamodb-tables"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 DynamoDB 資料表。 | 在來源和目標 AWS 帳戶中建立具有索引的 DynamoDB 資料表。將容量佈建設定為隨需模式，這可讓 DynamoDB 根據工作負載動態擴展讀取/寫入容量。 或者，您可以使用佈建容量搭配 4000 RCUs 和 4000 WCUs。 | 應用程式開發人員、DBA、遷移工程師 | 
| 填入來源資料表。 | 使用測試資料填入來源帳戶中的 DynamoDB 資料表。擁有至少 50 MB 或更多的測試資料可協助您查看資料表複製期間消耗的峰值和平均 RCUs。然後，您可以視需要變更容量佈建。 | 應用程式開發人員、DBA、遷移工程師 | 

### 設定登入資料以存取 DynamoDB 資料表
<a name="set-up-credentials-to-access-the-dynamodb-tables"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 IAM 角色以存取來源和目標 DynamoDB 資料表。 | 在來源帳戶中建立具有存取 （讀取） 來源帳戶中 DynamoDB 資料表許可的 IAM 角色。新增來源帳戶做為此角色的信任實體。在目標帳戶中建立具有存取 （建立、讀取、更新、刪除） 目標帳戶中 DynamoDB 資料表許可的 IAM 角色。 新增目標帳戶做為此角色的信任實體。 | 應用程式開發人員、AWS DevOps | 

### 將資料表資料從一個帳戶複製到另一個帳戶
<a name="copy-table-data-from-one-account-to-another"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 取得 IAM 角色的臨時登入資料。 | 取得來源帳戶中建立之 IAM 角色的臨時登入資料。取得在目標帳戶中建立之 IAM 角色的臨時登入資料。取得 IAM 角色臨時登入資料的一種方法是從 AWS CLI 使用 AWS STS。<pre>aws sts assume-role --role-arn arn:aws:iam::<account-id>:role/<role-name> --role-session-name <session-name> --profile <profile-name></pre>使用適當的 AWS 設定檔 （對應至來源或目標帳戶）。如需取得臨時登入資料之不同方式的詳細資訊，請參閱下列內容：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation.html) | 應用程式開發人員、遷移工程師 | 
| 初始化來源和目標 DynamoDB 存取的 DynamoDB 用戶端。 | 針對來源和目標 DynamoDB 資料表初始化 AWS 開發套件提供的 DynamoDB 用戶端。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation.html)如需使用 IAM 臨時登入資料提出請求的詳細資訊，請參閱 [AWS 文件](https://docs.aws.amazon.com/AmazonS3/latest/userguide/AuthUsingTempSessionToken.html)。 | 應用程式開發人員 | 
| 捨棄並重新建立目標資料表。 | 使用目標帳戶 DynamoDB 用戶端，在目標帳戶中刪除並重新建立目標 DynamoDB 資料表 （以及索引）。從 DynamoDB 資料表刪除所有記錄是一項昂貴的操作，因為它會使用佈建WCUs。刪除和重新建立資料表可避免這些額外費用。您可以在建立索引後將索引新增至資料表，但這需要 2-5 分鐘的時間。透過將索引集合傳遞至`createTable`呼叫，在資料表建立期間建立索引更有效率。 | 應用程式開發人員 | 
| 執行資料表複製。 | 重複下列步驟，直到複製所有資料：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation.html)如需詳細資訊，請參閱*附件*區段中的 C\$1 中的參考實作 （適用於捨棄、建立和填入資料表）。也會連接範例資料表組態 JavaScript 物件標記法 (JSON) 檔案。 | 應用程式開發人員 | 

## 相關資源
<a name="copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation-resources"></a>
+ [Amazon DynamoDB 文件](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html)
+ [在 AWS 帳戶中建立 IAM 使用者](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html)
+ [AWS 開發套件](https://aws.amazon.com/tools/)
+ [搭配 AWS 資源使用臨時登入資料](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html)

## 其他資訊
<a name="copy-amazon-dynamodb-tables-across-accounts-using-a-custom-implementation-additional"></a>

此模式使用 C\$1 實作，以複製具有 200，000 個項目的 DynamoDB 資料表 （平均項目大小為 5 KB，資料表大小為 250 MB)。目標 DynamoDB 資料表的設定佈建容量為 4000 RCUs 和 4000 WCUs。

完整的資料表複製操作 （從來源帳戶到目標帳戶），包括捨棄和重新建立資料表，需要 5 分鐘。使用的總容量單位：30，000 RCUs 和大約 400，000 WCUs。

如需 DynamoDB 容量模式的詳細資訊，請參閱 AWS 文件中的[讀取/寫入容量模式](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadWriteCapacityMode.html)。

## 附件
<a name="attachments-ba8175be-9809-4c2e-b2d1-6b9180ed056c"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/ba8175be-9809-4c2e-b2d1-6b9180ed056c/attachments/attachment.zip)

# 建立 Amazon RDS 和 Amazon Aurora 的詳細成本和用量報告
<a name="create-detailed-cost-and-usage-reports-for-amazon-rds-and-amazon-aurora"></a>

*Lakshmanan Lakshmanan 和 Sudarshan Narasimhan，Amazon Web Services*

## 總結
<a name="create-detailed-cost-and-usage-reports-for-amazon-rds-and-amazon-aurora-summary"></a>

此模式說明如何透過設定使用者定義的成本分配標籤來追蹤 Amazon Relational Database Service (Amazon RDS) 或 Amazon Aurora 叢集的使用成本。 [https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/custom-tags.html](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/custom-tags.html)您可以使用這些標籤，在 AWS Cost Explorer 中為多個維度的叢集建立詳細的成本和用量報告。例如，您可以在團隊、專案或成本中心層級追蹤用量成本，然後在 Amazon Athena 中分析資料。

## 先決條件和限制
<a name="create-detailed-cost-and-usage-reports-for-amazon-rds-and-amazon-aurora-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 一或多個 [Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateDBInstance.html) 或 [Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.CreateInstance.html) 執行個體

**限制**

如需標記限制，請參閱 [AWS Billing 使用者指南](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/allocation-tag-restrictions.html)。

## Architecture
<a name="create-detailed-cost-and-usage-reports-for-amazon-rds-and-amazon-aurora-architecture"></a>

**目標技術堆疊**
+ Amazon RDS 或 Amazon Aurora
+ AWS 成本和用量報告
+ AWS Cost Explorer
+ Amazon Athena

**工作流程和架構**

標記和分析工作流程包含下列步驟：

1. 資料工程師、資料庫管理員或 AWS 管理員會為 Amazon RDS 或 Aurora 叢集建立使用者定義的成本分配標籤。

1. AWS 管理員會啟用標籤。

1. 這些標籤會向 AWS Cost Explorer 報告中繼資料。

1. 資料工程師、資料庫管理員或 AWS 管理員會建立[每月成本分配報告](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/configurecostallocreport.html#allocation-viewing)。

1. 資料工程師、資料庫管理員或 AWS 管理員會使用 Amazon Athena 分析每月成本分配報告。

下圖顯示如何套用標籤來追蹤 Amazon RDS 或 Aurora 執行個體的使用成本。

 

![\[套用標籤以追蹤資料庫執行個體和叢集的使用成本\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/eab5001d-5115-4aa6-bdd2-23063b08b262/images/63292b18-01d6-4523-b8ac-2c3b12b11b84.png)


下列架構圖顯示成本分配報告如何與 Amazon Athena 整合以進行分析。

![\[在 Athena 中查詢成本分配報告\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/eab5001d-5115-4aa6-bdd2-23063b08b262/images/9c028405-1e93-4f6a-a0e5-36154e2b8eab.png)


每月成本分配報告會存放在您指定的 Amazon S3 儲存貯體中。當您使用 AWS CloudFormation 範本設定 Athena 時，如 *Epics* 一節所述，範本會為 Lambda 函數佈建數個額外的資源，包括 AWS Glue 爬蟲程式、AWS Glue 資料庫、Amazon Simple Notification System (Amazon SNS) 事件、AWS Lambda 函數，以及 AWS Identity and Access Management (IAM) 角色。當新的成本資料檔案送達 S3 儲存貯體時，事件通知會用來將這些檔案轉送至 Lambda 函數進行處理。Lambda 函數會啟動 AWS Glue 爬蟲程式任務，以在 AWS Glue Data Catalog 中建立或更新資料表。然後，此資料表用於查詢 Athena 中的資料。

 

## 工具
<a name="create-detailed-cost-and-usage-reports-for-amazon-rds-and-amazon-aurora-tools"></a>
+ [Amazon Athena](https://aws.amazon.com/athena/) 是一種互動式查詢服務，可讓您使用標準 SQL 輕鬆分析 Amazon S3 中的資料。
+ [Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html) 是一種全受管關聯式資料庫引擎，專為雲端而建置，並與 MySQL 和 PostgreSQL 相容。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。
+ [AWS CloudFormation](https://aws.amazon.com/cloudformation/) 是一種基礎設施即程式碼 (IaC) 服務，可讓您輕鬆地建立、佈建和管理 AWS 和第三方資源。
+ [AWS Cost Explorer](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/ce-what-is.html) 可協助您檢視和分析 AWS 成本和用量。

## 史詩
<a name="create-detailed-cost-and-usage-reports-for-amazon-rds-and-amazon-aurora-epics"></a>

### 為您的 Amazon RDS 或 Aurora 叢集建立和啟用標籤
<a name="create-and-activate-tags-for-your-amazon-rds-or-aurora-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為您的 Amazon RDS 或 Aurora 叢集建立使用者定義的成本分配標籤。 | 若要將標籤新增至新的或現有的 Amazon RDS 或 Aurora 叢集，請遵循 *Amazon Aurora 使用者指南*中的[新增、列出和移除標籤](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_Tagging.html#Tagging.HowTo)中的指示。如需有關如何設定 Amazon Aurora 叢集的資訊，請參閱《*Amazon Aurora 使用者指南*》中的 [MySQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_GettingStartedAurora.CreatingConnecting.Aurora.html) 和 [PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_GettingStartedAurora.CreatingConnecting.AuroraPostgreSQL.html) 的說明。 | AWS 管理員、資料工程師、DBA | 
| 啟用使用者定義的成本分配標籤。 | 遵循 *AWS Billing 使用者指南*中[啟用使用者定義的成本分配標籤](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/activating-tags.html)中的指示。 | AWS 管理員 | 

### 建立成本和用量報告
<a name="create-cost-and-usage-reports"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為您的叢集建立和設定成本和用量報告。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/create-detailed-cost-and-usage-reports-for-amazon-rds-and-amazon-aurora.html)資料將在 24 小時內提供。 | 應用程式擁有者、AWS 管理員、DBA、一般 AWS、資料工程師 | 

### 分析成本和用量報告資料
<a name="analyze-cost-and-usage-report-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 分析成本和用量報告資料。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/create-detailed-cost-and-usage-reports-for-amazon-rds-and-amazon-aurora.html)<pre>select status from cost_and_usage_data_status</pre>如需詳細資訊，請參閱[《AWS 成本和用量報告使用者指南》中的執行 Amazon Athena 查詢](https://docs.aws.amazon.com/cur/latest/userguide/cur-ate-run.html)。 **當您執行 SQL 查詢時，請確定已從下拉式清單中選取正確的資料庫。 | 應用程式擁有者、AWS 管理員、DBA、一般 AWS、資料工程師 | 

## 相關資源
<a name="create-detailed-cost-and-usage-reports-for-amazon-rds-and-amazon-aurora-resources"></a>

**參考**
+ [使用 AWS CloudFormation 範本設定 Athena ](https://docs.aws.amazon.com/cur/latest/userguide/use-athena-cf.html) （建議）
+ [手動設定 Athena](https://docs.aws.amazon.com/cur/latest/userguide/cur-ate-manual.html)
+ [執行 Amazon Athena 查詢](https://docs.aws.amazon.com/cur/latest/userguide/cur-ate-run.html)
+ [將報告資料載入其他資源](https://docs.aws.amazon.com/cur/latest/userguide/cur-query-other.html)

**教學課程和影片**
+ [使用 Amazon Athena 分析成本和用量報告 ](https://youtu.be/KEeJEZTYE8E)(YouTube 影片）

# 使用 Terraform 在 Amazon EC2 和 Amazon FSx 上部署 SQL Server 容錯移轉叢集執行個體
<a name="deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx"></a>

*Mark Hudson 和 Matt Burgess，Amazon Web Services*

## 總結
<a name="deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-summary"></a>

此模式使用 Terraform 在 Amazon Elastic Compute Cloud (Amazon EC2) 上的 Windows Server 容錯移轉叢集 (WSFC) 節點之間部署 SQL Server 容錯移轉叢集執行個體 (FCIs)。此外， 模式會使用 Amazon FSx 共用儲存來儲存資料和日誌檔案。

當 SQL Server 資料庫遷移至 時 AWS，第一個選擇是 Amazon RDS for SQL Server。不過，有時 Amazon RDS for SQL Server 不適合，而且 SQL Server 必須部署在高度可用的架構中的 Amazon EC2 上。在此解決方案中，SQL Server FCIs會跨 WSFC 節點安裝。

此模式隨附的 Terraform 模組最多可佈建兩個 Amazon EC2 SQL Server 執行個體。Amazon FSx for Windows File Server 檔案系統可做為仲裁見證，並存放共用的資料和日誌檔案。無論設定的執行個體數量為何，SQL Server 執行個體節點一律會建立並加入 FCI 叢集，以確保環境同位。（通常，一個執行個體設定為開發，兩個執行個體用於生產環境。) 對於使用兩個節點以獲得高可用性的組態，會佈建內部 Network Load Balancer。Network Load Balancer 使用 FCI 叢集上設定的運作狀態探查來識別哪個節點是主要節點。

## 先決條件和限制
<a name="deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。
+ 在個別可用區域中具有兩個子網路的 Amazon Virtual Private Cloud (Amazon VPC)。
+ Amazon VPC [DHCP 選項集](https://docs.aws.amazon.com/vpc/latest/userguide/DHCPOptionSet.html)。設定網域名稱以解析您的 Active Directory 網域名稱，以及網域和 NetBIOS 名稱伺服器以指向您的 Active Directory 網域控制站。如需詳細資訊，請參閱[其他資訊](#deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-additional)中的 *VPC 組態*。
+ AWS Directory Service for Microsoft Active Directory (AWS Managed Microsoft AD).
+ 自訂 Amazon Machine Image (AMI)。如需詳細資訊，請參閱[其他資訊](#deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-additional)中的 *AMI 組態*。
+ 包含 SQL Server ISO 映像的 Amazon Simple Storage Service (Amazon S3) 儲存貯體。只有在搭配提供的 `component.yaml` 檔案使用 [EC2 Image Builder](https://docs.aws.amazon.com/imagebuilder/latest/userguide/what-is-image-builder.html) 來建置自訂 AMI 時，才需要此先決條件。
+ AWS Key Management Service (AWS KMS) 加密金鑰。
+ 根據預設，SQL Server 是使用開發人員版本產品金鑰進行安裝。生產系統應該使用由相關變數傳遞給模組的有效產品金鑰。

**限制**
+ 此解決方案需要 AWS Managed Microsoft AD。不過，如果您願意，您可以改用自我管理 Active Directory 實作。若要這麼做，請修改包含的 Amazon FSx Terraform 模組以移除 `active_directory_id` 屬性。然後，新增自我管理 Active Directory 所需的四個屬性，如 [Terraform 文件](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/fsx_windows_file_system)所示。
+ SQL Server 設定為使用混合模式身分驗證。如果您願意，您可以使用僅限 Windows 的身分驗證。若要這樣做，請在提供的使用者資料指令碼中，移除提供給`setup.exe`命令的 `/SECURITYMODE`和 `/SAPWD` 參數。您可以移除`sql_accounts.tf`檔案，也可以修改`instances.tf`檔案以移除`sql_sa_password`項目。
+ 刪除部署的叢集時，您必須在 Active Directory 中移除對應的虛擬電腦物件和個別電腦物件。若要移除物件，請使用 Active Directory 管理工具。
+ 有些 AWS 服務 不適用於所有 AWS 區域。如需區域可用性，請參閱[AWS 依區域的服務](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)，然後選擇服務的連結。

**產品版本**

此解決方案已使用下列版本進行測試：
+ Windows Server 2019
+ SQL Server 2019
+ [Terraform 0.13.0 版](https://developer.hashicorp.com/terraform/language/v1.1.x/upgrade-guides/0-13)

## Architecture
<a name="deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-architecture"></a>

**來源技術堆疊**
+ SQL Server

**目標技術堆疊**
+ 使用 Amazon EC2 的 WSFC 節點上的 SQL Server FCI
+ Amazon FSx for Windows File Server
+ Amazon S3 儲存貯體
+ AWS Secrets Manager
+ AWS Managed Microsoft AD
+ AWS KMS
+ AWS Identity and Access Management (IAM)

**目標架構**

下圖顯示此解決方案的架構。

![\[在 Amazon EC2 上跨 Windows Server 容錯移轉叢集節點部署 SQL Server 容錯移轉叢集執行個體的架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/45f3ab19-d240-4353-ab6e-f6e565f537a4/images/0bff16f2-94e7-4e86-91ea-7ab5f3725620.png)


上圖顯示以下項目：
+ 提供 EC2 執行個體存取 AWS KMS 和 Secrets Manager 的 IAM 角色
+ 兩個 SQL Server 節點部署在跨兩個可用區域的私有子網路中的 Amazon EC2 執行個體上
+ Network Load Balancer，用於促進與作用中 SQL Server 執行個體的連線 （設定單一節點叢集時未部署）
+ Amazon FSx for Windows File Server 檔案系統部署在兩個私有子網路中，供 SQL Server 節點共用儲存
+ 用於存放 Active Directory 和 SQL Server 登入資料和組態的 Secrets Manager
+ 用於存放 SQL Server 安裝映像的 Amazon S3 儲存貯體
+ AWS Managed Microsoft AD 適用於 Windows 身分驗證
+ AWS KMS 用於建立加密金鑰

**自動化和擴展**

您可以使用 [GitHub 儲存庫](https://github.com/aws-samples/cluster-amazon-elastic-compute-cloud-amazon-fsx-microsoft-sql-server)中的 Terraform 模組來自動化目標架構的部署。您必須修改 `terraform.tfvars` 檔案，以包含您環境特有的變數值。Amazon S3 儲存貯體、 AWS Managed Microsoft AD 元件、 AWS KMS 加密金鑰和某些秘密是此部署的先決條件，不包含在 Terraform 程式碼中。

## 工具
<a name="deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-tools"></a>

**AWS 服務**
+ [AWS Directory Service for Microsoft Active Directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html) 可讓您的目錄感知工作負載 AWS 和資源在 中使用 Microsoft Active Directory AWS 雲端。在此模式中， AWS Managed Microsoft AD 用於 Windows Server 和 SQL Server 身分驗證，以及 DNS。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。在此模式中，SQL Server 容錯移轉叢集執行個體會安裝在 Amazon EC2 執行個體上。
+ [EC2 Image Builder](https://docs.aws.amazon.com/imagebuilder/latest/userguide/what-is-image-builder.html) 可協助您自動化自訂伺服器映像的建立、管理和部署。
+ [Amazon FSx for Windows File Server](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/what-is.html) 在 Windows Server 上提供全受管共用儲存。在此模式中，FSx for Windows File Server 為 SQL Server 資料和日誌檔案以及規定人數見證提供共用儲存。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Key Management Service (AWS KMS)](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) 可協助您建立和控制密碼編譯金鑰，以協助保護您的資料。在此模式中，它會用來加密 Secrets Manager 秘密、Amazon Elastic Block Store (Amazon EBS) 磁碟區上的 SQL Server 儲存體，以及 FSx for Windows File Server 檔案系統。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您將程式碼中的硬式編碼憑證 (包括密碼) 取代為 Secrets Manager 的 API 呼叫，以便透過程式設計方法來擷取機密。在此模式中，用於安裝和執行 SQL Server 的 Active Directory 登入資料、`sa`使用者登入資料和資料庫連線資訊會儲存在 Secrets Manager 中。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。此模式使用 Amazon S3 儲存貯體來存放 SQL Server 安裝映像。
+ [Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) 可協助您在已定義的虛擬網路中啟動 AWS 資源。此虛擬網路與您在自己的資料中心中操作的傳統網路相似，且具備使用 AWS可擴展基礎設施的優勢。

** ****其他工具**
+ [Microsoft SQL Server FCIs](https://learn.microsoft.com/en-us/sql/sql-server/failover-clusters/windows/always-on-failover-cluster-instances-sql-server?view=sql-server-ver15)安裝在 Windows Server 叢集節點之間。此外，它們可以跨多個子網路安裝。在此模式中，SQL Server FCI 執行個體會跨 WSFC 節點安裝。
+ [Terraform](https://www.terraform.io/) 是一種基礎設施即程式碼 (IaC) 工具，可協助您使用程式碼來佈建和管理雲端基礎設施和資源。在此模式中，Terraform 用於建立資源和設定 SQL Server FCI 執行個體。
+ [Windows Server 容錯移轉叢集](https://learn.microsoft.com/en-us/sql/sql-server/failover-clusters/windows/windows-server-failover-clustering-wsfc-with-sql-server?view=sql-server-ver15)提供基礎設施功能，可支援 SQL Server 等託管伺服器應用程式的高可用性。在此模式中，FCI 節點會利用 WSFC 功能，透過執行個體層級的備援提供本機高可用性。

**程式碼儲存庫**

此模式的程式碼可在 GitHub [cluster-amazon-elastic-compute-cloud-amazon-fsx-microsoft-sql-server](https://github.com/aws-samples/cluster-amazon-elastic-compute-cloud-amazon-fsx-microsoft-sql-server) 儲存庫中使用。下列資源可在 儲存庫中使用：
+ 提供解決方案概觀和其他安裝和使用資訊`README.md`的檔案
+ 一組基本的 Terraform 組態檔案和 Amazon FSx 特定模組，用於佈建此模式的元件
+ 做為 Amazon EC2 使用者資料指令碼執行的執行個體設定指令碼
+ Image Builder 可用來建立自訂 AMI 的 `component.yam`l 檔案

## 最佳實務
<a name="deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-best-practices"></a>

**安全性和修補**
+ AMI 先決條件安裝和組態是部署 SQL Server FCI 叢集的最低需求。可能需要其他軟體和組態，才能符合組織的標準和安全要求。
+ 部署之後，請持續修補 Windows。您可以直接修補執行中的執行個體，或使用最新的 Windows 修補程式建立新的 AMI，並使用新的 AMI 取代執行個體 （一次一個）。 每月 AWS 發行新的 Windows AMIs，其中包含最新的作業系統修補程式、驅動程式和啟動代理程式。我們建議您在啟動新執行個體或建置自訂映像時，檢查是否有最新的 AMI。
+ Amazon EC2 執行個體設定為允許所有傳出流量。在生產環境中部署時，應設定安全群組中的傳出規則，將此流量限制在所需的目的地。
+ FSx for Windows File Server 檔案系統可以自動記錄檔案共用和檔案和資料夾存取的稽核日誌，如果這是您環境中的需求，請將它們運送到您所需的目的地。
+ 定期自動輪換 Secrets Manager 秘密。對於 Amazon EC2 執行個體金鑰對，請考慮自動輪換解決方案，如[如何使用 AWS Secrets Manager 安全地存放和輪換 SSH 金鑰對](https://aws.amazon.com/blogs/security/how-to-use-aws-secrets-manager-securely-store-rotate-ssh-key-pairs/)所述。對於 Active Directory 登入資料和 SQL Server `sa`登入資料秘密，請根據您的密碼管理政策設定自動輪換。

**Active Directory 管理**
+ 在 FCI 叢集中，Windows 會在 Active Directory 中產生電腦名稱物件 (CNO)。CNO 會回應 DNS 請求，並將流量轉送至作用中的 SQL 節點。*我們不*建議使用此 Active Directory 提供的 DNS。TTL 太高，無法提供合理的容錯移轉時間，通常需要最多 5 分鐘才能反映新的主要 IP 地址。相反地，對於高可用性的安裝，內部 Network Load Balancer 設定為在 30 秒內容錯移轉。
+ 建立叢集需要 Active Directory 網域管理員。此需求是因為在 Active Directory 中建立叢集物件和修改許可所需的許可較高。不過，SQL Server 服務不需要以網域管理員身分執行。因此，我們建議您為此目的建立第二個 Active Directory 使用者。不過，如果服務將以網域管理員使用者身分執行，您可以消除此使用者。在這種情況下，網域管理員使用者必須新增至在此模式中建立的 Active Directory 管理員群組。

## 史詩
<a name="deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-epics"></a>

### 設定叢集登入資料
<a name="set-up-cluster-credentials"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Active Directory 群組。 | 在 中 AWS Managed Microsoft AD，建立下列群組：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx.html)如需詳細資訊，請參閱 AWS 文件中的[建立 AWS Managed Microsoft AD 群組](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_create_group.html)。 | AD 管理員 | 
| 建立 Active Directory 使用者。 | 在 中 AWS Managed Microsoft AD，建立下列使用者[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx.html)如需詳細資訊，請參閱 AWS 文件中的[建立 AWS Managed Microsoft AD 使用者](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_manage_users_groups_create_user.html)。 | AD 管理員 | 
| 將 Active Directory 登入資料新增至秘密。 | 使用 Secrets Manager 建立四個秘密來存放下列資訊：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx.html)如需詳細資訊，請參閱 AWS 文件中的[建立 AWS Secrets Manager 秘密](https://docs.aws.amazon.com/secretsmanager/latest/userguide/create_secret.html)。 | AWS 管理員 | 

### 準備環境
<a name="prepare-the-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Windows AMI。 | 建立包含必要軟體和組態的自訂 Windows AMI。如需詳細資訊，請參閱[其他資訊](#deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-additional)。 | AWS 管理員、AWS DevOps | 
| 安裝 Terraform。 | 若要安裝 Terraform，請遵循 [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli) 網站上的說明。 | AWS DevOps | 
| 複製儲存庫。 | 複製此模式的[儲存庫](https://github.com/aws-samples/cluster-amazon-elastic-compute-cloud-amazon-fsx-microsoft-sql-server)。如需詳細資訊，請參閱 GitHub [網站上的複製儲存庫](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository)。 | AWS DevOps | 

### 安裝叢集
<a name="install-the-cluster"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 修改 Terraform 變數。 | 更新提供的`terraform.tfvars`檔案，將所有變數設定為適合您環境的值。例如，更新 `domain_group_administrators`和 `domain_group_rdp_users`變數以使用您的 Active Directory 網域名稱和先前建立的 Active Directory 群組名稱。 | AWS DevOps | 
| 初始化 Terraform。 | 若要查看提議的部署，請導覽至儲存庫的根目錄。使用 Terraform 命令列界面 (CLI) 執行 `terraform init` ，然後執行 `terraform plan`。 | AWS DevOps | 
| 部署 資源。 | 若要部署 SQL 叢集和相關聯的資源，請使用 Terraform CLI 來執行 `terraform apply`。 | AWS DevOps、AWS 管理員 | 
| 驗證部署。 | 若要驗證部署，請使用下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx.html) | DBA、AWS 系統管理員 | 

## 疑難排解
<a name="deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| Terraform 佈建已完成，但 Windows 容錯移轉叢集管理員未顯示叢集已建立或叢集處於不可操作狀態。 | 叢集的整個資源和組態安裝可能需要 45-60 分鐘。Terraform 完成後，使用者資料指令碼必須執行到完成，這需要多次重新啟動。若要監控進度，您可以使用`C:\`磁碟機中的 `Checkpoints`目錄和 中的 SQL Server 安裝日誌`C:\Program Data\Microsoft SQL Server\150\Log`。完成後， `C:\ProgramData\Amazon\EC2-Windows\Launch\Log\UserdataExecution.log` 檔案中會提供**安裝完成**訊息。 | 
| 佈建正常運作的叢集之後，使用 Terraform 刪除並重新建立叢集不會成功。Terraform 完成，但叢集未正確設定。 | 佈建程序的一部分涉及向 Active Directory 和 Active Directory DNS 註冊機器和虛擬物件。當 Amazon EC2 叢集節點和叢集節點存在電腦名稱時，FCI 無法正確初始化，且佈建會失敗。若要修正此問題，請執行下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx.html) | 

## 相關資源
<a name="deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-resources"></a>

**AWS 文件**
+ [使用映像建置器建立自訂映像](https://docs.aws.amazon.com/imagebuilder/latest/userguide/create-images.html)
+ [建立 KMS 金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html)
+ [建立一般用途儲存貯體](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)
+ [建立金鑰政策](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-overview.html)
+ [建立您的 AWS Managed Microsoft AD](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/ms_ad_getting_started_create_directory.html)

## 其他資訊
<a name="deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-additional"></a>

**Terraform 模組資訊**

此模組使用混合 AMI 組態和使用者資料組態，以取得佈建時間和穩定性的良好組合。在佈建期間，Windows 需要多次重新啟動和等待。已實作檢查點方法，以防止持久性使用者資料重新啟動期間無限迴圈。使用者資料設定為持久性。因此，使用者資料組態指令碼具有且必須繼續開發為等冪性。冪等性可簡化更新程序，允許在更新週期期間交換執行個體，無需手動設定即可重新加入或重新建立 FCI 叢集。

**SQL Server 連線字串和容錯移轉叢集**

模組將發佈秘密，其中包含應用於此資料庫連線字串的端點地址。秘密名稱遵循格式 `{environment_name}/sqlserver/{cluster_name}/endpoint`。對於只使用一個節點的安裝，您可以預期這是 Amazon EC2 執行個體 SQL Server 介面的 IP 地址。對於高可用性安裝 （兩個執行個體），您可以預期這是內部 Network Load Balancer 的 DNS 名稱。

此模組不支援容錯移轉叢集虛擬 IPs。虛擬 IP 必須保留在相同的子網路中才能運作。在 中 AWS，單一子網路無法跨越多個可用區域。因此，使用虛擬 IPs 會移除將此模組視為高度可用的能力。

每個 Amazon EC2 執行個體都會獲得三個私有 IP 地址。它們的 usai 如下所示：
+ **網路流量的主要 IP** – 輸出流量的來源 IP。
+ **FCI 通訊** – 用來維護容錯移轉叢集的狀態和同步。
+ **SQL Server (TCP 連接埠 1433)** – 接聽程式和 也會接聽活動訊號流量，以判斷哪個執行個體是主要執行個體。

**VPC 組態**

[先決條件](#deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx-prereqs)會列出設定為使用 Active Directory 進行 DNS 解析的 DHCP 選項集。不過，此先決條件並非硬性要求。硬性要求是 EC2 執行個體必須能夠解析您的 Active Directory 網域名稱。您可以透過其他方式達成此要求，例如使用 Amazon Route 53 Resolver 端點。如需詳細資訊，請參閱[整合 Directory Service 的 DNS 解析與 Amazon Route 53 解析程式](https://aws.amazon.com/blogs/networking-and-content-delivery/integrating-your-directory-services-dns-resolution-with-amazon-route-53-resolvers/) (AWS 部落格文章）。

**AMI 組態**

此模式中使用的 AMI 必須包含下列必要軟體和組態：

1. 下載 SQL Server 2019 安裝檔案並將其展開至 `C:\SQL_Install_media`。

1. 安裝下列 Windows 功能：
   + `Install-WindowsFeature Failover-Clustering`
   + `Install-WindowsFeature RSAT-AD-PowerShell`
   + `Install-WindowsFeature RSAT-AD-Tools`
   + `Install-WindowsFeature RSAT-Clustering-Mgmt`
   + `Install-WindowsFeature RSAT-Clustering-PowerShell`
   + `Install-WindowsFeature RSAT-Clustering-CmdInterface`

1. 停用 Windows 防火牆，如下所示：
   + `Get-NetFirewallProfile | Set-NetFirewallProfile -Enabled False`

1. 啟用 CredSSP 身分驗證方法 (`<domain>`以組織的 Windows 網域名稱取代），如下所示：
   + `Enable-WSManCredSSP -Role "Server" -Force`
   + `Enable-WSManCredSSP -Role "Client" -DelegateComputer *.<domain>.com -Force`

1. 設定下列登錄機碼：
   + 允許 NTLM 身分驗證憑證：
     + `HKLM:\Software\Policies\Microsoft\Windows\CredentialsDelegation`
       + 名稱：`AllowFreshCredentialsWhenNTLMOnly`
       + 值：1
       + 類型：`REG_DWORD`
   + 允許本機網域電腦從 PowerShell 使用 NTLM：
     + 路徑： `HKLM:\Software\Policies\Microsoft\Windows\CredentialsDelegation\AllowFreshCredentialsWhenNTLMOnly`
       + 名稱：`1`
       + 值：`wsman/*.<domain>.com`
       + 類型：`REG_SZ`

1. 設定 [PowerShell Gallery](https://learn.microsoft.com/en-us/powershell/gallery/overview?view=powershellget-3.x)，如下所示：
   + `[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12`
   + `Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force`
   + `Set-PSRepository -Name PSGallery -InstallationPolicy Trusted`

1. 安裝下列 Windows PowerShell 模組`*`：
   + `Install-Module -Name ComputerManagementDsc`
   + `Install-Module -Name FailOverClusterDsc`
   + `Install-Module -Name PSDscResources`
   + `Install-Module -Name xSmbShare`
   + `Install-Module -Name xActiveDirectory`
   + `Install-Module -Name SqlServer`

若要使用映像建置器建立 AMI，請遵循映像建置器文件中[使用 EC2 Image Builderconsole 精靈建立映像管道](https://docs.aws.amazon.com/imagebuilder/latest/userguide/start-build-image-pipeline.html)中的指示。若要使用先前的先決條件建立配方的元件，請使用下列步驟：

1. 從 [GitHub 儲存庫](https://github.com/aws-samples/cluster-amazon-elastic-compute-cloud-amazon-fsx-microsoft-sql-server)的 `ami `資料夾下載 [component.yaml](https://github.com/aws-samples/cluster-amazon-elastic-compute-cloud-amazon-fsx-microsoft-sql-server/blob/main/ami/component.yaml) 檔案。

1. 將內容複製到新的映像建置器元件。

1. 使用您的資訊更新下列預留位置：
   + `<domain>` – 您的 Active Directory 網域名稱
   + `<bucket_name>` – 包含 SQL Server 映像的 Amazon S3 儲存貯體名稱

# 在 Amazon Aurora PostgreSQL 和 Amazon RDS for PostgreSQL 中模擬 Oracle PL/SQL 關聯陣列
<a name="emulate-oracle-plsql-associative-arrays-in-aurora-and-rds-postgresql"></a>

*Rajkumar Raghuwanshi、Bhanu Ganesh Gudivada 和 Sachin Khanna，Amazon Web Services*

## 總結
<a name="emulate-oracle-plsql-associative-arrays-in-aurora-and-rds-postgresql-summary"></a>

此模式說明如何模擬 [Amazon Aurora PostgreSQL ](https://aws.amazon.com/rds/aurora/)和 [Amazon RDS for PostgreSQL ](https://aws.amazon.com/rds/postgresql/)環境中具有空索引位置的 Oracle PL/SQL 關聯陣列。它還描述了 Oracle PL/SQL 關聯陣列和 PostgreSQL 陣列在遷移期間如何處理空索引位置的一些差異。

我們提供 PostgreSQL 替代方案，除了在遷移 Oracle 資料庫時使用 `aws_oracle_ext`函數來處理空的索引位置。此模式使用額外的資料欄來存放索引位置，並維護 Oracle 處理稀疏陣列，同時整合原生 PostgreSQL 功能。

**Oracle**

在 Oracle 中，集合可以初始化為空白，並使用`EXTEND`集合方法填入，這會將`NULL`元素附加到陣列。使用由 編製索引的 PL/SQL 關聯陣列時`PLS_INTEGER`，`EXTEND`方法會依序新增`NULL`元素，但元素也可以在非連續索引位置初始化。任何未明確初始化的索引位置都會保持空白。

此彈性允許稀疏陣列結構，其中元素可以填入任意位置。使用`FOR LOOP`具有 `FIRST`和 `LAST` 邊界的 反覆查看集合時，只會處理初始化的元素 （無論 `NULL`還是具有定義的值），同時略過空位置。

**PostgreSQL (Amazon Aurora 和 Amazon RDS)**

PostgreSQL 處理空值的方式與`NULL`值不同。它會將空值儲存為使用一個位元組儲存體的不同實體。當陣列具有空值時，PostgreSQL 會指派循序索引位置，就像非空值一樣。但是，循序索引需要額外處理，因為系統必須逐一查看所有索引位置，包括空的位置。這會使稀疏資料集的傳統陣列建立效率降低。

**AWS Schema Conversion Tool**

[AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/) 通常會使用 `aws_oracle_ext`函數處理 Oracle-to-PostgreSQL 的遷移。在此模式中，我們提出使用原生 PostgreSQL 功能的替代方法，該功能結合了 PostgreSQL 陣列類型和用於儲存索引位置的額外資料欄。然後，系統只需使用索引欄即可反覆查看陣列。

## 先決條件和限制
<a name="emulate-oracle-plsql-associative-arrays-in-aurora-and-rds-postgresql-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。
+ 具有管理員許可的 AWS Identity and Access Management (IAM) 使用者。
+ 與 Amazon RDS 或 Aurora PostgreSQL 相容的執行個體。
+ 對關聯式資料庫的基本了解。

**限制**
+ 有些 AWS 服務 不適用於所有 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

**產品版本**

此模式已使用下列版本進行測試：
+ Amazon Aurora PostgreSQL 13.3
+ Amazon RDS for PostgreSQL 13.3
+ AWS SCT 1.0.674
+ Oracle 12c EE 12.2

## Architecture
<a name="emulate-oracle-plsql-associative-arrays-in-aurora-and-rds-postgresql-architecture"></a>

**來源技術堆疊**
+ 內部部署 Oracle 資料庫

**目標技術堆疊**
+ Amazon Aurora PostgreSQL
+ Amazon RDS for PostgreSQL

**目標架構**

![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/a62d038c-ca3c-41e1-aa7e-74282d2e54f4/images/13aacf00-655a-4149-a4e7-42b66dbea4e1.png)


上圖顯示以下項目：
+ 來源 Amazon RDS for Oracle 資料庫執行個體
+ 使用 AWS SCT 將 Oracle 函數轉換為 PostgreSQL 對等項目的 Amazon EC2 執行個體
+ 與 Amazon Aurora PostgreSQL 相容的目標資料庫

## 工具
<a name="emulate-oracle-plsql-associative-arrays-in-aurora-and-rds-postgresql-tools"></a>

**AWS 服務**
+ [Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html) 是一種全受管關聯式資料庫引擎，專為雲端而建置，並與 MySQL 和 PostgreSQL 相容。
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 中設定、操作和擴展關聯式資料庫 AWS 雲端。
+ [Amazon Relational Database Service (Amazon RDS) for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 可協助您在 中設定、操作和擴展 Oracle 關聯式資料庫 AWS 雲端。
+ [適用於 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html) 可協助您在 中設定、操作和擴展 PostgreSQL 關聯式資料庫 AWS 雲端。
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 透過自動將來源資料庫結構描述和大部分自訂程式碼轉換為與目標資料庫相容的格式，支援異質資料庫遷移。

**其他工具**
+ [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) 是一種整合的開發環境，可簡化傳統和雲端部署中 Oracle 資料庫的開發和管理。
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。在此模式中，pgAdmin 會連線至 RDS for PostgreSQL 資料庫執行個體並查詢資料。或者，您可以使用 psql 命令列用戶端。

## 最佳實務
<a name="emulate-oracle-plsql-associative-arrays-in-aurora-and-rds-postgresql-best-practices"></a>
+ 測試資料集邊界和邊緣案例。
+ 考慮針對out-of-bounds索引條件實作錯誤處理。
+ 最佳化查詢以避免掃描稀疏資料集。

## 史詩
<a name="emulate-oracle-plsql-associative-arrays-in-aurora-and-rds-postgresql-epics"></a>

### Oracle 關聯陣列行為 （來源）
<a name="oracle-associative-array-behavior-source"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Oracle 中建立來源 PL/SQL 區塊。 | 在 Oracle 中建立使用下列關聯陣列的來源 PL/SQL 區塊：<pre>DECLARE<br />    TYPE country_codes IS TABLE OF VARCHAR2(100) INDEX BY pls_integer;<br />    cc country_codes;<br />    cc_idx NUMBER := NULL;<br />BEGIN<br />    cc(7) := 'India';<br />    cc(3) := 'UK';<br />    cc(5) := 'USA';<br />    cc(0) := 'China';<br />    cc(-2) := 'Invalid';<br />    dbms_output.put_line('cc_length:' || cc.COUNT);<br />    IF (cc.COUNT > 0) THEN<br />        cc_idx := cc.FIRST;<br />        FOR i IN 1..cc.COUNT LOOP<br />            dbms_output.put_line('cc_idx:' || cc_idx || ' country:' || cc(cc_idx));<br />            cc_idx := cc.next(cc_idx);<br />        END LOOP;<br />    END IF;<br />END;</pre> | DBA | 
| 執行 PL/SQL 區塊。 | 在 Oracle 中執行來源 PL/SQL 區塊。如果關聯陣列的索引值之間存在間隙，則不會在這些間隙中存放任何資料。這可讓 Oracle 迴圈僅逐一查看索引位置。 | DBA | 
| 檢閱輸出。 | 以非連續間隔將五個元素插入陣列 (`cc`)。陣列計數會顯示在下列輸出中：<pre>cc_length:5<br />cc_idx:-2 country:Invalid<br />cc_idx:0 country:China<br />cc_idx:3 country:UK<br />cc_idx:5 country:USA<br />cc_idx:7 country:India</pre> | DBA | 

### PostgreSQL 關聯陣列行為 （目標）
<a name="postgresql-associative-array-behavior-target"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 PostgreSQL 中建立目標 PL/pgSQL 區塊。 PostgreSQL | 在 PostgreSQL 中建立使用以下關聯陣列的目標 PL/pgSQL 區塊： PostgreSQL <pre>DO $$<br />DECLARE<br />    cc character varying(100)[];<br />    cc_idx integer := NULL;<br />BEGIN<br />    cc[7] := 'India';<br />    cc[3] := 'UK';<br />    cc[5] := 'USA';<br />    cc[0] := 'China';<br />    cc[-2] := 'Invalid';<br />    RAISE NOTICE 'cc_length: %', ARRAY_LENGTH(cc, 1);<br />    IF (ARRAY_LENGTH(cc, 1) > 0) THEN<br />        FOR i IN ARRAY_LOWER(cc, 1)..ARRAY_UPPER(cc, 1)<br />        LOOP<br />            RAISE NOTICE 'cc_idx:% country:%', i, cc[i];<br />        END LOOP;<br />    END IF;<br />END;<br />$$;</pre> | DBA | 
| 執行 PL/pgSQL 區塊。 | 在 PostgreSQL 中執行目標 PL/pgSQL 區塊。 PostgreSQL 如果關聯陣列的索引值之間存在間隙，則不會在這些間隙中存放任何資料。這可讓 Oracle 迴圈僅逐一查看索引位置。 | DBA | 
| 檢閱輸出。 | 陣列長度大於 5，因為 `NULL` 存放在索引位置之間的間隙中。如下列輸出所示，迴圈會完成 10 次反覆運算，以擷取陣列中的 5 個值。<pre>cc_length:10<br />cc_idx:-2 country:Invalid<br />cc_idx:-1 country:<NULL><br />cc_idx:0 country:China<br />cc_idx:1 country:<NULL><br />cc_idx:2 country:<NULL><br />cc_idx:3 country:UK<br />cc_idx:4 country:<NULL><br />cc_idx:5 country:USA<br />cc_idx:6 country:<NULL><br />cc_idx:7 country:India</pre> | DBA | 

### 模擬 Oracle 關聯陣列行為
<a name="emulate-oracle-associative-array-behavior"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用陣列和使用者定義的類型建立目標 PL/pgSQL 區塊。 | 為了最佳化效能並符合 Oracle 的功能，我們可以建立使用者定義的類型，同時存放索引位置及其對應的資料。這種方法透過維持索引和值之間的直接關聯來減少不必要的反覆運算。<pre>DO $$<br />DECLARE<br />    cc country_codes[];<br />    cc_append country_codes := NULL;<br />    i record;<br />BEGIN<br />    cc_append.idx = 7;<br />    cc_append.val = 'India';<br />    cc := array_append(cc, cc_append);<br />    cc_append.idx = 3;<br />    cc_append.val = 'UK';<br />    cc := array_append(cc, cc_append);<br />    cc_append.idx = 5;<br />    cc_append.val = 'USA';<br />    cc := array_append(cc, cc_append);<br />    cc_append.idx = 0;<br />    cc_append.val = 'China';<br />    cc := array_append(cc, cc_append);<br />    cc_append.idx = - 2;<br />    cc_append.val = 'Invalid';<br />    cc := array_append(cc, cc_append);<br />    RAISE NOTICE 'cc_length: %', ARRAY_LENGTH(cc, 1);<br />    IF (ARRAY_LENGTH(cc, 1) > 0) THEN<br />        FOR i IN (<br />            SELECT<br />                *<br />            FROM<br />                unnest(cc)<br />            ORDER BY<br />                idx)<br />                LOOP<br />                    RAISE NOTICE 'cc_idx:% country:%', i.idx, i.val;<br />                END LOOP;<br />    END IF;<br />END;<br />$$;</pre> | DBA | 
| 執行 PL/pgSQL 區塊。 | 執行目標 PL/pgSQL 區塊。如果關聯陣列的索引值之間存在間隙，則不會在這些間隙中存放任何資料。這可讓 Oracle 迴圈僅逐一查看索引位置。 | DBA | 
| 檢閱輸出。 | 如下列輸出所示，使用者定義的類型只會存放填入的資料元素，這表示陣列長度符合值的數量。因此，`LOOP`反覆運算已最佳化，僅處理現有資料，無需追蹤空位置。<pre>cc_length:5<br />cc_idx:-2 country:Invalid<br />cc_idx:0 country:China<br />cc_idx:3 country:UK<br />cc_idx:5 country:USA<br />cc_idx:7 country:India</pre> | DBA | 

## 相關資源
<a name="emulate-oracle-plsql-associative-arrays-in-aurora-and-rds-postgresql-resources"></a>

**AWS 文件**
+ [AWS 資料庫部落格](https://aws.amazon.com/blogs/database/)
+ [Oracle 到 Aurora PostgreSQL 遷移手冊](https://docs.aws.amazon.com/dms/latest/oracle-to-aurora-postgresql-migration-playbook/chap-oracle-aurora-pg.html)

**其他文件**
+ [Oracle 關聯陣列](https://docs.oracle.com/en/database/oracle/oracle-database/23/lnpls/associative-arrays.html#GUID-8060F01F-B53B-48D4-9239-7EA8461C2170)
+ [PostgreSQL 陣列函數和運算子](https://www.postgresql.org/docs/current/functions-array.html)
+ [PostgreSQL 使用者定義類型](https://www.postgresql.org/docs/current/sql-createtype.html)

# 在 Amazon RDS 中啟用 PostgreSQL 資料庫執行個體的加密連線
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds"></a>

*Rohit Kapoor，Amazon Web Services*

## 總結
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-summary"></a>

Amazon Relational Database Service (Amazon RDS) 支援 PostgreSQL 資料庫執行個體的 SSL 加密。使用 SSL，您可以加密應用程式與 Amazon RDS for PostgreSQL 資料庫執行個體之間的 PostgreSQL 連線。根據預設，Amazon RDS for PostgreSQL 會使用 SSL/TLS，並預期所有用戶端都會使用 SSL/TLS 加密進行連線。Amazon RDS for PostgreSQL 支援 TLS 1.1 和 1.2 版。

此模式說明如何啟用 Amazon RDS for PostgreSQL 資料庫執行個體的加密連線。您可以使用相同的程序來啟用 Amazon Aurora PostgreSQL 相容版本的加密連線。

## 先決條件和限制
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-prereqs"></a>
+ 作用中的 AWS 帳戶
+ [Amazon RDS for PostgreSQL 資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_RDS_Configuring.html)
+ [SSL 套件](https://www.postgresql.org/docs/current/ssl-tcp.html)

## Architecture
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-architecture"></a>

![\[在 Amazon RDS 中啟用 PostgreSQL 資料庫執行個體的加密連線\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/4f87c6a3-b4ff-4248-96d3-a4a498659735/images/ccc5c880-1191-4c12-a255-6908b96b96a5.png)


## 工具
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-tools"></a>
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理和開發平台。您可以在 Linux、Unix、macOS 和 Windows 上使用 pgAdmin 來管理 PostgreSQL 10 和更新版本中的資料庫物件。
+ [PostgreSQL 編輯器](https://wiki.postgresql.org/wiki/PostgreSQL_Clients)提供更易於使用的界面，協助您建立、開發和執行查詢，以及根據您的需求編輯程式碼。

## 最佳實務
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-best-practices"></a>
+ 監控不安全的資料庫連線。
+ 稽核資料庫存取權。
+ 確定備份和快照已在靜態加密。
+ 監控資料庫存取。
+ 避免不受限制的存取群組。
+ 使用 [Amazon GuardDuty](https://docs.aws.amazon.com/guardduty/latest/ug/what-is-guardduty.html) 增強您的通知。
+ 定期監控政策遵循。

## 史詩
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-epics"></a>

### 下載信任的憑證並將其匯入您的信任存放區
<a name="download-a-trusted-certificate-and-import-it-into-your-trust-store"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將信任的憑證載入您的電腦。 | 若要將憑證新增至您電腦的信任根憑證授權機構存放區，請遵循下列步驟。（這些指示使用 Window Server 做為範例。)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html) | DevOps 工程師、遷移工程師、DBA | 

### 強制 SSL 連線
<a name="force-ssl-connections"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立參數群組並設定 rds.force\$1ssl 參數。 | 如果 PostgreSQL 資料庫執行個體具有自訂參數群組，請編輯參數群組並變更為 `rds.force_ssl` 1。如果資料庫執行個體使用未`rds.force_ssl`啟用的預設參數群組，請建立新的參數群組。您可以使用 Amazon RDS API 或手動修改新的參數群組，如下列說明所示。若要建立新的參數群組：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html)若要將參數群組與 PostgreSQL 資料庫執行個體建立關聯：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html)如需詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithDBInstanceParamGroups.html)。 | DevOps 工程師、遷移工程師、DBA | 
| 強制 SSL 連線。 | 連線至 Amazon RDS for PostgreSQL 資料庫執行個體。不使用 SSL 的連線嘗試會遭到拒絕，並顯示錯誤訊息。如需詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Concepts.General.SSL.html#PostgreSQL.Concepts.General.SSL.Requiring)。 | DevOps 工程師、遷移工程師、DBA | 

### 安裝 SSL 延伸模組
<a name="install-ssl-extension"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝 SSL 延伸模組。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html)如需詳細資訊，請參閱 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Concepts.General.SSL.html)。 | DevOps 工程師、遷移工程師、DBA | 

### 為 SSL 設定 PostgreSQL 用戶端
<a name="configure-your-postgresql-client-for-ssl"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 SSL 的用戶端。 | 透過使用 SSL，您可以啟動 PostgreSQL 伺服器，並支援使用 TLS 通訊協定的加密連線。伺服器會接聽相同 TCP 連接埠上的標準和 SSL 連線，並與任何連線用戶端協商是否使用 SSL。根據預設，這是用戶端選項。如果您使用的是 psql 用戶端：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html)對於其他 PostgreSQL 用戶端：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html)檢閱這些用戶端的下列頁面：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.html) | DevOps 工程師、遷移工程師、DBA | 

## 疑難排解
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 無法下載 SSL 憑證。 | 請檢查您的網站連線，然後重試下載憑證到您的本機電腦。 | 

## 相關資源
<a name="enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds-resources"></a>
+ [Amazon RDS for PostgreSQL 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html)
+ [搭配 PostgreSQL 資料庫執行個體使用 SSL ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Concepts.General.SSL.html)(Amazon RDS 文件）
+ [使用 SSL 保護 TCP/IP 連線](https://www.postgresql.org/docs/9.1/ssl-tcp.html) (PostgreSQL 文件）
+ [使用 SSL](https://jdbc.postgresql.org/documentation/ssl/) (JDBC 文件）

# 加密現有的 Amazon RDS for PostgreSQL 資料庫執行個體
<a name="encrypt-an-existing-amazon-rds-for-postgresql-db-instance"></a>

*Piyush Goyal、Shobana Raghu 和 Yaser Raja，Amazon Web Services*

## 總結
<a name="encrypt-an-existing-amazon-rds-for-postgresql-db-instance-summary"></a>

此模式說明如何在最短的停機時間下，加密 AWS 雲端中 PostgreSQL 資料庫執行個體的現有 Amazon Relational Database Service (Amazon RDS)。此程序也適用於 Amazon RDS for MySQL 資料庫執行個體。

您可以在建立 Amazon RDS 資料庫執行個體時啟用加密，但無法在建立之後啟用加密。不過，您可以透過建立資料庫執行個體的快照，然後建立該快照的加密複本，將加密新增至未加密的資料庫執行個體。然後，您可以從加密快照還原資料庫執行個體，以取得原始資料庫執行個體的加密副本。如果您的專案允許在此活動期間停機 （至少用於寫入交易），這正是您需要做的。當資料庫執行個體的新加密複本可用時，您可以將應用程式指向新資料庫。不過，如果您的專案不允許此活動的重大停機時間，您需要替代方法來協助將停機時間降至最低。此模式使用 AWS Database Migration Service (AWS DMS) 來遷移和持續複寫資料，以便在最短的停機時間內完成切換到新的加密資料庫。 

Amazon RDS 加密資料庫執行個體使用業界標準的 AES-256 加密演算法，在託管 Amazon RDS 資料庫執行個體的伺服器上加密您的資料。資料加密後，Amazon RDS 會以透明的方式處理資料的存取和解密身分驗證，並將對效能的影響降至最低。您不需要修改資料庫用戶端應用程式即可使用加密。

## 先決條件和限制
<a name="encrypt-an-existing-amazon-rds-for-postgresql-db-instance-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 未加密的 Amazon RDS for PostgreSQL 資料庫執行個體
+ 使用 （建立、修改或停止） AWS DMS 任務的經驗 （請參閱 [AWS DMS 文件中的使用 AWS DMS 任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.html))
+ 熟悉用於加密資料庫的 AWS Key Management Service (AWS KMS) （請參閱 [AWS KMS 文件](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html))

**限制**
+ 您只能在建立 Amazon RDS 資料庫執行個體時啟用加密，而不是在建立資料庫執行個體之後。
+ 未使用快照還原[未記錄資料表](https://www.postgresql.org/docs/current/sql-createtable.html)中的資料。如需詳細資訊，請參閱[使用 PostgreSQL 的最佳實務](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_BestPractices.html#CHAP_BestPractices.PostgreSQL)。
+ 未加密資料庫執行個體不可以有加密僅供讀取複本，加密資料庫執行個體也不可以有未加密僅供讀取複本。
+ 您無法將未加密的備份或快照還原至已加密的資料庫執行個體。
+ AWS DMS 不會自動傳輸序列，因此需要其他步驟才能處理此問題。

如需詳細資訊，請參閱 [Amazon RDS 文件中的 Amazon RDS 加密資料庫執行個體限制](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.Encryption.html#Overview.Encryption.Limitations)。

## Architecture
<a name="encrypt-an-existing-amazon-rds-for-postgresql-db-instance-architecture"></a>

**來源架構**
+ 未加密的 RDS 資料庫執行個體

**目標架構**
+ 加密的 RDS 資料庫執行個體
  + 透過還原來源 RDS 資料庫執行個體的資料庫快照複本，即可建立目的地 RDS 資料庫執行個體。
  + 還原快照時，AWS KMS 金鑰用於加密。
  + AWS DMS 複寫任務用於遷移資料。

![\[程序使用 AWS DMS 將現有的 Amazon RDS for PostgreSQL 資料庫執行個體加密為新的資料庫。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/820d17c0-0eed-4ed9-9f43-cbada081d924/images/44dd8420-d89d-466e-b7fb-1bdafab8f7f9.png)


## 工具
<a name="encrypt-an-existing-amazon-rds-for-postgresql-db-instance-tools"></a>

**用來啟用加密的工具：**
+ 用於加密的 AWS KMS 金鑰 – 當您建立加密的資料庫執行個體時，您可以選擇客戶受管金鑰或 Amazon RDS 的 AWS 受管金鑰來加密資料庫執行個體。如果您未指定客戶受管金鑰的金鑰識別符，Amazon RDS 會為您的新資料庫執行個體使用 AWS 受管金鑰。Amazon RDS 會為您的 AWS 帳戶建立 Amazon RDS 的 AWS 受管金鑰。您的 AWS 帳戶對於每個 AWS 區域都有不同的 Amazon RDS AWS 受管金鑰。如需使用 KMS 金鑰進行 Amazon RDS 加密的詳細資訊，請參閱[加密 Amazon RDS 資源](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.Encryption.html)。

**用於持續複寫的工具**：
+ AWS DMS – 您可以使用 AWS Database Migration Service (AWS DMS) 將變更從來源資料庫複寫到目標資料庫。請務必讓來源和目標資料庫保持同步，以將停機時間降至最低。如需有關設定 AWS DMS 和建立任務的資訊，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)。

## 史詩
<a name="encrypt-an-existing-amazon-rds-for-postgresql-db-instance-epics"></a>

### 建立來源資料庫執行個體的快照並進行加密
<a name="create-a-snapshot-of-the-source-db-instance-and-encrypt-it"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢查來源 PostgreSQL 資料庫執行個體的詳細資訊。 | 在 Amazon RDS 主控台上，選擇來源 PostgreSQL 資料庫執行個體。在**組態**索引標籤上，確定執行個體未啟用加密。如需畫面圖例，請參閱[其他資訊](#encrypt-an-existing-amazon-rds-for-postgresql-db-instance-additional)一節。 | DBA | 
| 建立資料庫快照。 | 建立您要加密之執行個體的資料庫快照。建立快照所需的時間取決於資料庫的大小。如需說明，請參閱 [Amazon RDS 文件中的建立資料庫快照](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateSnapshot.html)。 | DBA | 
| 加密快照。 | 在 Amazon RDS 主控台導覽窗格中，選擇**快照**，然後選取您建立的資料庫快照。針對 **Actions** (動作) 選擇 **Copy Snapshot** (複製快照)。在對應的欄位中，提供目的地 AWS 區域和資料庫快照複本的名稱。選取**啟用加密**核取方塊。在 **Master Key (主金鑰)** 中，指定用來加密資料庫快照副本的 KMS 金鑰識別符。選擇 **Copy Snapshot (複製快照)**。如需詳細資訊，請參閱 [Amazon RDS 文件中的複製快照](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CopySnapshot.html)。 | DBA | 

### 準備目標資料庫執行個體
<a name="prepare-the-target-db-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 還原資料庫快照。 | 在 Amazon RDS 主控台上，選擇**快照**。選擇您建立的加密快照。針對 **Actions** (動作)，選擇 **Restore Snapshot** (還原快照)。針對**資料庫執行個體識別符**，提供新資料庫執行個體的唯一名稱。檢閱執行個體詳細資訊，然後選擇**還原資料庫執行個體**。系統會從您的快照建立新的加密資料庫執行個體。如需詳細資訊，請參閱 Amazon RDS 文件中的[從資料庫快照還原](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RestoreFromSnapshot.html)。 | DBA | 
| 使用 AWS DMS 遷移資料。 | 在 AWS DMS 主控台上，建立 AWS DMS 任務。針對**遷移類型**，選擇**遷移現有資料並複寫進行中的變更**。在**任務設定**中，針對**目標資料表準備模式**，選擇**截斷**。如需詳細資訊，請參閱 AWS DMS 文件中的[建立任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.Creating.html)。 | DBA | 
| 啟用資料驗證。 | 在**任務設定**中，選擇**啟用驗證**。這可讓您比較來源資料與目標資料，以確認資料已準確遷移。  | DBA | 
| 停用目標資料庫執行個體的限制。 | [停用目標資料庫執行個體上的任何觸發條件和外部金鑰限制](https://www.postgresql.org/docs/current/sql-altertable.html)，然後啟動 AWS DMS 任務。如需停用觸發條件和外部金鑰限制的詳細資訊，請參閱 [AWS DMS 文件。](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.PostgreSQL.html) | DBA | 
| 驗證資料。 | 完全載入完成後，請驗證目標資料庫執行個體上的資料，以查看是否符合來源資料。如需詳細資訊，請參閱 [AWS DMS 文件中的 AWS DMS 資料驗證](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Validating.html)。 | DBA | 

### 切換到目標資料庫執行個體
<a name="cut-over-to-the-target-db-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在來源資料庫執行個體上停止寫入操作。 | 停止來源資料庫執行個體上的寫入操作，以便開始應用程式停機時間。確認 AWS DMS 已完成管道中資料的複寫。在目標資料庫執行個體上啟用觸發和外部索引鍵。 | DBA | 
| 更新資料庫序列 | 如果來源資料庫包含任何序號，請驗證並更新目標資料庫中的序列。 | DBA | 
| 設定應用程式端點。 | 設定您的應用程式連線以使用新的 Amazon RDS 資料庫執行個體端點。資料庫執行個體現在已加密。 | DBA，應用程式擁有者 | 

## 相關資源
<a name="encrypt-an-existing-amazon-rds-for-postgresql-db-instance-resources"></a>
+ [建立 AWS DMS 任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.Creating.html) 
+ [使用 Amazon CloudWatch 監控複寫任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Monitoring.html#CHAP_Monitoring.CloudWatch)
+ [監控 AWS DMS 任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Monitoring.html)
+ [更新 Amazon RDS 加密金鑰](https://aws.amazon.com/premiumsupport/knowledge-center/update-encryption-key-rds/)

## 其他資訊
<a name="encrypt-an-existing-amazon-rds-for-postgresql-db-instance-additional"></a>

檢查來源 PostgreSQL 資料庫執行個體的加密：

![\[來源 PostgreSQL 資料庫執行個體的摘要頁面顯示未啟用儲存體加密。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/820d17c0-0eed-4ed9-9f43-cbada081d924/images/d53d1dab-b5c2-452d-b823-ba3d6508ad15.png)


此模式的其他備註：
+ 將 `rds.logical_replication` 參數設定為 1，以在 PostgreSQL 上啟用複寫。

**重要注意事項：**複寫槽會保留預先寫入日誌 (WAL) 檔案，直到檔案在外部使用，例如 `pg_recvlogical`； 擷取、轉換和載入 (ETL) 任務；或 AWS DMS。當您將`rds.logical_replication`參數值設定為 1 時，AWS DMS 會設定 `wal_level`、`max_wal_senders`、 `max_replication_slots`和 `max_connections` 參數。如果邏輯複寫槽存在，但複寫槽保留的 WAL 檔案沒有取用者，您可能會看到交易日誌磁碟用量增加，以及可用儲存空間持續減少。如需詳細資訊和解決此問題的步驟，請參閱 AWS Support 知識中心的文章[如何識別導致 Amazon RDS for PostgreSQL 上的「沒有剩餘空間」或「DiskFull」錯誤的原因](https://aws.amazon.com/premiumsupport/knowledge-center/diskfull-error-rds-postgresql/)。
+ 您在建立資料庫快照後對來源資料庫執行個體所做的任何結構描述變更都不會出現在目標資料庫執行個體上。
+ 建立加密的資料庫執行個體之後，您無法變更該資料庫執行個體所使用的 KMS 金鑰。在建立加密的資料庫執行個體之前，請務必判斷您的 KMS 金鑰需求。
+ 您必須先在目標資料庫執行個體上停用觸發和外部金鑰，才能執行 AWS DMS 任務。您可以在任務完成時重新啟用這些項目。

# 在啟動時強制執行 Amazon RDS 資料庫的自動標記
<a name="enforce-automatic-tagging-of-amazon-rds-databases-at-launch"></a>

*Susanne Kangnoh 和 Archit Mathur，Amazon Web Services*

## 總結
<a name="enforce-automatic-tagging-of-amazon-rds-databases-at-launch-summary"></a>

Amazon Relational Database Service (Amazon RDS) 是一種 Web 服務，可讓您更輕鬆地在 Amazon Web Services (AWS) 雲端中設定、操作和擴展關聯式資料庫。其能為產業標準的關聯式資料庫提供具成本效益、可調整大小的容量，並管理常見的資料庫管理任務。

您可以使用標記，以不同的方式分類您的 AWS 資源。當您帳戶中有許多資源，而且您想要根據標籤快速識別特定資源時，關聯式資料庫標記很有用。您可以使用 Amazon RDS 標籤將自訂中繼資料新增至 RDS 資料庫執行個體。標籤由使用者定義的索引鍵和值組成。我們建議您建立一組一致的標籤，以符合組織的需求。

此模式提供 AWS CloudFormation 範本，協助您監控和標記 RDS 資料庫執行個體。範本會建立監控 AWS CloudTrail CreateDBInstance 事件的 Amazon CloudWatch Events 事件。 CloudTrail **CreateDBInstance** (CloudTrail 會將 Amazon RDS 的 API 呼叫擷取為事件。) 當偵測到此事件時，它會呼叫 AWS Lambda 函數，自動套用您定義的標籤索引鍵和值。範本也會使用 Amazon Simple Notification Service (Amazon SNS) 傳送執行個體已標記的通知。

## 先決條件和限制
<a name="enforce-automatic-tagging-of-amazon-rds-databases-at-launch-prerequisites-and-limitations"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 用於上傳 Lambda 程式碼的 Amazon Simple Storage Service (Amazon S3) 儲存貯體。
+ 您想要接收標記通知的電子郵件地址。

**限制**
+ 解決方案支援 CloudTrail **CreateDBInstance** 事件。它不會為任何其他事件建立通知。

## Architecture
<a name="enforce-automatic-tagging-of-amazon-rds-databases-at-launch-architecture"></a>

**工作流程架構**

![\[Workflow diagram showing AWS 服務 interaction for RDS instance creation and notification.\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5541bc1e-e00f-4b5a-94b7-bb1808b5591a/images/ec0bcf92-f986-4af3-bfe7-d2c5e04051c5.png)


 

**自動化和擴展**
+ 您可以針對不同的 AWS 區域和帳戶多次使用 AWS CloudFormation 範本。您只需要在每個區域或帳戶中執行範本一次。

## 工具
<a name="enforce-automatic-tagging-of-amazon-rds-databases-at-launch-tools"></a>

**AWS 服務**
+ [AWS CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html) – AWS CloudTrail 是一種 AWS 服務，可協助您進行 AWS 帳戶的控管、合規以及營運和風險稽核。使用者、角色或 AWS 服務所執行的動作會在 CloudTrail 中記錄為事件。 
+ [Amazon CloudWatch Events](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html) – Amazon CloudWatch Events 提供近乎即時的系統事件串流，說明 AWS 資源的變更。CloudWatch Events 會在操作變更發生時得知並在必要時採取修正動作，方法是傳送訊息以回應環境、啟用 函數、進行變更，以及擷取狀態資訊。 
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) – AWS Lambda 是一種運算服務，支援執行程式碼，而不需要佈建或管理伺服器。Lambda 只有在需要時才會執行程式碼，可自動從每天數項請求擴展成每秒數千項請求。只需為使用的運算時間支付費用，一旦未執行程式碼，就會停止計費。
+ [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html) – Amazon Simple Storage Service (Amazon S3) 是一種高度可擴展的物件儲存服務，可用於各種儲存解決方案，包括網站、行動應用程式、備份和資料湖。
+ [Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) – Amazon Simple Notification Service (Amazon SNS) 是一種 Web 服務，可讓應用程式、最終使用者和裝置立即從雲端傳送和接收通知。 

**Code**

此模式包含兩個檔案的附件：
+ `index.zip` 是一種壓縮檔案，其中包含此模式的 Lambda 程式碼。
+ `rds.yaml` 是部署 Lambda 程式碼的 CloudFormation 範本。

如需如何使用這些檔案的資訊，請參閱 *Epics* 一節。

## 史詩
<a name="enforce-automatic-tagging-of-amazon-rds-databases-at-launch-epics"></a>

### 部署 Lambda 程式碼
<a name="deploy-the-lambda-code"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將程式碼上傳至 S3 儲存貯體。 | 建立新的 S3 儲存貯體或使用現有的 S3 儲存貯體上傳連接`index.zip`的檔案 (Lambda 程式碼）。此儲存貯體必須與您要監控的資源 (RDS 資料庫執行個體） 位於相同的 AWS 區域。 | 雲端架構師 | 
| 部署 CloudFormation 範本。 | 在與 S3 儲存貯體相同的 AWS 區域中開啟 Cloudformation 主控台，並部署附件中提供`rds.yaml`的檔案。在下一個 Epic 中，提供範本參數的值。 | 雲端架構師 | 

### 完成 CloudFormation 範本中的參數
<a name="complete-the-parameters-in-the-cloudformation-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 提供 S3 儲存貯體名稱。 | 輸入您在第一個 epic 中建立或選取的 S3 儲存貯體名稱。此 S3 儲存貯體包含 Lambda 程式碼的 .zip 檔案，且必須與 CloudFormation 範本和您要監控的 RDS 資料庫執行個體位於相同的 AWS 區域。 | 雲端架構師 | 
| 提供 S3 金鑰。 | 在您的 S3 儲存貯體中提供 Lambda 程式碼 .zip 檔案的位置，而不帶正斜線 （例如 `index.zip`或 `controls/index.zip`)。 | 雲端架構師 | 
| 提供電子郵件地址。 | 提供您要接收違規通知的作用中電子郵件地址。 | 雲端架構師 | 
| 指定記錄層級。 | 指定記錄層級和詳細程度。 會`Info`指定應用程式進度的詳細資訊性訊息，並應僅用於偵錯。 會`Error`指定仍然可以允許應用程式繼續執行的錯誤事件。 會`Warning`指定潛在的有害情況。 | 雲端架構師 | 
| 輸入 RDS 資料庫執行個體的標籤索引鍵和值。 | 輸入您要自動套用至 RDS 執行個體的必要標籤索引鍵和值。如需詳細資訊，請參閱 AWS 文件中的[標記 Amazon RDS 資源](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_Tagging.html)。 | 雲端架構師 | 

### 確認訂閱
<a name="confirm-the-subscription"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 確認電子郵件訂閱。 | 當 CloudFormation 範本成功部署時，它會傳送訂閱電子郵件訊息到您提供的電子郵件地址。若要在執行個體加上標籤時接收通知，您必須確認此電子郵件訂閱。 | 雲端架構師 | 

## 相關資源
<a name="enforce-automatic-tagging-of-amazon-rds-databases-at-launch-related-resources"></a>
+ [建立儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/create-bucket.html)體 (Amazon S3 文件）
+ [標記 Amazon RDS 資源](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_Tagging.html) (Amazon Aurora 文件）
+ [上傳物件 ](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/upload-objects.html)(Amazon S3 文件）
+ [使用 AWS CloudTrail 建立在 AWS API 呼叫上觸發的 CloudWatch Events 規則 CloudTrail](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/Create-CloudWatch-Events-CloudTrail-Rule.html) (Amazon CloudWatch 文件）

## 附件
<a name="attachments-5541bc1e-e00f-4b5a-94b7-bb1808b5591a"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/5541bc1e-e00f-4b5a-94b7-bb1808b5591a/attachments/attachment.zip)

# 預估 DynamoDB 資料表的隨需容量成本
<a name="estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity"></a>

*Moinul Al-Mamun，Amazon Web Services*

## 總結
<a name="estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity-summary"></a>

[Amazon DynamoDB](https://aws.amazon.com/dynamodb/) 是 NoSQL 交易資料庫，即使在 PB 規模下也能提供單一位數毫秒延遲。此 Amazon Web Services (AWS) 無伺服器產品因其一致的效能和可擴展性而廣受歡迎。 您不需要佈建基礎基礎設施。您的單一資料表最多可增長至 PB。

使用隨需容量模式時，您需要為應用程式在資料表上執行的資料讀取和寫入支付每個請求的費用。AWS 費用是以每月累積的讀取請求單位 (RRUs) 和寫入請求單位 WRUs) 為基礎。DynamoDB 會在一個月內持續監控資料表的大小，以判斷您的儲存費用。它支援使用point-in-time-recovery(PITR) 進行連續備份。DynamoDB 會在一個月內持續監控已啟用 PITR 的資料表大小，以判斷您的備份費用。

若要預估專案的 DynamoDB 成本，請務必計算產品生命週期的不同階段會耗用多少 RRU、WRU 和儲存體。對於粗略成本估算，您可以使用 [AWS 定價計算器](https://calculator.aws/#/createCalculator/DynamoDB)，但必須為資料表提供大約數量RRUs、WRUs和儲存需求。這些在專案開始時可能很難預估。AWS 定價計算器不會考慮資料成長率或項目大小，也不會分別考慮基底資料表和全域次要索引 (GSIs讀取和寫入次數。若要使用 AWS 定價計算器，您必須估計所有這些層面，以假設 WRU、RRU 和儲存體大小的 ballpark 數字，以取得您的成本估算。

此模式提供一種機制和可重複使用的 Microsoft Excel 範本，可針對隨需容量模式預估基本的 DynamoDB 成本因素，例如寫入、讀取、儲存、備份和復原成本。它比 AWS 定價計算器更精細，並獨立考慮基礎資料表和 GSIs要求。它也會考慮每月項目資料成長率，並預測三年的成本。

## 先決條件和限制
<a name="estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity-prereqs"></a>

**先決條件**
+ DynamoDB 和 DynamoDB 資料模型設計的基本知識
+ DynamoDB 定價、WRU、RRU、儲存以及備份和復原的基本知識 （如需詳細資訊，請參閱[隨需容量定價](https://aws.amazon.com/dynamodb/pricing/on-demand/))
+ 了解 DynamoDB 中的資料、資料模型和項目大小
+ DynamoDB GSIs的知識

**限制**
+ 範本提供您近似的計算，但不適用於所有組態。若要取得更準確的預估值，您必須測量基礎資料表和 GSIs 中每個項目的個別項目大小。
+ 為了獲得更準確的預估，您必須考慮平均月份中每個項目的預期寫入次數 （插入、更新和刪除） 和讀取次數。
+ 此模式支援根據固定的資料成長假設，估計未來幾年的寫入、讀取、儲存和備份和復原成本。

## 工具
<a name="estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity-tools"></a>

**AWS 服務**
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) 是一項全受管 NoSQL 資料庫服務，可提供快速、可預期且可擴展的效能。

**其他工具**
+ [AWS 定價計算器](https://calculator.aws/#/createCalculator/DynamoDB)是一種 Web 型規劃工具，可用來建立 AWS 使用案例的預估值。

## 最佳實務
<a name="estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity-best-practices"></a>

為了協助降低成本，請考慮下列 DynamoDB 設計最佳實務。
+ [分割區索引鍵設計](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-partition-key-uniform-load.html) – 使用高基數分割區索引鍵來均勻分配負載。
+ [相鄰清單設計模式](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html) – 使用此設計模式來管理一對多和多對多關係。
+ [稀鬆索引](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-indexes-general-sparse-indexes.html) – 對 GSI 使用稀鬆索引。在您建立 GSI 時，指定一個分割區索引鍵和 (選用) 一個排序索引鍵。只有在基本資料表中包含對應 GSI 分割區索引鍵的項目才會出現在稀疏索引中。這有助於保持 GSI 更小。
+ [索引過載](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-gsi-overloading.html) – 使用相同的 GSI 對各種類型的項目編製索引。
+ [GSI 寫入碎片](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-indexes-gsi-sharding.html) – 明智地進行碎片以跨分割區分佈資料，以實現高效、更快的查詢。
+ [大型項目](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-use-s3-too.html) – 僅將中繼資料儲存在表內，將 Blob 儲存在 Amazon S3 中，並將參考保留在 DynamoDB 中。將大型項目分解為多個項目，並使用排序索引鍵有效率地編製索引。

如需更多設計最佳實務，請參閱《Amazon DynamoDB [開發人員指南](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/best-practices.html)》。

## 史詩
<a name="estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity-epics"></a>

### 從 DynamoDB 資料模型擷取項目資訊
<a name="extract-item-information-from-your-dynamodb-data-model"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 取得項目大小。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity.html) | 資料工程師 | 
| 預估寫入成本。 | 若要在隨需容量模式中預估寫入成本，您必須先測量一個月將耗用多少 WRUs。因此，您需要考慮下列因素：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity.html)如需詳細資訊，請參閱*其他資訊*一節。 | 資料工程師 | 
| 預估讀取成本。 | 若要在隨需模式中預估讀取成本，您必須先測量一個月將耗用多少 RRUs。因此，您需要考慮下列因素： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity.html) | 資料工程師、應用程式開發人員 | 
| 估算儲存體大小和成本。 | 首先，根據資料表中的項目大小估計每月平均儲存需求。然後將儲存體大小乘以 AWS 區域的每 GB 儲存體價格，以計算儲存體成本。 如果您已輸入用於估算寫入成本的資料，則不需要再次輸入它來計算儲存體大小。否則，若要估計儲存體大小，您需要考慮下列因素： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity.html) | 資料工程師 | 

### 在 Excel 範本中輸入項目和物件資訊
<a name="enter-the-item-and-object-information-in-the-excel-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從附件區段下載 Excel 範本，並針對您的使用案例資料表進行調整。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity.html) | 資料工程師 | 
| 在 Excel 範本中輸入資訊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity.html)在範本中，有三個項目或實體：資訊、中繼資料和關係。有兩個 GSIs。針對您的使用案例，如果您需要更多項目，請建立新的資料列。如果您需要更多 GSIs，請複製現有的 GSI 區塊，然後貼上以視需要建立任意數量的 GSI 區塊。然後調整 SUM 和總計資料欄計算。 | 資料工程師 | 

## 相關資源
<a name="estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity-resources"></a>

**參考**
+ [Amazon DynamoDB 隨需容量定價](https://aws.amazon.com/dynamodb/pricing/on-demand/)
+ [DynamoDB 的 AWS 定價計算器](https://calculator.aws/#/createCalculator/DynamoDB)
+ [使用 DynamoDB 進行設計和架構的最佳實務](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/best-practices.html)
+ [DynamoDB 入門](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStartedDynamoDB.html)

**指南和模式**
+ [使用 Amazon DynamoDB 建立資料模型](https://docs.aws.amazon.com/prescriptive-guidance/latest/dynamodb-data-modeling/)
+ [Amazon DynamoDB 資料表的預估儲存成本](https://apg-library.amazonaws.com/content/9b74399d-9655-47ee-b9b3-de46b65bc4e3)

## 其他資訊
<a name="estimate-the-cost-of-a-dynamodb-table-for-on-demand-capacity-additional"></a>

**寫入成本計算範例**

DynamoDB 資料模型設計顯示產品的三個項目，平均項目大小為 4 KB。當您將新產品新增至 DynamoDB 基礎資料表時，它會耗用項目數量 \$1 （項目大小/1 KB 寫入單位） = 3 \$1 (4/1) = 12 WRU。在此範例中，針對寫入 1 KB，產品會耗用 1 個 WRU。 

**讀取成本計算範例**

若要取得 RRU 估算，請考慮每個項目一個月讀取的平均次數。例如，資訊項目將平均讀取一個月 10 次，中繼資料項目將讀取兩次，而關係項目將讀取五次。在範例範本中，所有元件的總 RRU = 每月建立的新元件數量 \$1 每個元件每月 RRU = 1，000 萬 \$1 17 RRU = 每月 1.700 萬 RRU。

每個月都會新增新事物 （元件或產品將會新增，且產品總數將會隨著時間成長。因此，RRU 需求也會隨著時間增加。
+ 第一個月的 RRU 使用量將為 1.7 億。
+ 第二個月，RRU 使用量將為 2 \$1 1.7 億 = 3.4 億。
+ 第三個月的 RRU 使用量將為 3 \$1 1.7 億 = 5.1 億。

下圖顯示每月 RRU 用量和成本預測。

![\[RRU 消耗的增加量比成本更陡峭。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/1797b48f-a183-4f25-811f-44921c3a48ee/images/3505bfc8-694d-4acc-8585-cd71258fa315.png)


請注意，圖表中的價格僅供說明之用。若要為您的使用案例建立準確的預測，請查看 AWS 定價頁面，並在 Excel 工作表中使用這些價格。

**儲存、備份和復原成本計算範例**

DynamoDB 儲存、備份和還原全部會彼此連線。備份會直接與儲存體連線，而復原則會直接與備份大小連線。隨著資料表大小的增加，對應的儲存、備份和還原成本將按比例增加。

*儲存體大小和成本*

儲存成本會根據您的資料成長率隨時間增加。例如，假設基礎資料表和 GSIs 中元件或產品的平均大小為 11 KB，每月會將 1，000 萬個新產品新增至您的資料庫資料表。在這種情況下，您的 DynamoDB 資料表大小將增長 (11 KB \$1 1000 萬）/1024/1024 = 每月 105 GB。在第一個月，您的資料表儲存大小將為 105 GB，第二個月將為 105 \$1 105 = 210 GBs，以此類推。
+ 第一個月，您的 AWS 區域的儲存成本為每 GB 105 GB \$1 儲存價格。 
+ 第二個月的儲存成本將是您所在區域的每 GB 210 GB \$1 儲存價格。
+ 第三個月的儲存成本將是您所在區域的每 GB 315 GB \$1 儲存價格。

如需未來三年的儲存大小和成本，請參閱*儲存大小和預測*一節。

*備份成本*

備份成本會根據您的資料成長率隨時間增加。當您使用point-in-time-recovery(PITR) 開啟連續備份時，連續備份費用是以每月平均儲存 GB 為基礎。在日曆月中，平均備份大小將與您的資料表儲存大小相同，但實際大小可能略有不同。隨著每個月都會新增新產品，總儲存大小和備份大小會隨著時間增加。例如，第一個月的平均備份大小 105 GB 可能會增加到第二個月的 210 GB。
+ 對於您的 AWS 區域，第一個月的備份成本為每 GB 105 GB/月 \$1 連續備份價格。 
+ 第二個月的備份成本將是 210 GB-月 \$1 您區域每 GB 的連續備份價格。
+ 第三個月的備份成本為 315 GB/月 \$1 您所在區域的每 GB 連續備份價格。
+ 和 ，以此類推

備份成本包含在*儲存體大小和成本預測*區段的圖表中。

*復原成本*

當您在啟用 PITR 的情況下進行連續備份時，復原操作費用會根據還原的大小而定。每次還原時，您都會根據 GB 的還原資料付費。如果您的資料表大小很大，而且您在一個月內執行多次還原，則其成本很高。

為了預估還原成本，此範例假設您每個月在月底執行一次 PITR 復原。此範例使用每月平均備份大小作為該月的還原資料大小。對於第一個月，平均備份大小為 105 GB，對於月底的復原，還原資料大小為 105 GB。第二個月會是 210 GBs以此類推。

復原成本會根據您的資料成長率隨時間增加。
+ 對於您的 AWS 區域，第一個月的復原成本將為每 GB 105 GB \$1 還原價格。 
+ 第二個月的復原成本將是 210 GB \$1 還原價格，每個 GB 的 區域。
+ 第三個月的復原成本將為 315 GB \$1 還原價格，每個 GB 的 區域。

如需詳細資訊，請參閱 Excel 範本中的儲存、備份和復原索引標籤，以及下一節中的圖表。

*儲存體大小和成本預測*

在範本中，實際計費儲存體大小的計算方式是將標準資料表類別的每月免費方案減去 25 GB。在工作表中，您會看到預測圖表分為每月值。

下列範例圖表預測未來 36 個日曆月的每月儲存大小，包括 GB、計費儲存成本、隨需備份成本和復原成本。所有成本都是 USD。從圖表中，顯然儲存、備份和復原成本會隨著儲存大小的增加而按比例增加。

![\[儲存體大小超過三千，而成本不到一千。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/1797b48f-a183-4f25-811f-44921c3a48ee/images/fd9f06d0-bc9c-4b4e-8cbd-3e527fe09e88.png)


請注意，圖表中使用的價格僅供說明之用。若要為您的使用案例建立準確的價格，請查看 AWS 定價頁面，並在 Excel 範本中使用這些價格。

## 附件
<a name="attachments-1797b48f-a183-4f25-811f-44921c3a48ee"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/1797b48f-a183-4f25-811f-44921c3a48ee/attachments/attachment.zip)

# Amazon DynamoDB 資料表的預估儲存成本
<a name="estimate-storage-costs-for-an-amazon-dynamodb-table"></a>

*Moinul Al-Mamun，Amazon Web Services*

## 總結
<a name="estimate-storage-costs-for-an-amazon-dynamodb-table-summary"></a>

Amazon DynamoDB 是 NoSQL 交易資料庫，即使在 PB 規模下也能提供單一位數毫秒延遲。的這項熱門無伺服器產品 AWS 提供一致的效能和可擴展性。您不需要佈建儲存體，而且您的單一資料表最多可增長至 PB。 

DynamoDB 會在一個月內持續監控資料表的大小，以判斷您的儲存費用。 AWS 然後， 會針對以 GB 為單位的平均儲存大小向您收費。隨著時間的推移，資料表的成長越多，儲存成本的成長就越多。若要計算儲存成本，您可以使用 [AWS 定價計算器](https://calculator.aws/#/createCalculator/DynamoDB)，但您需要提供資料表的大致大小，包括全域次要索引 (GSIs)，這在專案開始時很難估計。此外， AWS 定價計算器不會考慮資料成長率。

此模式提供一種機制和可重複使用的 Microsoft Excel 範本，用於計算 DynamoDB 儲存體大小和成本。它會獨立考慮基礎資料表和 GSIs的儲存需求。它透過考慮個別項目的大小和隨時間推移的資料成長率來計算儲存體大小。 

若要取得預估值，請將兩個資訊插入範本：
+ 基底資料表和 GSIs 的個別項目大小，以 KB 為單位
+ 一個月平均可以新增多少個新物件或產品至資料表 （例如 1，000 萬個）

範本會產生未來三年的儲存體和成本預測圖表，如下列範例所示。

![\[成本的較低線會緩慢上移，而儲存體的較高線會更快上移。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/9b74399d-9655-47ee-b9b3-de46b65bc4e3/images/c0436252-cc42-4ea3-ac50-c0455aece39d.png)


 

## 先決條件和限制
<a name="estimate-storage-costs-for-an-amazon-dynamodb-table-prereqs"></a>

**先決條件**
+ DynamoDB 的基本知識，包括 DynamoDB 儲存和定價
+ 了解 DynamoDB 中的資料、資料模型和項目大小
+ DynamoDB 全域次要索引 (GSIs的知識

**限制**
+ 範本提供您近似的計算，但不適用於所有組態。若要取得更準確的預估值，您必須測量基礎資料表和 GSIs 中每個項目的個別項目大小。 
+ 此模式僅支援根據固定資料成長假設來估計未來幾年的儲存大小和成本。

## 工具
<a name="estimate-storage-costs-for-an-amazon-dynamodb-table-tools"></a>

**AWS 服務**
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) 是一項全受管 NoSQL 資料庫服務，可提供快速、可預期且可擴展的效能。

**其他工具**
+ [AWS 定價計算器](https://docs.aws.amazon.com/pricing-calculator/latest/userguide/what-is-pricing-calculator.html)是一種 Web 型規劃工具，可用來建立 AWS 使用案例的預估值。

## 史詩
<a name="estimate-storage-costs-for-an-amazon-dynamodb-table-epics"></a>

### 從 DynamoDB 資料模型擷取項目資訊
<a name="extract-item-information-from-your-ddb-data-model"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 取得項目大小。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-storage-costs-for-an-amazon-dynamodb-table.html) | 資料工程師 | 
| 取得一個月內新增的物件數量。 | 估計一個月平均會將多少個元件或物件新增至 DynamoDB 資料表。 | 資料工程師 | 

### 在 Excel 範本中輸入項目和物件資訊
<a name="enter-the-item-and-object-information-in-the-excel-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 下載並調整 Excel 試算表。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-storage-costs-for-an-amazon-dynamodb-table.html) | 資料工程師 | 
| 在 Excel 範本中輸入資訊。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-storage-costs-for-an-amazon-dynamodb-table.html) | 資料工程師 | 

## 相關資源
<a name="estimate-storage-costs-for-an-amazon-dynamodb-table-resources"></a>
+ Amazon DynamoDB [的隨需容量定價](https://aws.amazon.com/dynamodb/pricing/on-demand/) 
+ [AWS DynamoDB 定價計算器](https://calculator.aws/#/createCalculator/DynamoDB)

## 其他資訊
<a name="estimate-storage-costs-for-an-amazon-dynamodb-table-additional"></a>

請注意，連接的範本只會預測標準儲存資料表類別的儲存大小和成本。根據儲存成本的預測，以及考量個別項目大小和產品或物件成長率，您可以預估下列項目：
+ 資料匯出成本
+ 備份和復原成本
+ 資料儲存需求。

**Amazon DynamoDB 資料儲存成本**

DynamoDB 會持續監控資料表的大小，以判斷您的儲存費用。DynamoDB 會根據您啟用的功能，將資料的原始位元組大小與每個項目的儲存額外負荷相加，以計算可計費資料大小。如需詳細資訊，請參閱 [DynamoDB 開發人員指南](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CapacityUnitCalculations.html)。 

資料儲存的價格取決於您的資料表類別。如果您使用 DynamoDB Standard 資料表類別，則每個月存放的前 25 GB 是免費的。如需不同標準和標準不常存取資料表類別儲存成本的詳細資訊 AWS 區域，請參閱[隨需容量定價](https://aws.amazon.com/dynamodb/pricing/on-demand/)。

## 附件
<a name="attachments-9b74399d-9655-47ee-b9b3-de46b65bc4e3"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/9b74399d-9655-47ee-b9b3-de46b65bc4e3/attachments/attachment.zip)

# 使用 AWR 報告估計 Oracle 資料庫的 Amazon RDS 引擎大小
<a name="estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports"></a>

*Abhishek Verma 和 Eduardo Valentim，Amazon Web Services*

## 總結
<a name="estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports-summary"></a>

當您將 Oracle 資料庫遷移至 Amazon Relational Database Service (Amazon RDS) 或 Amazon Aurora 時，計算目標資料庫的 CPU、記憶體和磁碟 I/O 是關鍵需求。您可以透過分析 Oracle 自動工作負載儲存庫 (AWR) 報告來估計目標資料庫所需的容量。此模式說明如何使用 AWR 報告來估計這些值。

來源 Oracle 資料庫可以是內部部署或在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上託管，也可以是 Amazon RDS for Oracle 資料庫執行個體。目標資料庫可以是任何 Amazon RDS 或 Aurora 資料庫。

**注意**  
如果您的目標資料庫引擎是 Oracle，容量預估會更精確。對於其他 Amazon RDS 資料庫，引擎大小可能會因資料庫架構的差異而有所不同。

我們建議您在遷移 Oracle 資料庫之前執行效能測試。

## 先決條件和限制
<a name="estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports-prereqs"></a>

**先決條件**
+ 下載 AWR 報告的 Oracle Database Enterprise Edition 授權和 Oracle Diagnostics Pack 授權。

**產品版本**
+ 版本 11g （版本 11.2.0.3.v1 及更新版本） 和最高 12.2 和 18c、19c 的所有 Oracle 資料庫版本。
+ 此模式不包含 Oracle Engineered Systems 或 Oracle Cloud Infrastructure (OCI)。

## Architecture
<a name="estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports-architecture"></a>

**來源技術堆疊**

下列其中一項：
+ 內部部署 Oracle 資料庫
+ EC2 執行個體上的 Oracle 資料庫
+ Amazon RDS for Oracle 資料庫執行個體

**目標技術堆疊**
+ 任何 Amazon RDS 或 Amazon Aurora 資料庫

**目標架構**

如需完整遷移程序的資訊，請參閱[使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫遷移至 Aurora PostgreSQL ](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct.html)的模式。

**自動化和擴展**

如果您有多個 Oracle 資料庫要遷移，而且想要使用其他效能指標，您可以依照部落格文章中所述的步驟[，根據 Oracle 效能指標大規模調整 Amazon RDS 執行個體的大小](https://aws.amazon.com/blogs/database/right-sizing-amazon-rds-instances-at-scale-based-on-oracle-performance-metrics/)，來自動化程序。

## 工具
<a name="estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports-tools"></a>
+ [Oracle 自動工作負載儲存庫 (AWR)](https://docs.oracle.com/en-us/iaas/performance-hub/doc/awr-report-ui.html) 是內建於 Oracle 資料庫的儲存庫。它會定期收集和存放系統活動和工作負載資料，然後由自動資料庫診斷監控 (ADDM) 進行分析。AWR 會定期擷取系統效能資料的快照 （預設為每 60 分鐘），並儲存資訊 （預設為最多 8 天）。 您可以使用 AWR 檢視和報告來分析此資料。

## 最佳實務
<a name="estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports-best-practices"></a>
+ 若要計算目標資料庫的資源需求，您可以使用單一 AWR 報告、多個 AWR 報告或動態 AWR 檢視。我們建議您在尖峰負載期間使用多個 AWR 報告來估計處理這些尖峰負載所需的資源。此外，動態檢視提供了更多資料點，可協助您更精確地計算資源需求。 
+ 您應該預估 IOPS 僅適用於您計劃遷移的資料庫，而不是使用磁碟的其他資料庫和程序。
+ 若要計算資料庫正在使用多少 I/O，請勿使用 AWR 報告負載設定檔區段中的資訊。如果可用，請改用 I/O 設定檔區段，或跳至執行個體活動統計資料區段，並查看實體讀取和寫入操作的總值。
+ 當您估計 CPU 使用率時，我們建議您使用資料庫指標方法，而不是作業系統 (OS) 統計資料，因為它是以資料庫使用的 CPU 為基礎。(OS 統計資料也包含其他程序的 CPU 用量。) 您也應該檢查 ADDM 報告中與 CPU 相關的建議，以改善遷移後的效能。
+ 當您判斷正確的執行個體類型時，請考慮特定執行個體大小的 I/O 輸送量限制：Amazon Elastic Block Store (Amazon EBS) 輸送量和網路輸送量。
+ 在遷移之前執行效能測試，以驗證引擎大小。

## 史詩
<a name="estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports-epics"></a>

### 建立 AWR 報告
<a name="create-an-awr-report"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟用 AWR 報告。 | 若要啟用報告，請遵循 [Oracle 文件](https://docs.oracle.com/en/database/oracle/oracle-database/18/tgdba/gathering-database-statistics.html#GUID-26D359FA-F809-4444-907C-B5AFECD9AE29)中的指示。 | DBA | 
| 檢查保留期間。 | 若要檢查 AWR 報告的保留期間，請使用下列查詢。<pre>SQL> SELECT snap_interval,retention FROM dba_hist_wr_control;</pre> | DBA | 
| 產生快照。 | 如果 AWR 快照間隔不夠精細，無法擷取尖峰工作負載的峰值，您可以手動產生 AWR 報告。若要產生手動 AWR 快照，請使用下列查詢。<pre>SQL> EXEC dbms_workload_repository.create_snapshot;</pre> | DBA | 
| 檢查最近的快照。 | 若要檢查最近的 AWR 快照，請使用下列查詢。<pre>SQL> SELECT snap_id, to_char(begin_interval_time,'dd/MON/yy hh24:mi') Begin_Interval,<br /> to_char(end_interval_time,'dd/MON/yy hh24:mi') End_Interval<br /> FROM dba_hist_snapshot<br /> ORDER BY 1;</pre> | DBA | 

### 估計磁碟 I/O 需求
<a name="estimate-disk-i-o-requirements"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選擇一個方法。 | IOPS 是儲存裝置上每秒輸入和輸出操作的標準測量，包括讀取和寫入操作。 如果您要將現場部署資料庫遷移至 AWS，您需要判斷資料庫使用的尖峰磁碟 I/O。您可以使用下列方法來預估目標資料庫的磁碟 I/O：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)下列步驟說明這四種方法。 | DBA | 
| 選項 1：使用負載描述檔。 | 下表顯示 AWR 報告的 Load Profile 區段範例。如需更準確的資訊，建議您使用選項 2 (I/O 設定檔） 或選項 3 （執行個體活動統計資料），而非負載設定檔。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)根據此資訊，您可以計算 IOPs和輸送量，如下所示：*IOPS = 讀取 I/O 請求：\$1 寫入 I/O 請求 = 3，586.8 \$1 574.7 = 4134.5**輸送量 = 實體讀取 （區塊） \$1 實體寫入 （區塊） = 13，575.1 \$1 3，467.3 = 17，042.4*由於 Oracle 中的區塊大小為 8 KB，因此您可以計算總輸送量，如下所示：*MB 的總輸送量為 17042.4 \$1 8 \$1 1024 / 1024 / 1024 = 133.2 MB*請勿使用負載描述檔來估計執行個體大小。它不如執行個體活動統計資料或 I/O 設定檔精確。 | DBA | 
| 選項 2：使用執行個體活動統計資料。 | 如果您使用的是 12c 之前的 Oracle 資料庫版本，則可以使用 AWR 報告的執行個體活動統計資料區段來估計 IOPS 和輸送量。下表顯示本節的範例。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)根據此資訊，您可以計算總 IOPS 和輸送量，如下所示：*總 IOPS = 3，610.28 \$1 757.11 = 4367**總 Mbps = 114，482，426.26 \$1 36，165，631.84 = 150648058.1 / 1024 / 1024 = 143 Mbps* | DBA | 
| 選項 3：使用 I/O 設定檔。 | 在 Oracle Database 12c 中，AWR 報告包含 I/O 設定檔區段，可在單一資料表中呈現所有資訊，並提供更準確的資料庫效能資料。下表顯示本節的範例。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)下表提供輸送量和總 IOPS 的下列值：*輸送量 = 143 MBPS （從第五列，標記為總計，第二欄）**IOPS = 4，367.4 （從第一列，標記為請求總數，第二欄）* | DBA | 
| 選項 4：使用 AWR 檢視。 | 您可以使用 AWR 檢視來查看相同的 IOPS 和輸送量資訊。若要取得此資訊，請使用下列查詢： <pre>break on report<br /> compute sum of Value on report<br /> select METRIC_NAME,avg(AVERAGE) as "Value"<br /> from dba_hist_sysmetric_summary<br /> where METRIC_NAME in ('Physical Read Total IO Requests Per Sec','Physical Write Total IO Requests Per Sec')<br /> group by metric_name;</pre> | DBA | 
|   | 每秒 | 每個交易 | 每個執行 | 每次呼叫 | 
| --- |--- |--- |--- |--- |
| **資料庫時間 (s)：** | 26.6 | 0.2 | 0.00 | 0.02 | 
| **資料庫 CPU (s)：** | 18.0 | 0.1 | 0.00 | 0.01 | 
| **背景 CPU (s)：** | 0.2 | 0.0 | 0.00 | 0.00 | 
| **重做大小 （位元組）：** | 2，458，539.9 | 17，097.5 |   |   | 
| **邏輯讀取 （區塊）：** | 3，371，931.5 | 23，449.6 |   |   | 
| **區塊變更：** | 21，643.5 | 150.5 |   |   | 
| **實體讀取 （區塊）：** | 13，575.1 | 94.4 |   |   | 
| **實體寫入 （區塊）：** | 3，467.3 | 24.1 |   |   | 
| **讀取 IO 請求：** | 3，586.8 | 24.9 |   |   | 
| **寫入 IO 請求：** | 574.7 | 4.0 |   |   | 
| **讀取 IO (MB)：** | 106.1 | 0.7 |   |   | 
| **寫入 IO (MB)：** | 27.1 | 0.2 |   |   | 
| **IM 掃描資料列：** | 0.0 | 0.0 |   |   | 
| **工作階段邏輯讀取即時通訊：** |   |   |   |   | 
| **使用者呼叫：** | 1，245.7 | 8.7 |   |   | 
| **剖析 (SQL)：** | 4，626.2 | 32.2 |   |   | 
| **硬剖析 (SQL)：** | 8.9 | 0.1 |   |   | 
| **SQL 工作區 (MB)：** | 824.9 | 5.7 |   |   | 
| **登入：** | 1.7 | 0.0 |   |   | 
| **執行 (SQL)：** | 136，656.5 | 950.4 |   |   | 
| **轉返：** | 22.9 | 0.2 |   |   | 
| **交易：** | 143.8 |   |   |   | 
| 統計數字 | 總計 | 每秒 | 每個交易 | 
| --- |--- |--- |--- |
| **實體讀取總 IO 請求** | 2，547，333，217 | 3，610.28 | 25.11 | 
| **實體讀取總位元組數** | 80，776，296，124，928 | 114，482，426.26 | 796，149.98 | 
| **實體寫入總 IO 請求** | 534，198，208 | 757.11 | 5.27 | 
| **實體寫入總位元組數** | 25，517，678，849，024 | 36，165，631.84 | 251，508.18 | 
|   | 每秒讀寫數 | 每秒讀取數 | 每秒寫入數 | 
| --- |--- |--- |--- |
| **請求總數：** | 4，367.4 | 3，610.3 | 757.1 | 
| **資料庫請求：** | 4，161.5 | 3，586.8 | 574.7 | 
| **最佳化請求：** | 0.0 | 0.0 | 0.0 | 
| **重做請求：** | 179.3 | 2.8 | 176.6 | 
| **總計 (MB)：** | 143.7 | 109.2 | 34.5 | 
| **資料庫 (MB)：** | 133.1 | 106.1 | 27.1 | 
| **最佳化總計 (MB)：** | 0.0 | 0.0 | 0.0 | 
| **重做 (MB)：** | 7.6 | 2.7 | 4.9 | 
| **資料庫 （區塊）：** | 17，042.4 | 13，575.1 | 3，467.3 | 
| **透過緩衝區快取 （區塊）：** | 5，898.5 | 5，360.9 | 537.6 | 
| **直接 （區塊）：** | 11，143.9 | 8，214.2 | 2，929.7 | 

### 估算 CPU 需求
<a name="estimate-cpu-requirements"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選擇一個方法。 | 您可以透過三種方式估計目標資料庫所需的 CPU：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)如果您正在尋找已使用的核心，我們建議您使用資料庫指標方法，而不是作業系統統計資料，因為它是根據您計劃遷移的資料庫所使用的 CPU。(OS 統計資料也包含其他程序的 CPU 用量。) 您也應該檢查 ADDM 報告中與 CPU 相關的建議，以改善遷移後的效能。您也可以根據 CPU 產生來預估需求。如果您使用的是不同的 CPU 世代，您可以依照白皮書中的說明來預估目標資料庫所需的 CPU [以獲得最佳工作負載效能的 vCPUs 數量](https://d1.awsstatic.com/whitepapers/Demystifying_vCPUs.df200b766578b75009ad8d15c72e493d6408c68a.pdf)。 | DBA | 
| 選項 1：根據可用核心估計需求。 | 在 AWR 報告中：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)您可以透過兩種方式預估可用的核心：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)**使用作業系統命令估計可用的核心**使用以下命令計算處理器中的核心。<pre>$ cat /proc/cpuinfo |grep "cpu cores"|uniq<br />cpu cores    : 4<br />cat /proc/cpuinfo | egrep "core id|physical id" | tr -d "\n" | sed s/physical/\\nphysical/g | grep -v ^$ | sort | uniq | wc -l </pre>使用下列命令計算處理器中的通訊端數量。<pre>grep "physical id" /proc/cpuinfo | sort -u<br />  physical id     : 0<br />  physical id     : 1</pre>  我們不建議使用 **nmon** 和 **sar** 等作業系統命令來擷取 CPU 使用率。這是因為這些計算包含其他程序的 CPU 使用率，可能無法反映資料庫使用的實際 CPU。**使用 AWR 報告預估可用的核心**您也可以從 AWR 報告的第一個區段衍生 CPU 使用率。以下是報告中的摘錄。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)在此範例中，CPUs計數為 80，這表示這些是邏輯 （虛擬） CPUs。您也可以看到此組態有兩個通訊端、每個通訊端上的一個實體處理器 （總共兩個實體處理器），以及每個實體處理器或通訊端的 40 個核心。  | DBA | 
| 選項 2：使用作業系統統計資料估計 CPU 使用率。 | 您可以直接在作業系統 （使用 **sar** 或其他主機作業系統公用程式） 中檢查作業系統 CPU 用量統計資料，也可以從 AWR 報告的作業系統統計資料區段檢閱 IDLE/(IDLE\$1BUSY) 值。您可以查看直接從 **v\$1osstat** 消耗的 CPU 秒數。AWR 和 Statspack 報告也會在作業系統統計資料區段中顯示此資料。如果同一個方塊中有多個資料庫，則它們對於 BUSY\$1TIME 都有相同的 **v\$1osstat** 值。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)如果系統中沒有其他主要 CPU 取用者，請使用下列公式來計算 CPU 使用率的百分比：*使用率 = 忙碌時間/總時間**忙碌時間 = 需求 = v\$1osstat.BUSY\$1TIME**C = 總時間 （忙碌 \$1 閒置）**C = 容量 = v\$1ostat.BUSY\$1TIME \$1 v\$1ostat.IDLE\$1TIME**使用率 = BUSY\$1TIME / (BUSY\$1TIME \$1 IDLE\$1TIME)**= -1，305，569，937 / (1，305，569，937 \$1 4，312，718，839)**= 使用 23%* | DBA | 
| 選項 3：使用資料庫指標估計 CPU 使用率。 | 如果系統中有多個資料庫正在執行，您可以使用出現在報告開頭的資料庫指標。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)若要取得 CPU 使用率指標，請使用此公式：*資料庫 CPU 用量 （可用 CPU 功率的 %) = CPU 時間 / NUM\$1CPUS / 經過時間*其中 CPU 用量是以 *CPU 時間*描述，並代表在 CPU 上花費的時間，而不是等待 CPU 的時間。此計算會導致：*= 312，625.40 / 11，759.64/80 = 正在使用 33% 的 CPU**核心數量 (33%) \$1 80 = 26.4 個核心**總核心 = 26.4 \$1 (120%) = 31.68 個核心*您可以使用這兩個值中的較大值來計算 Amazon RDS 或 Aurora 資料庫執行個體的 CPU 使用率。在 IBM AIX 上，計算的使用率不符合作業系統或資料庫的值。這些值確實符合其他作業系統。 | DBA | 
| 資料庫名稱 | 資料庫 ID | 執行個體 | Inst num | 啟動時間 | 發行版本 | RAC | 
| --- |--- |--- |--- |--- |--- |--- |
| XXXX | <DB\$1ID> | XXXX | 1 | 205-Sep-20 日 23：09 | 12.1.0.2.0 | NO | 
| **Host Name (主機名稱)** | **平台** | **CPUs** | **核心** | **通訊端** | **記憶體 (GB)** | 
| <host\$1name> | Linux x86 64 位元 | 80 | 80 | 2 | 441.78 | 
| 統計數字 | Value | 結束值 | 
| --- |--- |--- |
| **FREE\$1MEMORY\$1BYTES** | 6，810，677，248 | 12，280，799，232 | 
| **INACTIVE\$1MEMORY\$1BYTES** | 175，627，333，632 | 160，380，653，568 | 
| **SWAP\$1FREE\$1BYTES** | 17，145，614，336 | 17，145，872，384 | 
| **BUSY\$1TIME** | 1，305，569，937 |   | 
| **IDLE\$1TIME** | 4，312，718，839 |   | 
| **IOWAIT\$1TIME** | 53，417，174 |   | 
| **NICE\$1TIME** | 29，815 |   | 
| **SYS\$1TIME** | 148，567，570 |   | 
| **USER\$1TIME** | 1，146，918，783 |   | 
| **LOAD** | 25 | 29 | 
| **VM\$1IN\$1BYTES** | 593，920 |   | 
| **VM\$1OUT\$1BYTES** | 327，680 |   | 
| **PHYSICAL\$1MEMORY\$1BYTES** | 474，362，417，152 |   | 
| **NUM\$1CPUS** | 80 |   | 
| **NUM\$1CPU\$1CORES** | 80 |   | 
| **NUM\$1CPU\$1SOCKETS** | 2 |   | 
| **GLOBAL\$1RECEIVE\$1SIZE\$1MAX** | 4，194，304 |   | 
| **GLOBAL\$1SEND\$1SIZE\$1MAX** | 2，097，152 |   | 
| **TCP\$1RECEIVE\$1SIZE\$1DEFAULT** | 87，380 |   | 
| **TCP\$1RECEIVE\$1SIZE\$1MAX** | 6，291，456 |   | 
| **TCP\$1RECEIVE\$1SIZE\$1MIN** | 4,096 |   | 
| **TCP\$1SEND\$1SIZE\$1DEFAULT** | 16,384 |   | 
| **TCP\$1SEND\$1SIZE\$1MAX** | 4，194，304 |   | 
| **TCP\$1SEND\$1SIZE\$1MIN** | 4,096 |   | 
|   | 快照 ID | 快照時間 | 工作階段 | 游標/工作階段 | 
| --- |--- |--- |--- |--- |
| **開始 Snap：** | 184662 | 28-Sep-20 日 09：00：42 | 1226 | 35.8 | 
| **結束快照：** | 185446 | 06-Oct-20 日 13：00：20 | 1876 | 41.1 | 
| **已過：** |   | 11，759.64 （分鐘） |   |   | 
| **資料庫時間：** |   | 312，625.40 （分鐘） |   |   | 

### 估計記憶體需求
<a name="estimate-memory-requirements"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用記憶體統計資料估計記憶體需求。 | 您可以使用 AWR 報告來計算來源資料庫的記憶體，並比對目標資料庫中的記憶體。您也應該檢查現有資料庫的效能，並減少記憶體需求以節省成本，或提高需求以改善效能。這需要詳細分析應用程式的 AWR 回應時間和服務層級協議 (SLA)。使用 Oracle 系統全域區域 (SGA) 和程式全域區域 (PGA) 用量的總和作為 Oracle 的估計記憶體使用率。為作業系統新增額外 20%，以判斷目標記憶體大小需求。對於 Oracle RAC，請使用所有 RAC 節點的估計記憶體使用率總和，並降低總記憶體，因為它存放在常見區塊上。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)*使用中的執行個體記憶體總數 = SGA \$1 PGA = 220 GB \$1 45 GB = 265 GB*新增 20% 的緩衝區：*總執行個體記憶體 = 1.2 \$1 265 GB = 318 GB*由於 SGA 和 PGA 佔主機記憶體的 70%，因此總記憶體需求為： *主機記憶體總數 = 318/0.7 = 464 GB*當您遷移至 Amazon RDS for Oracle 時，PGA 和 SGA 會根據預先定義的公式預先計算。請確定預先計算的值接近您的預估值。 | DBA | 
| 緩衝區 Nowait %： | 99.99 | 重做 NoWait %： | 100.00 | 
| --- |--- |--- |--- |
| **緩衝區命中 %：** | 99.84 | **記憶體內排序 %：** | 100.00 | 
| **Library Hit %：** | 748.77 | **軟剖析 %**： | 99.81 | 
| **執行 以剖析 %：** | 96.61 | **Latch Hit %：** | 100.00 | 
| **剖析 CPU 到剖析重疊 %：** | 72.73 | **非稀疏 CPU %：** | 99.21 | 
| **Flash Cache Hit %：** | 0.00 |   |   | 
|   | Begin | 結束 | 
| --- |--- |--- |
| **主機記憶體 (MB)：** | 452，387.3 | 452，387.3 | 
| **SGA 使用 (MB)：** | 220，544.0 | 220，544.0 | 
| **PGA 使用 (MB)：** | 36，874.9 | 45，270.0 | 

### 判斷目標資料庫的資料庫執行個體類型
<a name="determine-the-db-instance-type-of-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 根據磁碟 I/O、CPU 和記憶體預估值判斷資料庫執行個體類型。 | 根據先前步驟中的預估值，目標 Amazon RDS 或 Aurora 資料庫的容量應為：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.html)在目標 Amazon RDS 或 Aurora 資料庫中，您可以將這些值對應至 db.r5.16xlarge 執行個體類型，其容量為 32 個核心、512 GB RAM 和 13，600 Mbps 的輸送量。如需詳細資訊，請參閱 AWS 部落格文章[根據 Oracle 效能指標大規模調整大小的 Amazon RDS 執行個體](https://aws.amazon.com/blogs/database/right-sizing-amazon-rds-instances-at-scale-based-on-oracle-performance-metrics/)。 | DBA | 

## 相關資源
<a name="estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports-resources"></a>
+ [Aurora 資料庫執行個體類別 ](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Concepts.DBInstanceClass.html)(Amazon Aurora 文件）
+ [Amazon RDS 資料庫執行個體儲存體 ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html)(Amazon RDS 文件）
+ [AWS Miner 工具](https://github.com/tmuth/AWR-Miner/blob/master/release/5.0.8/AWR-Miner-capture-5.0.8/awr_miner.sql) (GitHub 儲存庫）

# 使用 AWS DMS 將 Amazon RDS for SQL Server 資料表匯出至 S3 儲存貯體
<a name="export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms"></a>

*Subhani Shaik，Amazon Web Services*

## 總結
<a name="export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms-summary"></a>

SQL Server 的 Amazon Relational Database Service (Amazon RDS) 不支援將資料載入 Amazon Web Services (AWS) 雲端上的其他資料庫引擎連結伺服器。反之，您可以使用 AWS Database Migration Service (AWS DMS) 將 Amazon RDS for SQL Server 資料表匯出至 Amazon Simple Storage Service (Amazon S3) 儲存貯體，其中資料可供其他資料庫引擎使用。

AWS DMS 可協助您快速且安全地將資料庫遷移至 AWS。來源資料庫在遷移期間保持完全運作，將依賴資料庫的應用程式停機時間降至最低。AWS DMS 可以在最廣泛使用的商業和開放原始碼資料庫之間遷移您的資料。

此模式會在設定 AWS DMS 端點時使用 AWS Secrets Manager。Secrets Manager 可協助您保護存取應用程式、服務和 IT 資源所需的秘密。您可以使用 服務在整個生命週期輪換、管理和擷取資料庫登入資料、API 金鑰和其他秘密。使用者和應用程式透過呼叫 Secrets Manager 來擷取秘密，減少對敏感資訊進行硬式編碼的需求。Secrets Manager 提供秘密輪換與 Amazon RDS、Amazon Redshift 和 Amazon DocumentDB 的內建整合。此外，此服務可延伸至其他類型的秘密，包括 API 金鑰和 OAuth 權杖。透過 Secrets Manager，您可以針對 AWS 雲端、第三方服務和內部部署中的資源，集中使用精細的許可和稽核秘密輪換來控制對秘密的存取。

## 先決條件和限制
<a name="export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ S3 儲存貯體
+ 虛擬私有雲端 (VPC)
+ 資料庫子網路
+ Amazon RDS for SQL Server
+ 代表 Amazon RDS 執行個體存取 （列出、取得和放置物件） 至 S3 儲存貯體的 AWS Identity and Access Management (IAM) 角色。
+ Secrets Manager 存放 RDS 執行個體登入資料。

## Architecture
<a name="export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms-architecture"></a>

**技術堆疊**
+ Amazon RDS for SQL Server
+ AWS DMS
+ Amazon S3
+ AWS Secrets Manager

**目標架構**

下圖顯示 AWS DMS 協助將資料從 Amazon RDS 執行個體匯入 S3 儲存貯體的架構。

![\[描述遵循圖表。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/7ba5756d-44a5-4aa3-97b6-fa3684ae6ce6/images/90f918e1-3ec2-4434-82b8-3ff4ad340fb9.png)


1. 透過來源端點連線至來源 Amazon RDS 執行個體的 AWS DMS 遷移任務

1. 從來源 Amazon RDS 執行個體複製資料

1. 透過目標端點連線至目標 S3 儲存貯體的 AWS DMS 遷移任務

1. 以逗號分隔值 (CSV) 格式將複製的資料匯出至 S3 儲存貯體

## 工具
<a name="export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms-tools"></a>

**AWS 服務**
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 可透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您以 API 呼叫 Secrets Manager，以程式設計方式擷取秘密，取代程式碼中的硬式編碼登入資料，包括密碼。

**其他服務**
+ [Microsoft SQL Server Management Studio (SSMS)](https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-ver16) 是一種用於管理 SQL Server 的工具，包括存取、設定和管理 SQL Server 元件。

## 史詩
<a name="export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms-epics"></a>

### 設定 Amazon RDS for SQL Server 執行個體
<a name="configure-the-amazon-rds-for-sql-server-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon RDS for SQL Server 執行個體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms.html) | DBA，DevOps 工程師 | 
| 設定執行個體的登入資料。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms.html) | DBA，DevOps 工程師 | 
| 設定執行個體類別、儲存體、自動擴展和可用性。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms.html) | DBA，DevOps 工程師 | 
| 指定 VPC、子網路群組、公有存取和安全群組。 | 視需要選取 **VPC**、**資料庫子網路群組**和 **VPC 安全群組**，以建立 Amazon RDS 執行個體。遵循最佳實務，例如：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms.html) | DBA，DevOps 工程師 | 
| 設定監控、備份和維護。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms.html) | DBA，DevOps 工程師 | 

### 設定資料庫和範例資料
<a name="set-up-the-database-and-example-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立資料表並載入範例資料。 | 在新資料庫中，建立資料表。使用*其他資訊*區段中的範例程式碼，將資料載入資料表。 | DBA，DevOps 工程師 | 

### 設定登入資料
<a name="set-up-credentials"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立機密。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms.html)此秘密將用於 AWS DMS 來源端點。 | DBA，DevOps 工程師 | 

### 設定資料庫與 S3 儲存貯體之間的存取權
<a name="set-up-access-between-the-database-and-the-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 IAM 角色以存取 Amazon RDS。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms.html) | DBA，DevOps 工程師 | 

### 建立 S3 儲存貯體
<a name="create-the-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 S3 儲存貯體。 | 若要從 Amazon RDS for SQL Server 儲存資料，請在主控台上選擇 **S3**，然後選擇**建立儲存貯**體。請確定 S3 儲存貯體未公開提供。 | DBA，DevOps 工程師 | 

### 設定 AWS DMS 和 S3 儲存貯體之間的存取權
<a name="set-up-access-between-aws-dms-and-the-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為 AWS DMS 建立 IAM 角色以存取 Amazon S3。 | 建立 IAM 角色，允許 AWS DMS 從 S3 儲存貯體列出、取得和放置物件。 | DBA，DevOps 工程師 | 

### 設定 AWS DMS
<a name="configure-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 AWS DMS 來源端點。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms.html) | DBA，DevOps 工程師 | 
| 建立 AWS DMS 目標端點。 | 建立**目標端點，**選取 Amazon S3 做為**目標引擎**。提供您先前建立之 IAM 角色的 S3 儲存貯體名稱和資料夾名稱。 | DBA，DevOps 工程師 | 
| 建立 AWS DMS 複寫執行個體。 | 在相同的 VPC、子網路和安全群組中，建立 AWS DMS 複寫執行個體。如需選擇執行個體類別的詳細資訊，請參閱 [AWS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.Types.html#CHAP_ReplicationInstance.Types.Deciding)。 | DBA，DevOps 工程師 | 
| 建立 AWS DMS 遷移任務。 | 若要將資料從 Amazon RDS for SQL Server 匯出到 S3 儲存貯體，請建立資料庫遷移任務。針對遷移類型，選擇**遷移現有資料**。選取您建立的 AWS DMS 端點和複寫執行個體。 | DBA，DevOps 工程師 | 

### 將資料匯出至 S3 儲存貯體
<a name="export-the-data-to-the-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 執行資料庫遷移任務。 | 若要匯出 SQL Server 資料表資料，請啟動資料庫遷移任務。任務將以 CSV 格式將資料從 Amazon RDS for SQL Server 匯出至 S3 儲存貯體。 | DBA，DevOps 工程師 | 

### 清除資源
<a name="clean-up-resources"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 刪除 資源。 | 若要避免產生額外費用，請使用 主控台以下列順序刪除資源：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms.html) | DBA，DevOps 工程師 | 

## 相關資源
<a name="export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms-resources"></a>
+ [AWS DMS](https://aws.amazon.com/dms/)
+ [Amazon S3](https://aws.amazon.com/s3/)
+ [Amazon RDS for SQL Server](https://aws.amazon.com/rds/sqlserver/)
+ [Amazon S3 整合](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/oracle-s3-integration.html)

## 其他資訊
<a name="export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms-additional"></a>

若要建立資料庫和資料表，以及載入範例資料，請使用下列程式碼。

```
--Step1: Database creation in RDS SQL Server
CREATE DATABASE [Test_DB]
 ON  PRIMARY
( NAME = N'Test_DB', FILENAME = N'D:\rdsdbdata\DATA\Test_DB.mdf' , SIZE = 5120KB , FILEGROWTH = 10%)
 LOG ON
( NAME = N'Test_DB_log', FILENAME = N'D:\rdsdbdata\DATA\Test_DB_log.ldf' , SIZE = 1024KB , FILEGROWTH = 10%)
GO

--Step2: Create Table
USE Test_DB
GO
Create Table Test_Table(ID int, Company Varchar(30), Location Varchar(20))

--Step3: Load sample data.
USE Test_DB
GO
Insert into Test_Table values(1,'AnyCompany','India')
Insert into Test_Table values(2,'AnyCompany','USA')
Insert into Test_Table values(3,'AnyCompany','UK')
Insert into Test_Table values(4,'AnyCompany','Hyderabad')
Insert into Test_Table values(5,'AnyCompany','Banglore')
```

# 在 Aurora PostgreSQL 中處理動態 SQL 陳述式中的匿名區塊
<a name="handle-anonymous-blocks-in-dynamic-sql-statements-in-aurora-postgresql"></a>

*anuradha chintha，Amazon Web Services*

## 總結
<a name="handle-anonymous-blocks-in-dynamic-sql-statements-in-aurora-postgresql-summary"></a>

注意：Amazon Cloud Directory 不再開放給新客戶。如需 Cloud Directory 的替代方案，請探索 [Amazon DynamoDB](https://aws.amazon.com/dynamodb/) 和 [Amazon Neptune](https://aws.amazon.com/neptune/)。如果您需要協助為您的使用案例選擇正確的替代方案，或有其他問題，請聯絡 [AWS 支援](https://aws.amazon.com/support/)。

此模式說明如何避免在動態 SQL 陳述式中處理匿名區塊時遇到的錯誤。當您使用 AWS Schema Conversion Tool 將 Oracle 資料庫轉換為 Aurora PostgreSQL 相容版本資料庫時，會收到錯誤訊息。為了避免錯誤，您必須知道`OUT`綁定變數的值，但在執行 SQL 陳述式之前，您無法知道`OUT`綁定變數的值。AWS Schema Conversion Tool (AWS SCT) 無法了解動態 SQL 陳述式中的邏輯所產生的錯誤。AWS SCT 無法轉換 PL/SQL 程式碼中的動態 SQL 陳述式 （即函數、程序和套件）。

## 先決條件和限制
<a name="handle-anonymous-blocks-in-dynamic-sql-statements-in-aurora-postgresql-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ [Aurora PostgreSQL 資料庫 （資料庫） 執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Concepts.DBInstanceClass.html)
+ [Oracle 資料庫執行個體的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html)
+ [PostgreSQLinteractive 終端機 (psql)](https://www.postgresql.org/docs/current/app-psql.html)
+ [SQL \$1Plus](https://docs.oracle.com/cd/B14117_01/server.101/b12170/qstart.htm)
+ `AWS_ORACLE_EXT` 目標資料庫中的結構描述 ([AWS SCT 延伸套件](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_ExtensionPack.html)的一部分）
+ 最新版 [AWS Schema Conversion Tool (AWS SCT)](https://aws.amazon.com/dms/schema-conversion-tool/) 及其必要的驅動程式

## Architecture
<a name="handle-anonymous-blocks-in-dynamic-sql-statements-in-aurora-postgresql-architecture"></a>

**來源技術堆疊**
+ 內部部署 Oracle 資料庫 10g 及更新版本

**目標技術堆疊**
+ Amazon Aurora PostgreSQL
+ Amazon RDS for PostgreSQL
+ AWS Schema Conversion Tool (AWS SCT)

**遷移架構**

下圖顯示如何使用 AWS SCT 和 Oracle `OUT`繫結變數來掃描應用程式程式碼以取得內嵌 SQL 陳述式，並將程式碼轉換為 Aurora 資料庫可以使用的相容格式。

![\[使用 AWS SCT 和 Oracle OUT 繫結變數的架構圖\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/ada89410-b866-4d39-af9c-021be6cc6ae5/images/7c004981-2ed0-4b67-989f-54d8691712ca.png)


該圖顯示以下工作流程：

1. 使用 Aurora PostgreSQL 做為目標資料庫，為來源資料庫產生 AWS SCT 報告。

1. 識別動態 SQL 程式碼區塊中的匿名區塊 (AWS SCT 為此引發錯誤）。

1. 手動轉換程式碼區塊，並在目標資料庫上部署程式碼。

## 工具
<a name="handle-anonymous-blocks-in-dynamic-sql-statements-in-aurora-postgresql-tools"></a>

**AWS 服務**
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。
+ [Amazon Relational Database Service (Amazon RDS) for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展 Oracle 關聯式資料庫。
+ [AWS Schema Conversion Tool (AWS SCT)](https://aws.amazon.com/dms/schema-conversion-tool/) 可將來源資料庫結構描述和大部分資料庫程式碼物件自動轉換為與目標資料庫相容的格式，協助您預測異質資料庫遷移。

**其他工具**
+ [pgAdmin](https://www.pgadmin.org/) 可讓您連線至資料庫伺服器並與之互動。
+ [Oracle SQL Developer](https://www.oracle.com/database/sqldeveloper/) 是一種整合的開發環境，可用來開發和管理 Oracle Database 中的資料庫。您可以針對此模式使用 [SQL \$1Plus](https://docs.oracle.com/cd/B19306_01/server.102/b14357/qstart.htm) 或 Oracle SQL Developer。

## 史詩
<a name="handle-anonymous-blocks-in-dynamic-sql-statements-in-aurora-postgresql-epics"></a>

### 設定 Oracle 來源資料庫
<a name="configure-the-oracle-source-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Amazon RDS 或 Amazon EC2 上建立 Oracle 執行個體。 | 若要在 Amazon RDS 上建立 Oracle 資料庫執行個體，請參閱《Amazon RDS 文件》中的[建立 Oracle 資料庫執行個體並連線至 Oracle 資料庫執行個體上的](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.Oracle.html)資料庫。若要在 Amazon Elastic Compute Cloud (Amazon EC2) 上建立 Oracle 資料庫執行個體，請參閱 AWS 規範指引文件中的 [Amazon EC2 for Oracle](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/ec2-oracle.html)。 | DBA | 
| 建立資料庫結構描述和物件以進行遷移。 | 您可以使用 Amazon Cloud Directory 來建立資料庫結構描述。如需詳細資訊，請參閱 Cloud Directory 文件中的[建立結構描述](https://docs.aws.amazon.com/clouddirectory/latest/developerguide/getting_started_create_schema.html)。 | DBA | 
| 設定傳入和傳出安全群組。 | 若要建立和設定安全群組，請參閱 Amazon RDS 文件中的[使用安全群組控制存取](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.RDSSecurityGroups.html)。 | DBA | 
| 確認資料庫正在執行。 | 若要檢查資料庫的狀態，請參閱 [Amazon RDS 文件中的檢視 Amazon RDS 事件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ListEvents.html)。 | DBA | 

### 設定目標 Aurora PostgreSQL 資料庫
<a name="configure-the-target-aurora-postgresql-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Amazon RDS 中建立 Aurora PostgreSQL 執行個體。 | 若要建立 Aurora PostgreSQL 執行個體，請參閱 Amazon RDS 文件中的[建立資料庫叢集並連線至 Aurora PostgreSQL 資料庫叢集](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_GettingStartedAurora.CreatingConnecting.AuroraPostgreSQL.html)上的資料庫。 | DBA | 
| 設定傳入和傳出安全群組。 | 若要建立和設定安全群組，請參閱 Aurora 文件[中的透過建立安全群組來提供 VPC 中資料庫叢集的存取權](https://docs.amazonaws.cn/en_us/AmazonRDS/latest/AuroraUserGuide/CHAP_SettingUp_Aurora.html#CHAP_SettingUp_Aurora.SecurityGroup)。 | DBA | 
| 確認 Aurora PostgreSQL 資料庫正在執行。 | 若要檢查資料庫的狀態，請參閱 Aurora 文件中的[檢視 Amazon RDS 事件](https://docs.amazonaws.cn/en_us/AmazonRDS/latest/AuroraUserGuide/USER_ListEvents.html)。 | DBA | 

### 設定 AWS SCT
<a name="set-up-aws-sct"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 AWS SCT 連線至來源資料庫。 | 若要將 AWS SCT 連線至來源資料庫，請參閱 AWS SCT 文件中的[連線至 PostgreSQL 做為來源](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.PostgreSQL.html#CHAP_Source.PostgreSQL.Connecting)。 | DBA | 
| 將 AWS SCT 連線至目標資料庫。 | 若要將 AWS SCT 連線至目標資料庫，請參閱[《AWS Schema Conversion Tool 使用者指南》中的什麼是 AWS Schema Conversion Tool？](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)。 Schema Conversion Tool  | DBA | 
| 在 AWS SCT 中轉換資料庫結構描述，並將自動轉換的程式碼儲存為 SQL 檔案。 | 若要儲存 AWS SCT 轉換的檔案，請參閱[《AWS 結構描述轉換工具使用者指南》中的在 AWS SCT 中儲存和套用轉換](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Converting.html#CHAP_Converting.SaveAndApply)Schema Conversion Tool。 | DBA | 

### 遷移程式碼
<a name="migrate-the-code"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 取得 SQL 檔案以進行手動轉換。 | 在 AWS SCT 轉換檔案中，提取需要手動轉換的 SQL 檔案。 | DBA | 
| 更新指令碼。 | 手動更新 SQL 檔案。 | DBA | 

## 相關資源
<a name="handle-anonymous-blocks-in-dynamic-sql-statements-in-aurora-postgresql-resources"></a>
+ [Amazon RDS](https://aws.amazon.com/rds/)
+ [Amazon Aurora 功能](https://aws.amazon.com/rds/aurora/postgresql-features/)

## 其他資訊
<a name="handle-anonymous-blocks-in-dynamic-sql-statements-in-aurora-postgresql-additional"></a>

下列範例程式碼示範如何設定 Oracle 來源資料庫：

```
CREATE or replace PROCEDURE calc_stats_new1 (
  a NUMBER,
  b NUMBER,
  result out NUMBER)
IS
BEGIN
result:=a+b;
END;
/
```

```
set serveroutput on ;
 
DECLARE
  a NUMBER := 4;
  b NUMBER := 7;
  plsql_block VARCHAR2(100);
  output number;
BEGIN
  plsql_block := 'BEGIN calc_stats_new1(:a, :b,:output); END;';
  EXECUTE IMMEDIATE plsql_block USING a, b,out output;  
  DBMS_OUTPUT.PUT_LINE('output:'||output);
 
END;
```

下列範例程式碼示範如何設定目標 Aurora PostgreSQL 資料庫：

```
 w integer,
 x integer)
RETURNS integer
AS
$BODY$
DECLARE
begin
return w + x ;
end;
$BODY$
LANGUAGE  plpgsql;
 
 
CREATE OR REPLACE FUNCTION test_pg.init()
RETURNS void
AS
$BODY$
BEGIN
if aws_oracle_ext.is_package_initialized
      ('test_pg' ) then
      return;
    end if;
    perform aws_oracle_ext.set_package_initialized
      ('test_pg' );
 
PERFORM aws_oracle_ext.set_package_variable('test_pg', 'v_output', NULL::INTEGER);
PERFORM aws_oracle_ext.set_package_variable('test_pg', 'v_status', NULL::text);
END;
$BODY$
LANGUAGE  plpgsql;
 

DO $$ 
declare
v_sql text;
v_output_loc int; 
a integer :=1;
b integer :=2;
BEGIN 
perform  test_pg.init();
--raise notice 'v_sql %',v_sql;
execute 'do $a$ declare v_output_l int; begin select * from test_pg.calc_stats_new1('||a||','||b||') into v_output_l;
PERFORM aws_oracle_ext.set_package_variable(''test_pg'', ''v_output'', v_output_l) ; end; $a$'  ; 
v_output_loc := aws_oracle_ext.get_package_variable('test_pg', 'v_output');
raise notice 'v_output_loc %',v_output_loc; 
END ; 
$$
```

# 協助強制執行 DynamoDB 標記
<a name="help-enforce-dynamodb-tagging"></a>

*Mansi Suratwala，Amazon Web Services*

## 總結
<a name="help-enforce-dynamodb-tagging-summary"></a>

此模式會在預先定義的 Amazon DynamoDB 標籤遺失或從 Amazon Web Services (AWS) 雲端上的 DynamoDB 資源中移除時設定自動通知。 

DynamoDB 是全受管的 NoSQL 資料庫服務，可提供快速且可預測的效能與可擴展性。DynamoDB 可讓您卸載操作和擴展分散式資料庫的管理負擔。當您使用 DynamoDB 時，不必擔心硬體佈建、設定和組態、複寫、軟體修補或叢集擴展。

模式使用 AWS CloudFormation 範本，這會建立 Amazon CloudWatch Events 事件和 AWS Lambda 函數。事件會使用 AWS CloudTrail 來監控任何新的或現有的 DynamoDB 標記資訊。如果遺失或移除預先定義的標籤，CloudWatch 會觸發 Lambda 函數，這會傳送 Amazon Simple Notification Service (Amazon SNS) 通知給您，通知您違規。 

## 先決條件和限制
<a name="help-enforce-dynamodb-tagging-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Lambda .zip 檔案的 Amazon Simple Storage Service (Amazon S3) 儲存貯體，其中包含執行 Lambda 函數的 Python 指令碼

**限制**
+ 解決方案只有在 `TagResource`或 `UntagResource` CloudTrail 事件發生時才有效。它不會為任何其他事件建立通知。

## Architecture
<a name="help-enforce-dynamodb-tagging-architecture"></a>

**目標技術堆疊**
+ Amazon DynamoDB
+ AWS CloudTrail
+ Amazon CloudWatch
+ AWS Lambda
+ Amazon S3
+ Amazon SNS

**目標架構**

![\[缺少 DynamoDB 標籤會觸發 CloudWatch 事件和 Lambda 函數來傳送 Amazon SNS 通知。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/638d2b87-e031-4a53-8677-2d62e563746b/images/acc448c5-c39b-40b7-94c0-3534d2e725d7.png)


**自動化和擴展**

您可以針對不同的 AWS 區域和帳戶多次使用 AWS CloudFormation 範本。您只需要在每個區域或帳戶中執行範本一次。

## 工具
<a name="help-enforce-dynamodb-tagging-tools"></a>

**工具**
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) – DynamoDB 是全受管的 NoSQL 資料庫服務，可提供快速且可預測的效能與可擴展性。 
+ [AWS CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html) – CloudTrail 是一種 AWS 服務，可協助您進行 AWS 帳戶的控管、合規以及操作和風險稽核。使用者、角色或 AWS 服務所執行的動作會在 CloudTrail 中記錄為事件。 
+ [Amazon CloudWatch Events](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html) – Amazon CloudWatch Events 提供近乎即時的系統事件串流，說明 AWS 資源的變更。 
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) – Lambda 是一種運算服務，支援執行程式碼，而不需要佈建或管理伺服器。Lambda 只有在需要時才會執行程式碼，可自動從每天數項請求擴展成每秒數千項請求。 
+ [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html) – Amazon Simple Storage Service (Amazon S3) 是一種高度可擴展的物件儲存服務，可用於各種儲存解決方案，包括網站、行動應用程式、備份和資料湖。
+ [Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) – Amazon Simple Notification Service (Amazon SNS) 是一種 Web 服務，可讓應用程式、最終使用者和裝置立即從雲端傳送和接收通知。 

**Code**
+ 專案的 .zip 檔案可做為附件使用。

## 史詩
<a name="help-enforce-dynamodb-tagging-epics"></a>

### 定義 S3 儲存貯體
<a name="define-the-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 定義 S3 儲存貯體。 | 在 Amazon S3 主控台上，選擇或建立具有不包含正斜線之唯一名稱的 S3 儲存貯體。此 S3 儲存貯體將託管 Lambda 程式碼 .zip 檔案。您的 S3 儲存貯體必須與受監控的 DynamoDB 資源位於相同的 AWS 區域。 | 雲端架構師 | 

### 將 Lambda 程式碼上傳至 S3 儲存貯體
<a name="upload-the-lambda-code-to-the-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 Lambda 程式碼上傳至 S3 儲存貯體。 | 將*附件*區段中提供的 Lambda 程式碼 .zip 檔案上傳至 S3 儲存貯體。S3 儲存貯體必須與受監控的 DynamoDB 資源位於相同的區域。 | 雲端架構師 | 

### 部署 AWS CloudFormation 範本
<a name="deploy-the-aws-cloudformation-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 部署 AWS CloudFormation 範本。 | 在 AWS CloudFormation 主控台上，部署*附件*區段中提供的 AWS CloudFormation 範本。在下一個史詩中，提供參數的值。 | 雲端架構師  | 

### 完成 AWS CloudFormation 範本中的參數
<a name="complete-the-parameters-in-the-aws-cloudformation-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 命名 S3 儲存貯體。 | 輸入您在第一個史詩中建立或選擇的 S3 儲存貯體名稱。 | 雲端架構師 | 
| 提供 Amazon S3 金鑰。 | 提供 Lambda 程式碼 .zip 檔案在 S3 儲存貯體中的位置，不帶正斜線 （例如 `<folder>/<file-name>.zip`)。 | 雲端架構師 | 
| 提供電子郵件地址 | 提供作用中的電子郵件地址以接收 Amazon SNS 通知。 | 雲端架構師  | 
| 定義記錄層級。 | 定義 Lambda 函數的記錄層級和頻率。 會`Info`指定應用程式進度的詳細資訊訊息。 會`Error`指定仍可允許應用程式繼續執行的錯誤事件。 會`Warning`指定可能有害的情況。 | 雲端架構師 | 
| 輸入所需的 DynamoDB 標籤金鑰。 | 請確定標籤以逗號分隔，中間沒有空格 （例如 `ApplicationId,CreatedBy,Environment,Organization`)。CloudWatch Events 事件會搜尋這些標籤，並在找不到它們時傳送通知。 | 雲端架構師 | 

### 確認訂閱。
<a name="confirm-the-subscription"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 確認訂閱。 | 當範本成功部署時，它會傳送訂閱電子郵件到您提供的電子郵件地址。若要接收違規通知，您必須確認此電子郵件訂閱。 | 雲端架構師  | 

## 相關資源
<a name="help-enforce-dynamodb-tagging-resources"></a>
+ [建立 S3 儲存貯體](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/create-bucket.html)
+ [將檔案上傳至 S3 儲存貯體](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/upload-objects.html) 
+ [DynamoDB 中的標記資源](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tagging.Operations.html)
+ [使用 AWS CloudTrail 建立在 AWS API 呼叫上觸發的 CloudWatch Events 規則 CloudTrail](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/Create-CloudWatch-Events-CloudTrail-Rule.html)

## 附件
<a name="attachments-638d2b87-e031-4a53-8677-2d62e563746b"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/638d2b87-e031-4a53-8677-2d62e563746b/attachments/attachment.zip)

# 使用 AWS DMS 和 Amazon Aurora 實作跨區域災難復原
<a name="implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora"></a>

*Mark Hudson，Amazon Web Services*

## 總結
<a name="implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora-summary"></a>

自然或人為造成的災難可能隨時發生，並可能影響在特定 AWS 區域中執行之服務和工作負載的可用性。若要降低風險，您必須開發災難復原 (DR) 計畫，其中包含 AWS 服務的內建跨區域功能。對於本質上不提供跨區域功能的 AWS 服務，DR 計畫也必須提供解決方案來處理跨 AWS 區域的容錯移轉。

此模式會引導您完成災難復原設定，其中涉及單一區域中的兩個 Amazon Aurora MySQL 相容版本資料庫叢集。為了符合 DR 需求，資料庫叢集會設定為使用 Amazon Aurora 全域資料庫功能，而單一資料庫跨越多個 AWS 區域。AWS Database Migration Service (AWS DMS) 任務會在本機區域中的叢集之間複寫資料。不過，AWS DMS 目前不支援區域之間的任務容錯移轉。此模式包含解決該限制和在兩個區域中獨立設定 AWS DMS 所需的步驟。

## 先決條件和限制
<a name="implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora-prereqs"></a>

**先決條件**
+ 選取支援 [Amazon Aurora 全域資料庫的主要和次要 AWS](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Concepts.AuroraFeaturesRegionsDBEngines.grids.html#Concepts.Aurora_Fea_Regions_DB-eng.Feature.GlobalDatabase) 區域。
+ 主要區域中單一帳戶中的兩個獨立 Amazon Aurora MySQL 相容版本資料庫叢集。
+ 資料庫執行個體類別 db.r5 或更新版本 （建議）。
+ 主要區域中的 AWS DMS 任務，在現有資料庫叢集之間執行持續複寫。
+ 已備妥 DR 區域資源，以符合建立資料庫執行個體的需求。如需詳細資訊，請參閱[在 VPC 中使用資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html)。

**限制**
+ 如需 Amazon Aurora 全域資料庫限制的完整清單，請參閱 [Amazon Aurora 全域資料庫的限制](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html#aurora-global-database.limitations)。

**產品版本**
+ Amazon Aurora MySQL 相容版本 5.7 或 8.0。如需詳細資訊，請參閱[Amazon Aurora 版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.VersionPolicy.html)。

## Architecture
<a name="implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora-architecture"></a>

**目標技術堆疊**
+ Amazon Aurora MySQL 相容版本全域資料庫叢集
+ AWS DMS

**目標架構**

下圖顯示兩個 AWS 區域的全域資料庫，一個具有主要主資料庫和報告程式資料庫和 AWS DMS 複寫，另一個具有次要主資料庫和報告程式資料庫。

![\[跨區域全域資料庫的架構圖。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/b01f5043-fcb5-4b1e-b79f-999792e89bed/images/3785384c-ed01-454f-b58c-fa09d223d57b.png)


**自動化和擴展**

您可以使用 AWS CloudFormation 在次要區域中建立先決條件基礎設施，例如虛擬私有雲端 (VPC)、子網路和參數群組。您也可以使用 AWS CloudFormation 在 DR 區域中建立次要叢集，並將其新增至全域資料庫。如果您使用 CloudFormation 範本在主要區域中建立資料庫叢集，您可以使用其他範本更新或增強這些叢集，以建立全域資料庫資源。如需詳細資訊，請參閱[使用兩個資料庫執行個體建立 Amazon Aurora 資料庫叢集](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html#aws-resource-rds-dbcluster--examples)和[為 Aurora MySQL 建立全域資料庫叢集](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-globalcluster.html#aws-resource-rds-globalcluster--examples)。

最後，您可以在容錯移轉和容錯回復事件發生後，使用 CloudFormation 在主要和次要區域中建立 AWS DMS 任務。如需詳細資訊，請參閱[AWS::DMS::ReplicationTask](https://docs.amazonaws.cn/en_us/AWSCloudFormation/latest/UserGuide/aws-resource-dms-replicationtask.html)。

## 工具
<a name="implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora-tools"></a>
+ [Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html) 是全受管關聯式資料庫引擎，與 MySQL 和 PostgreSQL 相容。此模式使用 Amazon Aurora MySQL 相容版本。
+ [Amazon Aurora 全域資料庫](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html)專為全域分散式應用程式而設計。單一 Amazon Aurora 全域資料庫可以跨越多個 AWS 區域。它會複寫您的資料，而不會影響資料庫效能。它還在每個區域中啟用具有低延遲的快速本機讀取，並從整個區域的中斷提供災難復原。
+ [AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 提供一次性遷移或持續複寫。持續複寫任務可讓您的來源和目標資料庫保持同步。設定之後，進行中的複寫任務會持續將來源變更套用至目標，並將延遲降至最低。資料驗證和轉換等所有 AWS DMS 功能都可用於任何複寫任務。

## 史詩
<a name="implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora-epics"></a>

### 準備主要區域中現有的資料庫叢集
<a name="prepare-the-existing-database-clusters-in-the-primary-region"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 修改資料庫叢集參數群組。 | 在現有的資料庫叢集參數群組中，將 `binlog_format` 參數設定為資料列的值，以啟用**資料列**層級二進位記錄。執行持續複寫或變更資料擷取 (CDC) 時，AWS DMS 需要 MYSQL 相容資料庫的資料列層級二進位記錄。如需詳細資訊，請參閱[使用 AWS 受管 MySQL 相容資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.MySQL.html#CHAP_Source.MySQL.AmazonManaged)。 | AWS 管理員 | 
| 更新資料庫二進位日誌保留期。 | 使用安裝在最終使用者裝置或 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的 MySQL 用戶端，在主要資料庫叢集的寫入器節點上執行 Amazon Relational Database Service (Amazon RDS) 提供的下列預存程序，其中 `XX`是保留日誌的時數。<pre>call mysql.rds_set_configuration('binlog retention hours', XX)</pre>執行下列命令以確認設定。<pre>call mysql.rds_show_configuration;</pre>AWS 管理的 MySQL 相容資料庫會盡快清除二進位日誌。因此，保留期間必須足夠長，以確保日誌不會在 AWS DMS 任務執行之前清除。值為 24 小時通常就已足夠，但值應以在 DR 區域中設定 AWS DMS 任務所需的時間為基礎。 | DBA | 

### 更新主要區域中現有的 AWS DMS 任務
<a name="update-the-existing-aws-dms-task-in-the-primary-region"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 記錄 AWS DMS 任務 ARN。 | 使用 Amazon Resource Name (ARN) 取得 AWS DMS 任務名稱以供日後使用。若要擷取 AWS DMS 任務 ARN，請在主控台中檢視任務或執行下列命令。<pre>aws dms describe-replication-tasks</pre>ARN 如下所示。<pre>arn:aws:dms:us-east-1:<accountid>:task:AN6HFFMPM246XOZVEUHCNSOVF7MQCLTOZUIRAMY</pre>最後一個冒號後面的字元對應於後續步驟中使用的任務名稱。 | AWS 管理員 | 
| 修改現有的 AWS DMS 任務以記錄檢查點。 | AWS DMS 會建立包含資訊的檢查點，以便複寫引擎知道變更串流的復原點。若要記錄檢查點資訊，請在 主控台中執行下列步驟：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora.html) | AWS 管理員 | 
| 驗證檢查點資訊。 | 使用連線至叢集寫入器端點的 MySQL 用戶端，查詢報告器資料庫叢集中的新中繼資料表，以確認其存在並包含複寫狀態資訊。執行下列命令。<pre>select * from awsdms_control.awsdms_txn_state;</pre>來自 ARN 的任務名稱應該在 `Task_Name` 欄中的此表格中找到。 | DBA | 

### 將兩個 Amazon Aurora 叢集展開至 DR 區域
<a name="expand-both-amazon-aurora-clusters-to-a-dr-region"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 DR 區域中建立基礎基礎設施。 | 建立和存取 Amazon Aurora 叢集所需的基本元件：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora.html)確定兩個參數群組的組態都符合主要區域中的組態。 | AWS 管理員 | 
| 將 DR 區域新增至兩個 Amazon Aurora 叢集。 | 將次要區域 (DR 區域） 新增至主要和報告者 Amazon Aurora 叢集。如需詳細資訊，請參閱[將 AWS 區域新增至 Amazon Aurora 全域資料庫](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-getting-started.html#aurora-global-database-attaching)。 | AWS 管理員 | 

### 執行容錯移轉
<a name="perform-failover"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止 AWS DMS 任務。 | 容錯移轉發生後，主要區域中的 AWS DMS 任務將無法正常運作，且應停止以避免錯誤。 | AWS 管理員 | 
| 執行受管容錯移轉。 | 執行主資料庫叢集的受管容錯移轉至 DR 區域。如需說明，請參閱[執行 Amazon Aurora 全域資料庫的受管計劃容錯移轉](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-disaster-recovery.html#aurora-global-database-disaster-recovery.managed-failover)。主要資料庫叢集上的容錯移轉完成後，請在報告者資料庫叢集上執行相同的活動。 | AWS 管理員，DBA | 
| 將資料載入主資料庫。 | 將測試資料插入 DR 資料庫叢集中主要資料庫的寫入器節點。此資料將用於驗證複寫是否正常運作。 | DBA | 
| 建立 AWS DMS 複寫執行個體。 | 若要在 DR 區域中建立 AWS DMS 複寫執行個體，請參閱[建立複寫執行個體](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.Creating.html)。 | AWS 管理員，DBA | 
| 建立 AWS DMS 來源和目標端點。 | 若要在 DR 區域中建立 AWS DMS 來源和目標端點，請參閱[建立來源和目標端點](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.Creating.html)。來源應指向主要資料庫叢集的寫入器執行個體。目標應指向報告者資料庫叢集的寫入器執行個體。 | AWS 管理員，DBA | 
| 取得複寫檢查點。 | 若要取得複寫檢查點，請使用 MySQL 用戶端，針對 DR 區域中報告者資料庫叢集中的寫入器節點執行下列動作來查詢中繼資料表。<pre>select * from awsdms_control.awsdms_txn_state;</pre>在表格中，尋找對應於 AWS DMS 任務 ARN 的 task\$1name 值，該 ARN 存在於您在第二個特徵中取得的主要區域中。 | DBA | 
| 建立 AWS DMS 任務。 | 使用 主控台，在 DR 區域中建立 AWS DMS 任務。在任務中，指定**僅複寫資料變更**的遷移方法。如需詳細資訊，請參閱[建立任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.Creating.html)。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora.html)將 AWS DMS 任務**開始遷移任務**設定為**建立時自動**。 | AWS 管理員，DBA | 
| 記錄 AWS DMS 任務 ARN。 | 使用 ARN 取得 AWS DMS 任務名稱以供日後使用。若要擷取 AWS DMS 任務 ARN，請執行下列命令。<pre>aws dms describe-replication-tasks</pre> | AWS 管理員，DBA | 
| 驗證複寫的資料。 | 查詢 DR 區域中的報告程式資料庫叢集，確認您載入主資料庫叢集的測試資料已複寫。 | DBA | 

### 執行容錯回復
<a name="perform-failback"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止 AWS DMS 任務。 | 發生容錯移轉後，DR 區域中的 AWS DMS 任務將無法正常運作，且應停止以避免錯誤。 | AWS 管理員 | 
| 執行受管容錯回復。 | 將主要資料庫叢集容錯移轉回主要區域。如需說明，請參閱[執行 Amazon Aurora 全域資料庫的受管計劃容錯移轉](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database-disaster-recovery.html#aurora-global-database-disaster-recovery.managed-failover)。主資料庫叢集上的容錯回復完成後，請在報告者資料庫叢集上執行相同的活動。 | AWS 管理員，DBA | 
| 取得複寫檢查點。 | 若要取得複寫檢查點，請使用 MySQL 用戶端，針對 DR 區域中報告者資料庫叢集中的寫入器節點執行下列動作來查詢中繼資料表。<pre>select * from awsdms_control.awsdms_txn_state;</pre>在表格中，尋找對應到 AWS DMS 任務 ARN `task_name`的值，該 ARN 存在於您在第四個 epic 中取得的 DR 區域中。 | DBA | 
| 更新 AWS DMS 來源和目標端點。 | 資料庫叢集故障後，請檢查主要區域中的叢集，以判斷哪些節點是寫入器執行個體。然後，確認主要區域中現有的 AWS DMS 來源和目標端點指向寫入器執行個體。如果沒有，請使用寫入器執行個體網域名稱系統 (DNS) 名稱更新端點。 | AWS 管理員 | 
| 建立 AWS DMS 任務。 | 使用 主控台，在主要區域中建立 AWS DMS 任務。在任務中，指定**僅複寫資料變更**的遷移方法。如需詳細資訊，請參閱[建立任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.Creating.html)。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora.html) | AWS 管理員，DBA | 
| 記錄 AWS DMS 任務 Amazon Resource Name (ARN)。 | 使用 ARN 取得 AWS DMS 任務名稱以供日後使用。若要擷取 AWS DMS 任務 ARN，請執行下列命令：<pre>aws dms describe-replication-tasks</pre>執行另一個受管容錯移轉或在 DR 案例期間，將需要任務名稱。 | AWS 管理員，DBA | 
| 刪除 AWS DMS 任務。 | 刪除主要區域中的原始 （目前停止） AWS DMS 任務，以及次要區域中的現有 AWS DMS 任務 （目前停止）。 | AWS 管理員 | 

## 相關資源
<a name="implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora-resources"></a>
+ [設定 Amazon Aurora 資料庫叢集](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraSettingUp.html)
+ [使用 Amazon Aurora 全球資料庫](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html)
+ [使用 Amazon Aurora MySQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraMySQL.html)
+ [使用 AWS DMS 複寫執行個體](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_ReplicationInstance.html)
+ [使用 AWS DMS 端點](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.html)
+ [使用 AWS DMS 任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.html)
+ [什麼是 AWS CloudFormation？](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)

## 其他資訊
<a name="implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora-additional"></a>

Amazon Aurora 全域資料庫在此範例中用於 DR，因為它們提供 1 秒的有效復原時間目標 (RTO) 和不到 1 分鐘的復原點目標 (RPO)，兩者都低於傳統的複寫解決方案，非常適合 DR 案例。

Amazon Aurora 全域資料庫提供許多其他優點，包括下列項目：
+ 具有本機延遲的全域讀取 – 全球消費者可以使用本機延遲存取本機區域中的資訊。
+ 可擴展的次要 Amazon Aurora 資料庫叢集 – 次要叢集可以獨立擴展，最多可新增 16 個唯讀複本。
+ 從主要叢集快速複寫到次要 Amazon Aurora 資料庫叢集 – 複寫對主要叢集的效能影響很小。它發生在儲存層，典型的跨區域複寫延遲少於 1 秒。

此模式也使用 AWS DMS 進行複寫。Amazon Aurora 資料庫提供建立僅供讀取複本的功能，可簡化複寫程序和 DR 設定。不過，當需要資料轉換或目標資料庫需要來源資料庫沒有的其他索引時，AWS DMS 通常用於複寫。

# 將具有超過 100 個引數的 Oracle 函數和程序遷移至 PostgreSQL
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql"></a>

*Srinivas Potlachervoo，Amazon Web Services*

## 總結
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-summary"></a>

此模式說明如何將具有超過 100 個引數的 Oracle 資料庫函數和程序遷移至 PostgreSQL。例如，您可以使用此模式將 Oracle 函數和程序遷移至下列其中一個 PostgreSQL 相容 AWS 資料庫服務：
+ PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)
+ Amazon Aurora PostgreSQL-Compatible Edition

PostgreSQL 不支援具有超過 100 個引數的函數或程序。做為解決方法，您可以定義具有符合來源函數引數之類型欄位的新資料類型。然後，您可以建立並執行使用自訂資料類型做為引數的 PL/pgSQL 函數。

## 先決條件和限制
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ [Amazon RDS Oracle 資料庫 (DB) 執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html)
+ [Amazon RDS for PostgreSQL 資料庫執行個體](https://aws.amazon.com/getting-started/hands-on/create-connect-postgresql-db/)或 [Aurora PostgreSQL 相容資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_GettingStartedAurora.CreatingConnecting.AuroraPostgreSQL.html)

**產品版本**
+ Amazon RDS Oracle 資料庫執行個體 10.2 版及更新版本
+ Amazon RDS PostgreSQL 資料庫執行個體 9.4 版及更新版本，或 Aurora PostgreSQL 相容資料庫執行個體 9.4 版及更新版本
+ Oracle SQL Developer 18 版及更新版本
+ pgAdmin 第 4 版及更新版本

## Architecture
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-architecture"></a>

**來源技術堆疊**
+ Amazon RDS Oracle 資料庫執行個體 10.2 版及更新版本

**目標技術堆疊**
+ Amazon RDS PostgreSQL 資料庫執行個體 9.4 版及更新版本，或 Aurora PostgreSQL 相容資料庫執行個體 9.4 版及更新版本

## 工具
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-tools"></a>

**AWS 服務**
+ [適用於 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS) ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html)可協助您在 AWS 雲端中設定、操作和擴展 PostgreSQL 關聯式資料庫。
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。

**其他服務**
+ [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) 是一種整合的開發環境，可簡化傳統和雲端部署中 Oracle 資料庫的開發和管理。
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。

## 最佳實務
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-best-practices"></a>

請確定您建立的資料類型符合來源 Oracle 函數或程序中包含的類型欄位。

## 史詩
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-epics"></a>

### 執行具有超過 100 個引數的 Oracle 函數或程序
<a name="run-an-oracle-function-or-procedure-that-has-more-than-100-arguments"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立或識別具有超過 100 個引數的現有 Oracle/PLSQL 函數或程序。 | 建立具有超過 100 個引數的 Oracle/PLSQL 函數或程序。-或-識別具有超過 100 個引數的現有 Oracle/PLSQL 函數或程序。如需詳細資訊，請參閱 Oracle 資料庫文件中的第 [14.7 節 CREATE FUNCTION 陳述式](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/lnpls/CREATE-FUNCTION-statement.html#GUID-B71BC5BD-B87C-4054-AAA5-213E856651F2)和 [14.11 CREATE PROCEDURE 陳述式。](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/lnpls/CREATE-PROCEDURE-statement.html#GUID-5F84DB47-B5BE-4292-848F-756BF365EC54) | Oracle/PLSQL 知識 | 
| 編譯 Oracle/PLSQL 函數或程序。 | 編譯 Oracle/PLSQL 函數或程序。如需詳細資訊，請參閱 Oracle 資料庫文件中[的編譯函數](https://docs.oracle.com/cd/E37097_01/doc.42/e35128/GUID-6B7B6F82-616D-4915-82BE-D4AE7F59CF37.htm#AEUTL165)。 | Oracle/PLSQL 知識 | 
| 執行 Oracle/PLSQL 函數。 | 執行 Oracle/PLSQL 函數或程序。然後，儲存輸出。 | Oracle/PLSQL 知識 | 

### 定義符合來源函數或程序引數的新資料類型
<a name="define-a-new-data-type-that-matches-the-source-functionapos-s-or-procedureapos-s-arguments"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 PostgreSQL 中定義新的資料類型。 | 在 PostgreSQL 中定義新的資料類型，其中包含出現在來源 Oracle 函數或程序引數中的所有相同欄位。如需詳細資訊，請參閱 PostgreSQL 文件中的 [CREATE TYPE](https://www.postgresql.org/docs/current/sql-createtype.html)。 | PostgreSQL PL/pgSQL 知識 | 

### 建立 PostgreSQL 函數，其中包含新的 TYPE 引數
<a name="create-a-postgresql-function-that-includes-the-new-type-argument"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立包含新資料類型的 PostgreSQL 函數。 | 建立包含新`TYPE`引數的 PostgreSQL 函數。若要檢閱範例函數，請參閱此模式**的其他資訊**區段。 | PostgreSQL PL/pgSQL 知識 | 
| 編譯 PostgreSQL 函數。 | 在 PostgreSQL 中編譯 函數。如果新的資料類型欄位符合來源函數的 或程序的引數，則函數會成功編譯。 | PostgreSQL PL/pgSQL 知識 | 
| 執行 PostgreSQL 函數。 | 執行 PostgreSQL 函數。 | PostgreSQL PL/pgSQL 知識 | 

## 疑難排解
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 函數會傳回下列錯誤：**錯誤：「<statement>」附近的語法錯誤** | 確定所有函數的陳述式都以分號 () 結尾`;`。 | 
| 函數會傳回下列錯誤：**錯誤：「<variable>」不是已知的變數** | 確定函數內文中使用的變數已列在函數的 `DECLARE`區段中。 | 

## 相關資源
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-resources"></a>
+ [使用 Amazon Aurora PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html) (*Amazon Aurora 使用者指南*)
+ [CREATE TYPE](https://www.postgresql.org/docs/11/sql-createtype.html) (PostgreSQL 文件）

## 其他資訊
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-additional"></a>

**包含 TYPE 引數的範例 PostgreSQL 函數**

```
CREATE OR REPLACE FUNCTION test_proc_new
(
    IN p_rec type_test_proc_args
) 
RETURNS void
AS
$BODY$
BEGIN

    /*
    **************
    The body would contain code to process the input values.
    For our testing, we will display couple of values.
    ***************
    */
    RAISE NOTICE USING MESSAGE = CONCAT_WS('', 'p_acct_id: ', p_rec.p_acct_id);
    RAISE NOTICE USING MESSAGE = CONCAT_WS('', 'p_ord_id: ', p_rec.p_ord_id);
    RAISE NOTICE USING MESSAGE = CONCAT_WS('', 'p_ord_date: ', p_rec.p_ord_date);
   
END;
$BODY$
LANGUAGE plpgsql 
COST 100;
```

# 將 Redis 工作負載遷移至 AWS 上的 Redis Enterprise Cloud
<a name="migrate-redis-workloads-to-redis-enterprise-cloud-on-aws"></a>

*Antony Prasad Thevaraj，Amazon Web Services*

*Srinivas Pendyala，Redis*

## 總結
<a name="migrate-redis-workloads-to-redis-enterprise-cloud-on-aws-summary"></a>

此模式討論將 Redis 工作負載遷移至 Redis Enterprise Cloud on Amazon Web Services (AWS) 的高階程序。它描述了遷移步驟，提供有關選擇可用工具的資訊，並討論了使用每個工具的優點、缺點和步驟。或者，如果您需要從 Redis 遷移工作負載的其他協助，您可以與 Redis Professional Services 互動。

如果您在內部部署執行 Redis OSS 或 Redis Enterprise Software，您會熟悉在資料中心維護 Redis 資料庫的重大管理開銷和操作複雜性。透過將工作負載遷移至雲端，您可以大幅減輕營運負擔，並利用 [Redis Enterprise Cloud](https://redis.com/redis-enterprise-cloud/overview/)，這是 Redis 的全託管資料庫即服務 (DBaaS) 產品。此遷移有助於提高業務敏捷性、改善應用程式可靠性，並降低整體成本，同時您可以存取最新的 Redis Enterprise Cloud on AWS 功能，例如 99.999% 的可用性、架構簡單性和擴展性。

金融服務、零售、醫療保健和遊戲領域以及需要詐騙偵測、即時清查、索賠處理和工作階段管理解決方案的使用案例中，都有 Redis Enterprise Cloud 的潛在應用程式。您可以使用 Redis Enterprise Cloud 連線至您的 AWS 資源，例如，連線至在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上執行的應用程式伺服器，或連線到部署為 AWS Lambda 服務的微服務。

## 先決條件和限制
<a name="migrate-redis-workloads-to-redis-enterprise-cloud-on-aws-prereqs"></a>

**假設**
+ 您目前正在操作要遷移至雲端的內部部署資料庫系統。
+ 您已識別工作負載的遷移需求，包括：
  + 資料一致性需求
  + 基礎設施和系統環境需求
  + 資料映射和轉換需求
  + 功能測試要求
  + 效能測試要求
  + 驗證要求
  + 定義的切換策略
+ 您已評估遷移所需的時間表和成本估算。
+ 您的需求會考量工作範圍，以及您識別為遷移一部分的系統和資料庫。
+ 您已在負責、負責、諮詢、告知 (RACI) 矩陣中識別利益相關者及其角色和責任。
+ 您已收到所有利益相關者的必要協議和核准。

**成本**

根據現有來源資料庫的技術規格 （例如記憶體大小、輸送量和總資料大小），Redis 解決方案架構師可以在 Redis Enterprise Cloud 上調整目標系統的大小。 如需一般定價資訊，請參閱 [Redis 網站上的 Redis 定價](https://redis.com/redis-enterprise-cloud/pricing)。

**人員和技能**

遷移程序涉及下列角色和責任。


| 
| 
| Role | Description | 所需的技能 | 
| --- |--- |--- |
| **遷移解決方案架構師** | 具備定義、規劃和實作遷移策略專業知識的技術架構師 | 了解來源和目標系統的技術和應用程式層級；具備將工作負載遷移至雲端的經驗 | 
| **資料架構師** | 技術架構師，在定義、實作和交付各種資料庫的資料解決方案方面擁有廣泛的經驗 | 結構化和非結構化資料的資料建模、對為企業實作資料庫的深入了解和經驗 | 
| **Redis 解決方案架構師** | 技術架構師，可協助針對適當的使用案例建構大小最佳的 Redis 叢集 | 精通各種使用案例的架構和部署 Redis 解決方案 | 
| **雲端解決方案架構師** | 技術架構師對雲端解決方案有更深入的了解，尤其是在 AWS | 精通雲端架構解決方案；工作負載遷移和應用程式現代化體驗 | 
| **企業架構師** | 技術架構師，完全了解組織的技術格局、擁有未來藍圖的共同願景，以及在整個組織中所有團隊中實作和建立標準化架構最佳實務 | 軟體架構認證，例如 TOGAF、基礎軟體工程技能，以及解決方案架構和企業架構專業知識 | 
| **IT 或 DevOps 工程師** | 負責建立和維護基礎設施的工程師，包括監控基礎設施是否有問題、執行維護任務，以及視需要進行更新。 | 充分了解各種技術，包括作業系統、聯網和雲端運算；熟悉程式設計語言，例如 Python、Bash 和 Ruby，以及 Docker、Kubernetes 和 Ansible 等工具 | 

## Architecture
<a name="migrate-redis-workloads-to-redis-enterprise-cloud-on-aws-architecture"></a>

**遷移選項**

下圖顯示將內部部署 (Redis 型或其他） 資料來源遷移至 AWS 的選項。它會顯示數種您可以選擇的遷移工具，例如使用 Redis 複寫功能或使用 AWS DMS 將 Redis 資料庫 (RDB) 檔案匯出至 Amazon Simple Storage Service (Amazon S3)。

![\[將內部部署資料來源遷移至 Redis Enterprise Cloud on AWS 的選項\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/384309f6-7218-4a46-83a5-f37ff95c8832/images/4b242a29-d283-49a3-aaea-a970813db6be.png)


1. 內部部署資料來源：非以 Redis 為基礎的資料庫，例如 MySQL、PostgreSQL、Oracle、SQL Server 或 MariaDB。 

1. 內部部署資料來源：Redis 通訊協定型資料庫，例如 Redis OSS 和 Redis Enterprise Software。

1. 從 Redis 型資料庫遷移資料最簡單的方法是匯出 RDB 檔案，並將其匯入目標 Redis Enterprise Cloud on AWS。

1. 或者，您可以使用 Redis 中的複寫功能 (`ReplicaOf`)，將資料從來源遷移到目標。

1. 如果您的資料遷移需求包含資料轉換，您可以採用 Redis 輸入/輸出工具 (RIOT) 來遷移資料。

1. 或者，您可以使用 AWS Data Migration Service (AWS DMS) 從 SQL 型資料庫遷移資料。 

1. 您必須使用 AWS DMS 的虛擬私有雲端 (VPC) 對等互連，才能成功將資料遷移至目標 Redis Enterprise Cloud on AWS。

**目標架構**

下圖顯示 Redis Enterprise Cloud on AWS 的典型部署架構，並說明如何與金鑰 AWS 服務搭配使用。

![\[適用於 AWS 上 Redis Enterprise Cloud 的部署架構，並搭配 AWS 服務使用\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/384309f6-7218-4a46-83a5-f37ff95c8832/images/f1351537-e710-4a68-8768-89d44870150f.png)


1. 您可以連線到由 Redis Enterprise Cloud on AWS 支援的商業應用程式。

1. 您可以在自己的 AWS 帳戶中，在該帳戶中的 VPC 中執行商業應用程式。

1. 您可以使用 Redis Enterprise Cloud 資料庫端點來連線至您的應用程式。範例包括在 EC2 執行個體上執行的應用程式伺服器、部署為 AWS Lambda 服務的微服務、Amazon Elastic Container Service (Amazon ECS) 應用程式或 Amazon Elastic Kubernetes Service (Amazon EKS) 應用程式。

1. 在 VPC 中執行的商業應用程式需要與 Redis Enterprise Cloud VPC 的 VPC 對等連線。這可讓商業應用程式透過私有端點安全地連線。

1. Redis Enterprise Cloud on AWS 是一種記憶體內 NoSQL 資料庫平台，部署為 AWS 上的DBaaS，並由 Redis 完全管理。

1. Redis Enterprise Cloud 會部署在由 Redis 建立的標準 AWS 帳戶中的 VPC 內。

1. 基於安全考量，Redis Enterprise Cloud 會部署在可在私有和公有端點存取的私有子網路中。建議您將用戶端應用程式連接到私有端點上的 Redis。如果您打算使用公有端點，強烈建議您[啟用 TLS](https://docs.redis.com/latest/rc/security/database-security/tls-ssl/) 來加密用戶端應用程式與 Redis Enterprise Cloud 之間的資料。

Redis 遷移方法與 AWS 遷移方法保持一致，如 AWS 規範指引網站上的[調動您的組織以加速大規模遷移](https://docs.aws.amazon.com/prescriptive-guidance/latest/strategy-migration/overview.html)。

** 自動化和擴展**

遷移的環境設定任務可以透過 AWS 登陸區域和基礎設施即程式碼 (IaC) 範本進行自動化和擴展。這些會在此模式的 [Epics ](#migrate-redis-workloads-to-redis-enterprise-cloud-on-aws-epics)區段中討論。

## 工具
<a name="migrate-redis-workloads-to-redis-enterprise-cloud-on-aws-tools"></a>

根據您的資料遷移需求，您可以選擇各種技術選項，將資料遷移至 Redis Enterprise Cloud on AWS。下表說明並比較這些工具。


| 
| 
| 工具 | Description | 優點 | 缺點 | 
| --- |--- |--- |--- |
| [RDB 匯出](https://docs.redis.com/latest/rc/api/examples/back-up-and-import-data/)和[匯入](https://docs.redis.com/latest/rc/databases/import-data/) | 您從來源 （例如 Redis OSS 或 Redis Enterprise Software) 資料庫匯出資料，格式為 RDB 檔案。如果您的資料庫是透過 Redis OSS 叢集提供，您可以將每個主碎片匯出至 RDB。然後，您只需一個步驟即可匯入所有 RDB 檔案。如果您的來源資料庫是以 OSS 叢集為基礎，但您的目標資料庫未使用 OSS 叢集 API，您必須將應用程式原始碼變更為使用標準 Redis 用戶端程式庫。資料轉換需求或邏輯資料庫合併需要更複雜的程序，此表稍後會在*邏輯資料庫合併*下說明。 | 簡單。可與任何以 Redis 為基礎的解決方案搭配使用，這些解決方案可將 RDB 格式的資料匯出為來源 （包括 Redis OSS 和 Redis Enterprise Software)。透過簡單的程序實現資料一致性。 | 不處理資料轉換需求或支援邏輯資料庫合併。大型資料集耗時。沒有差異遷移支援會導致更長的停機時間。 | 
| [Redis 複寫功能](https://docs.redis.com/latest/rs/databases/import-export/replica-of/) （主動-被動） | 您可以持續將資料從 Redis OSS、Enterprise Software 或 Enterprise Cloud 資料庫複寫到 Redis Enterprise Cloud 資料庫。初始同步後，Redis 複寫功能 (`ReplicaOf`) 會執行差異遷移，這表示幾乎沒有觀察到應用程式停機時間。Redis 複寫功能旨在以主動-被動的方式使用。假設目標是被動的，並完全重新同步 （從來源資料庫漂移和同步）。因此，在來源和目標之間切換有些複雜。您可以將 OSS 叢集的所有主碎片指定為來源，以從 Redis OSS 叢集複寫到標準叢集 Redis Enterprise Cloud 資料庫。不過，Redis 複寫功能最多允許 32 個來源資料庫。 | 支援連續複寫 （初始資料載入，後面接著差異）。幾乎沒有停機時間 （取決於複寫延遲）。實現資料一致性。 | 只有一個站台是作用中的，因此在站台之間切換會更複雜。當您從 OSS 叢集遷移時，最多支援 32 個主碎片。 | 
| [AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) | 您可以使用 AWS DMS，以最短的停機時間將資料從任何支援的來源資料庫遷移到目標 Redis 資料存放區。如需詳細資訊，請參閱 [AWS DMS 文件中的使用 Redis 做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.Redis.html)。 | 支援 NoSQL 和 SQL 資料來源的遷移。與其他 AWS 服務搭配運作良好。支援即時遷移和變更資料擷取 (CDC) 使用案例。 | Redis 鍵值不能包含特殊字元，例如 %。不支援遷移資料列或欄位名稱中具有特殊字元的資料。不支援完整大型二進位物件 (LOB) 模式。 | 
| 邏輯資料庫合併 | 特殊資料庫合併需求可能需要自訂資料遷移解決方案。例如，您可能在 Redis OSS 中有四個邏輯資料庫 (`SELECT 0..3`)，但您可能想要使用單一資料庫端點，而不是將資料移至多個 Redis Enterprise Cloud 資料庫。Redis Enterprise 不支援可選取的邏輯資料庫，因此您必須轉換來源資料庫的實體資料模型。例如，您可以將每個資料庫索引映射到字首 (`0` 到 `cmp`、 `usr``1`到 等），然後使用遷移指令碼或擷取、轉換和載入 (ETL) 工具來輸出 RDB 檔案，然後您可以將其匯入目標資料庫。 | 使用自訂指令碼，在遷移至目標系統期間精細控制資料形狀。  | 如果您決定不完成遷移，則轉返可能非常具有挑戰性，特別是如果必須將較新的資料轉返至來源系統時。如果目標是為一次性遷移建置一次性解決方案，則建置成本可能會很高。如果遷移需求經常變更，程式碼、基礎設施、開發時間和其他區域的維護成本可能會很高。  | 

此外，您可以從 AWS 使用下列工具和服務。

評估和探索工具：
+ [遷移評估器](https://aws.amazon.com/migration-evaluator/)

應用程式和伺服器遷移工具：
+ [AWS Application Migration Service](https://aws.amazon.com/application-migration-service/)

[資料庫遷移工具](https://aws.amazon.com/solutions/database-migrations/)：
+ [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)
+ [AWS Database Migration Service (AWS DMS)](https://aws.amazon.com/dms/)

[資料遷移工具](https://aws.amazon.com/cloud-data-migration/)：
+ [AWS Storage Gateway](https://aws.amazon.com/storagegateway/)
+ [AWS DataSync](https://aws.amazon.com/datasync/)
+ [AWS Direct Connect](https://aws.amazon.com/directconnect/)
+ [AWS Snowball](https://aws.amazon.com/snowball/)
+ [Amazon Data Firehose](https://aws.amazon.com/kinesis/data-firehose/)

AWS 合作夥伴解決方案：
+ [AWS 遷移能力合作夥伴](https://aws.amazon.com/migration/partner-solutions/)

## 史詩
<a name="migrate-redis-workloads-to-redis-enterprise-cloud-on-aws-epics"></a>

### 完成探索和評估任務
<a name="complete-discovery-and-assessment-tasks"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別工作負載。 | 識別您要遷移的適當候選工作負載。在選擇工作負載進行遷移之前，請考慮下列事項：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html)理想情況下，請選擇具有最大業務影響且涉及最低風險的工作負載。保持整體程序反覆運算並以小幅度遷移。 | 資料架構師、商業擁護者、遷移專案發起人 | 
| 識別資料來源和需求；設計資料模型。 | Redis 會執行研討會來加速探索並定義專案的遷移規劃。在本研討會中，Redis 團隊會識別資料來源和來源資料模型需求，並分析如何在 Redis Enterprise Cloud 中重新建模。Redis 遷移團隊 （專業服務） 會與您的組織執行詳細的資料模型設計練習。在本練習中，Redis 團隊會：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html) | Redis 解決方案架構師 | 
| 識別來源資料庫的特性。 | 識別來源和目標環境中使用的 Redis 產品。例如：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html) | 資料架構師 | 
| 收集目前的系統 SLA 和其他調整規模指標。 | 判斷目前服務層級協議 (SLAs)，以輸送量 （每秒操作數）、延遲、每個資料庫的整體記憶體大小，以及高可用性 (HA) 需求表示。 | 資料架構師 | 
| 識別目標系統的特性。 | 判斷這些問題的答案：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html) | 資料架構師、Redis 解決方案架構師 （選用） | 
| 識別相依性。 | 識別要遷移之目前系統的上游和下游相依性。確定遷移工作與其他相依系統遷移一致。例如，如果您打算將其他商業應用程式從內部部署遷移到 AWS 雲端，請識別這些應用程式，並根據專案目標、時間表和利益相關者進行調整。 | 資料架構師、企業架構師 | 
| 識別遷移工具。 | 根據您的資料遷移需求 （例如來源資料或停機時間需求），您可以使用先前在工具章節中所述的任何[工具](#migrate-redis-workloads-to-redis-enterprise-cloud-on-aws-tools)。此外，您可以使用：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html) | 遷移解決方案架構師，Redis 解決方案架構師 | 
| 建立應變計畫。 | 建立應變計畫以復原，以防您在遷移期間遇到問題。 | 專案管理、技術團隊，包括架構師 | 

### 完成安全與合規任務
<a name="complete-security-and-compliance-tasks"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 保護 Redis 管理主控台。 | 若要保護管理主控台，請遵循 [Redis 文件](https://redis.io/docs/latest/operate/oss_and_stack/management/security/)中的指示。 | IT 基礎設施管理員 | 
| 保護 Redis 資料庫。 | 請參閱 Redis 文件中的下列頁面以：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html) |  | 
| 保護 Redis 雲端 APIs。 | [啟用 API](https://docs.redis.com/latest/rc/api/get-started/enable-the-api/) 時，您可以[管理 Redis Cloud 帳戶所有擁有者的 API 金鑰](https://docs.redis.com/latest/rc/api/get-started/manage-api-keys/)。如需 API 安全功能的概觀，請參閱 Redis 網站上的 [API 身分驗證文件](https://docs.redis.com/latest/rc/api/get-started/)。 | IT 基礎設施管理員 | 

### 設定新環境
<a name="set-up-the-new-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 AWS 上設定新的環境。 | 此任務包括：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html) | IT 或 DevOps 工程師 | 
| 部署遷移架構。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html)您現在已準備好執行實際的資料遷移管道並進行測試。 | IT 或 DevOps 工程師 | 

### 設定聯網
<a name="set-up-networking"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立連線。 | 在內部部署基礎設施和 AWS 雲端資源之間建立連線。使用安全群組、AWS Direct Connect 和其他資源來實現此功能。如需詳細資訊，請參閱 [AWS 網站上的將您的資料中心連線至](https://aws.amazon.com/getting-started/hands-on/connect-data-center-to-aws/) AWS。 | IT 或 DevOps 工程師 | 
| 設定 VPC 對等互連。 | 在 VPCs 執行商業應用程式的 VPC （或執行遷移工具的 EC2 執行個體或 AWS DMS 複寫伺服器） 與執行 Redis Enterprise Cloud 的 VPC 之間建立 VPC 對等互連。如需說明，請參閱 [Amazon VPC 文件中的開始使用](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-getting-started.html) Amazon VPC，以及 Redis 文件中的[啟用 VPC 對等](https://docs.redis.com/latest/rc/security/vpc-peering/)互連。 | IT 或 DevOps 工程師 | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選擇資料遷移工具。 | 檢閱[工具](#migrate-redis-workloads-to-redis-enterprise-cloud-on-aws-tools)區段中的表格，以查看這些工具的說明、優點和缺點：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html)下列資料列說明與每個工具相關聯的資料遷移任務。 | 遷移解決方案架構師 | 
| 選項 1：使用 RDB 匯出和匯入。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html)如需詳細資訊，請參閱 [Redis 文件](https://docs.redis.com/latest/rc/databases/import-data/)。 | 遷移解決方案架構師，Redis 解決方案架構師 | 
| 選項 2：使用 Redis 複寫功能 （主動-被動）。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html)如需詳細資訊，請參閱 [Redis 文件](https://docs.redis.com/latest/rs/databases/import-export/replica-of/)。 | 遷移解決方案架構師，Redis 解決方案架構師 | 
| 選項 3：使用 AWS DMS。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.html) | 遷移解決方案架構師，Redis 解決方案架構師 | 
| 選項 4：使用邏輯資料庫合併。 | 此選項涉及使用遷移指令碼或 ETL 工具來轉換來源資料庫的實體資料模型，以及產生 RDB 檔案。Redis Professional Services 會視需要協助此步驟。 | 遷移解決方案架構師，Redis 解決方案架構師 | 

### 遷移您的應用程式
<a name="migrate-your-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 協調專案管理時間表和目標。 | 將應用程式層的遷移專案目標、里程碑和時間表與 Redis 資料遷移專案的目標、里程碑和時間表保持一致。 | 專案管理 | 
| 對齊測試活動。 | 在 AWS 雲端中遷移和現代化應用程式層之後，將應用程式層指向新遷移的 Redis Enterprise Cloud on AWS 進行測試。 | 測試 | 

### 測試
<a name="test"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 實作測試計畫。 | 在測試環境中根據測試需求，在您的站點執行資料遷移常式和在實作階段開發的指令碼。 | 測試 | 
| 測試資料品質。 | 遷移資料後測試資料品質。 | 測試 | 
| 測試功能。 | 測試資料查詢和應用程式層，以確保應用程式在與來源系統中相同的層級執行。 | 測試 | 

### 切換
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 做出切換決策。 | 在所有應用程式層級和資料庫層級測試完成後，執行領導團隊和利益相關者會根據測試團隊確認的最終結果，決定是否在 AWS 上切換到新環境。 | 專案管理、商業擁護者 | 
| 切換到 AWS 雲端。 | 當您確認一切就緒時，請將應用程式層指向新遷移的資料，並將用戶端指向根據 AWS 上新的 Redis Enterprise Cloud 系統執行的新應用程式層。 | IT 或 DevOps 工程師、資料架構師、遷移解決方案架構師、Redis 解決方案架構師 | 

## 相關資源
<a name="migrate-redis-workloads-to-redis-enterprise-cloud-on-aws-resources"></a>

**Redis 資源**
+ [Redis Enterprise Cloud 文件](https://docs.redis.com/latest/rc/)
+ [RIOT](https://github.com/redis-developer/riot) 工具 (GitHub 儲存庫）
+ [Terraform 提供者](https://registry.terraform.io/providers/RedisLabs/rediscloud/latest) （下載）

**AWS 資源**
+ [示範遷移](https://aws.amazon.com/getting-started/tutorials/)
+ [AWS 合作夥伴解決方案](https://aws.amazon.com/quickstart/)
+ [文件](https://docs.aws.amazon.com/index.html)
+ [部落格文章](https://aws.amazon.com/blogs/database/category/migration/)
+ [白皮書](https://aws.amazon.com/whitepapers/)
+ [教學課程和影片](https://aws.amazon.com/getting-started/tutorials/)
+ [AWS 雲端遷移](https://aws.amazon.com/cloud-migration/)
+ [AWS 方案指引](https://aws.amazon.com/prescriptive-guidance/)

## 其他資訊
<a name="migrate-redis-workloads-to-redis-enterprise-cloud-on-aws-additional"></a>

如需將 Redis 工作負載遷移至 AWS 雲端的標準安全需求，請參閱 AWS 網站上的[安全、身分和合規最佳實務](https://aws.amazon.com/architecture/security-identity-compliance/)，以及 [Redis 網站上的 Redis 信任中心](https://trust.redis.io/)。

# 使用具有相同主機名稱的 SAP HSR 將 SAP HANA 遷移至 AWS
<a name="migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname"></a>

*Pradeep Puliyampatta，Amazon Web Services*

## 總結
<a name="migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname-summary"></a>

SAP HANA 遷移至 Amazon Web Services (AWS) 可以使用多個選項執行，包括備份和還原、匯出和匯入，以及 SAP HANA 系統複寫 (HSR)。特定選項的選擇取決於來源和目標 SAP HANA 資料庫之間的網路連線、來源資料庫的大小、停機時間考量事項和其他因素。 

當來源和目標系統與整個資料庫 (SAP HANA 資料庫複寫快照） 之間有穩定的網路時，將 SAP HANA 工作負載遷移至 AWS 的 SAP HSR 選項可在 1 天內完全複寫，如 SAP 針對 SAP HSR 的網路輸送量需求所規定。此方法的停機時間需求僅限於對目標 AWS 環境、SAP HANA 資料庫備份和遷移後任務執行接管。

SAP HSR 支援將不同的主機名稱 （映射至不同 IP 地址的主機名稱） 用於主要或來源與次要或目標系統之間的複寫流量。您可以透過在 的 `[system_replication_hostname_resolution]`區段下定義這些特定的主機名稱集來執行此操作`global.ini`。在本節中，必須在每個主機上定義主要和次要網站的所有主機。如需詳細的組態步驟，請參閱 [SAP 文件](https://help.sap.com/viewer/eb3777d5495d46c5b2fa773206bbfb46/1.0.12/en-US/c0cba1cb2ba34ec89f45b48b2157ec7b.html)。

此設定的一個關鍵要點是，主要系統中的主機名稱必須與次要系統中的主機名稱不同。否則，可以觀察到下列錯誤。
+ `"each site must have a unique set of logical hostnames"`
+ `"remoteHost does not match with any host of the source site. All hosts of source and target site must be able to resolve all hostnames of both sites correctly"`

不過，遷移後步驟的數量可以透過在目標 AWS 環境中使用相同的 SAP HANA 資料庫主機名稱來減少。 

此模式提供了在使用 SAP HSR 選項時，在來源和目標環境中使用相同主機名稱的解決方法。透過此模式，您可以使用 SAP HANA 主機名稱重新命名選項。您可以將暫時主機名稱指派給目標 SAP HANA 資料庫，以促進 SAP HSR 的主機名稱唯一性。遷移完成目標 SAP HANA 環境的接管里程碑後，您可以將目標系統主機名稱還原為來源系統的主機名稱。

## 先決條件和限制
<a name="migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。
+ 具有虛擬私有網路 (VPN) 端點或路由器的虛擬私有雲端 (VPC)。
+ AWS Client VPN 或 AWS Direct Connect 設定為將檔案從來源傳輸到目標。
+ 來源和目標環境中的 SAP HANA 資料庫。目標 SAP HANA 資料庫修補程式層級應該等於或高於相同 SAP HANA 平台版本中的來源 SAP HANA 資料庫修補程式層級。例如，複寫無法在 HANA 1.0 和 HANA 2.0 系統之間設定。如需詳細資訊，請參閱 SAP 備註：1999880 – 常見問答集：SAP HANA 系統複寫中的問題 15。
+ 目標環境中的 SAP 應用程式伺服器。
+ 目標環境中的 Amazon Elastic Block Store (Amazon EBS) 磁碟區。

**限制**

下列 SAP 文件清單涵蓋與此因應措施相關的已知問題，包括 SAP HANA 動態分層和橫向擴展遷移的相關限制：
+ 2956397 – SAP HANA 資料庫系統重新命名失敗
+ 2222694 – 嘗試重新命名 HANA 系統時，出現以下錯誤「原始 sidadm 使用者不擁有來源檔案 (uid = xxxx)」
+ 2607227 – hdblcm：register\$1rename\$1system：重新命名 SAP HANA 執行個體失敗
+ 2630562 – HANA 主機名稱重新命名失敗，且 HANA 未啟動
+ 2935639 – sr\$1register 未使用 global.ini 區段中 system\$1replication\$1hostname\$1resolution 指定的主機名稱
+ 2710211 – 錯誤：來源系統和目標系統具有重疊的邏輯主機名稱
+ 2693441 – 由於錯誤而無法重新命名 SAP HANA 系統
+ 2519672 – HANA 主要和次要具有不同的系統 PKI SSFS 資料和金鑰，或無法檢查
+ 2457129 – 當動態分層是橫向的一部分時，不允許 SAP HANA 系統主機重新命名
+ 2473002 – 使用 HANA 系統複寫來遷移向外擴展系統 （在 中，針對向外擴展 SAP HANA 系統使用此主機名稱重新命名方法，SAP 沒有提供限制。 不過，每個個別主機都必須重複此程序。 其他橫向擴展遷移限制也適用於此方法。)

**產品版本**
+ 此解決方案適用於 SAP HANA 資料庫平台版本 1.0 和 2.0。

## Architecture
<a name="migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname-architecture"></a>

**來源設定**

SAP HANA 資料庫安裝在來源環境中。所有 SAP 應用程式伺服器連線和資料庫介面都使用相同的主機名稱進行用戶端連線。下圖顯示範例來源主機名稱`hdbhost`及其對應的 IP 地址。

![\[SAP HANA 資料庫來源 hdbhost，位於 IP 地址為 10.1.2.1 的企業資料中心。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/004781c1-96df-43dd-a52e-ed1db5bdf9ef/images/a1b28c3a-93b7-4f82-a5da-81008b74c9ae.png)


**目標設定**

 AWS 雲端 目標環境使用相同的主機名稱來執行 SAP HANA 資料庫。AWS 上的目標環境包括下列項目：
+ SAP HANA 資料庫
+ SAP 應用程式伺服器
+ EBS 磁碟區

![\[AWS 雲端中的 SAP HANA 資料庫目標 hdbhost，IP 地址為 172.16.2.1。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/004781c1-96df-43dd-a52e-ed1db5bdf9ef/images/7f45d7aa-9b80-4413-bec9-1616492b650c.png)


**中繼組態**

在下圖中， AWS 目標環境上的主機名稱會暫時重新命名，`temp-host`因此來源和目標上的主機名稱是唯一的。遷移完成目標環境的接管里程碑後，會使用原始名稱 重新命名目標系統虛擬主機名稱`hdbhost`。

中繼組態包含下列其中一個選項：
+ AWS Client VPN 使用 Client VPN 端點
+ Direct Connect 連線至路由器

![\[以暫存主機 IP 地址為 172.31.5.10 的 AWS 雲端系統為目標的來源系統。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/004781c1-96df-43dd-a52e-ed1db5bdf9ef/images/e2794477-2e8f-4974-bca3-2275f6809fce.png)


 AWS 目標環境上的 SAP 應用程式伺服器可以在複寫設定之前或之後安裝。不過，在複寫設定之前安裝應用程式伺服器，有助於減少安裝期間的停機時間、高可用性組態和備份。

## 工具
<a name="migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname-tools"></a>

**AWS 服務**
+ [AWS Client VPN](https://docs.aws.amazon.com/vpn/latest/clientvpn-user/client-vpn-user-what-is.html) 是一種受管的用戶端型 VPN 服務，可讓您安全地存取內部部署網路中的 AWS 資源。
+ [AWS Direct Connect](https://docs.aws.amazon.com/directconnect/latest/UserGuide/Welcome.html) 會透過標準乙太網路光纖纜線將您的內部網路連結至 Direct Connect 位置。透過此連線，您可以直接建立與公有的虛擬介面 AWS 服務，繞過網路路徑中的網際網路服務供應商。
+ [Amazon Elastic Block Store (Amazon EBS)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html) 提供區塊層級儲存磁碟區，可與 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體搭配使用。EBS 磁碟區的行為與未格式化的原始區塊型儲存設備相似。您可以將這些磁碟區做為裝置，掛載在您的執行個體上。

**其他工具**
+ [SAP 應用程式伺服器](https://help.sap.com/doc/saphelp_nw73ehp1/7.31.19/en-US/47/a032c0305e0b3ae10000000a42189d/content.htm?no_cache=true) – SAP 應用程式伺服器提供程式設計人員表達商業邏輯的方式。SAP 應用程式伺服器會根據商業邏輯執行資料處理。實際資料會存放在資料庫中，這是個別的元件。 
+ [SAP HANA 駕駛艙](https://help.sap.com/viewer/6b94445c94ae495c83a19646e7c3fd56/2.0.03/en-US/da25cad976064dc0a24a1b0ee9b62525.html)和 [SAP HANA Studio](https://help.sap.com/viewer/a2a49126a5c546a9864aae22c05c3d0e/2.0.00/en-US/c831c3bbbb571014901199718bf7edc5.html) – SAP HANA 駕駛艙和 SAP HANA Studio 都提供 SAP HANA 資料庫的管理界面。在 SAP HANA Studio 中，SAP HANA 管理主控台是提供 SAP HANA 資料庫管理相關內容的系統檢視。 
+ [SAP HANA 系統複寫](https://help.sap.com/viewer/4e9b18c116aa42fc84c7dbfd02111aba/2.0.04/en-US) – SAP HANA 系統複寫 (SAP HSR) 是 SAP 提供的標準程序，用於複寫 SAP HANA 資料庫。SAP HSR 所需的可執行檔是 SAP HANA 伺服器核心本身的一部分。

## 史詩
<a name="migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname-epics"></a>

### 準備來源和目標環境
<a name="prepare-the-source-and-target-environments"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝和設定 SAP HANA 資料庫。 | 在來源和目標環境中，確保 SAP HANA 資料庫已安裝並根據 SAP HANA on 最佳實務進行設定。如需詳細資訊，請參閱 [SAP HANA on AWS](https://docs.aws.amazon.com/sap/latest/sap-hana/sap-hana.pdf)。 | SAP Basis 管理 | 
| 映射 IP 地址。 | 在目標環境中，確保將暫時主機名稱指派給內部 IP 地址。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname.html) | AWS 管理 | 
| 解決目標主機名稱。 | 在次要 SAP HANA 資料庫上，更新 `/etc/hosts` 檔案中的相關主機名稱，確認已解析 SAP HANA 複寫網路的兩個主機名稱 (`hdbhost` 和 `temp-host`)。 | Linux 管理 | 
| 備份來源和目標 SAP HANA 資料庫。 | 使用 SAP HANA Studio 或 SAP HANA 駕駛艙在 SAP HANA 資料庫上執行備份。 | SAP Basis 管理 | 
| Exchange 系統 PKI 憑證。 | （僅適用於 SAP HANA 2.0 和更新版本） 在主要和次要資料庫之間的檔案系統 (SSFS) 存放區中的系統公有金鑰基礎設施 (PKI) 安全存放區中交換憑證。如需詳細資訊，請參閱 SAP Note 2369981 – 使用 SAP HANA 系統複寫進行身分驗證所需的組態步驟。 | SAP Basis 管理 | 

### 重新命名目標 SAP HANA 資料庫
<a name="rename-the-target-sap-hana-db"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止目標用戶端連線。 | 在目標環境中，關閉 SAP 應用程式伺服器和其他用戶端連線。 | SAP Basis 管理 | 
| 將目標 SAP HANA 資料庫重新命名為暫時主機名稱。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname.html)SAP HANA 資料庫停止和啟動將由 控制`hdblcm`。  | SAP Basis 管理 | 
| 指派複寫網路。 | 在來源系統的 `global.ini`檔案中，在 `[system_replication_hostname_resolution]`標頭下，提供來源和目標複寫網路詳細資訊。然後將項目複製到目標系統上`global.ini`的檔案。 | SAP Basis 管理 | 
| 在主要 上啟用複寫。 | 若要在來源 SAP HANA 資料庫上啟用複寫，請執行下列命令。 <pre>hdbnsutil -sr_enable --name=siteA</pre> | SAP Basis 管理 | 
| 將目標 SAP HANA 資料庫註冊為次要系統。 | 若要將目標 SAP HANA 資料庫註冊為用於 SAP HSR 來源的次要系統，請選擇**非同步**複寫。 <pre>(sid)adm $> HDB stop<br />(sid)adm $> hdbnsutil -sr_register –name=siteB –remotehost=hdbhost /<br />--remoteInstance=00 –replicationMode=async –operationMode=logreplay<br />(sid)adm $> HDB start</pre>或者，您可以選擇要註冊`–online`的選項。在這種情況下，您不需要停止和啟動 SAP HANA 資料庫。 | SAP Basis 管理 | 
| 驗證同步。 | 在來源 SAP HANA 資料庫上，確認所有日誌都套用到目標系統 （因為它是非同步複寫）。若要驗證複寫，請在來源上執行下列命令。<pre>(sid)adm $> cdpy<br />(sidadm $> python systemReplicationStatus.py</pre> | SAP Basis 管理 | 
| 關閉來源 SAP 應用程式和 SAP HANA 資料庫。 | 在遷移切換期間，請關閉來源系統 (SAP 應用程式和 SAP HANA 資料庫。 | SAP Basis 管理 | 
| 在目標執行接管。 | 若要在 AWS 上執行目標接管，請執行命令 `hdbnsutil -sr_takeover`。 | SAP Basis 管理 | 
| 在目標 SAP HANA 資料庫上，關閉複寫。 | 若要清除複寫中繼資料，請執行命令 來停止目標系統的複寫`hdbnsutil -sr_disable`。 這符合 SAP Note 2693441 – 由於錯誤而無法重新命名 SAP HANA 系統。 | SAP Basis 管理 | 
| 備份目標 SAP HANA 資料庫。 | 接管成功後，建議您執行完整的 SAP HANA 資料庫備份。 | SAP Basis 管理 | 

### 還原至目標系統中的原始主機名稱
<a name="revert-to-the-original-hostname-in-the-target-system"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將目標 SAP HANA 資料庫主機名稱還原為原始。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname.html)您可以視需要驗證其他選項。不過，請確定您不會將主機重新命名與 SID 變更混淆 (SAP Note 2598814 – hdblcm：SID 重新命名失敗）。 | SAP Basis 管理 | 
| 調整 hdbuserstore。 | 調整指向來源`hdbuserstore`詳細資訊`schema/user`的詳細資訊。如需詳細步驟，請參閱 [SAP 文件](https://help.sap.com/viewer/b3ee5778bc2e4a089d3299b82ec762a7/2.0.02/en-US/ddbdd66b632d4fe7b3c2e0e6e341e222.html?q=hdbuserstore)。 若要驗證此步驟，請執行命令 `R3trans -d`。結果應該反映 SAP HANA 資料庫的成功連線。 | SAP Basis 管理 | 
| 啟動用戶端連線。 | 在目標環境中，啟動 SAP 應用程式伺服器和其他用戶端連線。 | SAP Basis 管理 | 

## 相關資源
<a name="migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname-resources"></a>

**SAP 參考**

SAP 文件參考經常由 SAP 更新。若要隨時掌握最新資訊，請參閱 SAP HANA 高可用性的 SAP Note 2407186 – 操作指南與白皮書。

*其他 SAP 備註*
+ 2550327 – 如何重新命名 SAP HANA 系統
+ 1999880 – 常見問答集：SAP HANA 系統複寫
+ 2078425 – SAP HANA 平台生命週期管理工具 hdblcm 的故障診斷備註
+ 2592227 – HANA 系統中的 FQDN 尾碼變更
+ 2048681 – 在沒有 SSH 或根登入資料的多主機系統上執行 SAP HANA 平台生命週期管理管理任務

*SAP 文件*
+ [系統複寫網路連線](https://help.sap.com/docs/SAP_HANA_PLATFORM/4e9b18c116aa42fc84c7dbfd02111aba/47190b425eb1433697b026ecd46ff5f9.html)
+ [系統複寫的主機名稱解析](https://help.sap.com/viewer/eb3777d5495d46c5b2fa773206bbfb46/1.0.12/en-US/c0cba1cb2ba34ec89f45b48b2157ec7b.html)

**AWS 參考**
+ [將 SAP HANA 從其他平台遷移至 AWS](https://docs.aws.amazon.com/sap/latest/sap-hana/migrating-hana-hana-to-aws.html)

## 其他資訊
<a name="migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname-additional"></a>

`hdblcm` 作為主機名稱重新命名活動的一部分執行的變更會合併在下列詳細日誌中。

![\[程式碼顯示從 hdbhost 開始在臨時主機上停止的程序，並重新命名 SAP HANA 資料庫系統。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/004781c1-96df-43dd-a52e-ed1db5bdf9ef/images/9e0c11ca-6555-484f-9639-107f60f725f5.png)


# 使用 遷移 Microsoft SQL Server Always On 可用性群組 AWS Application Migration Service
<a name="migrate-microsoft-sql-server-always-on-group-using-mgn"></a>

*Sreenivas Nettem、Bharath Kumar Pammi Ramesh、Anantharaman Seshadri 和 Gireesh Sreekantan，Amazon Web Services*

## 總結
<a name="migrate-microsoft-sql-server-always-on-group-using-mgn-summary"></a>

AWS Application Migration Service (AWS MGN) 是重新託管 中現有環境的偏好工具 AWS 雲端，可讓客戶遠離內部部署資料中心。此模式概述使用 AWS MGN 透過 Microsoft SQL Server Always On 可用性群組遷移 Windows 叢集的程序。

## 先決條件和限制
<a name="migrate-microsoft-sql-server-always-on-group-using-mgn-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶。
+ MGN 協同運作的 AWS AWS Identity and Access Management (IAM) 角色。
+ 存取來源資料庫伺服器 (SQL Server Always On 可用性群組）。
+  AWS 登陸區域中用於保留 DNS 名稱的 Active Directory。
+ 與 Active Directory 進行封閉網路通訊的預備子網路。
+ 可與 Active Directory 通訊的目標子網路。
+ 目標子網路中 Windows 叢集的兩個預留 IP 地址 （每個可用區域一個）。
+ 目標子網路中 SQL Always On 接聽程式的兩個預留 IP 地址 （每個可用區域一個）。

**產品版本**
+ Windows Server 2012 或更新版本
+ SQL Server 2012 或更新版本

## Architecture
<a name="migrate-microsoft-sql-server-always-on-group-using-mgn-architecture"></a>

**來源技術堆疊**

Microsoft Windows 叢集 （內部部署實體或虛擬機器） Microsoft SQL Server Always On 可用性群組

**目標技術堆疊**

Amazon EC2 Windows 執行個體

**目標架構**

![\[使用 AWS MGN 遷移 SQL Server Always On 可用性的 AWS 架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/aa94040b-5ecf-42f9-90e3-929d0fa5e715/images/0b85c613-51df-475b-9598-3da3f9cd47c6.png)


## 工具
<a name="migrate-microsoft-sql-server-always-on-group-using-mgn-tools"></a>

*AWS 服務*
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [AWS Application Migration Service](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html) 可協助您將應用程式重新託管 （提升和轉移） 到 ， AWS 雲端 無需變更，且停機時間最短。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。

*其他工具*
+ [Microsoft SQL Server Management Studio (SSMS)](https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms) 是一種用於管理 SQL Server 的工具，包括存取、設定和管理 SQL Server 元件。

## 最佳實務
<a name="migrate-microsoft-sql-server-always-on-group-using-mgn-best-practices"></a>

對於 AWS MGN，請參閱 [的最佳實務 AWS Application Migration Service](https://docs.aws.amazon.com/mgn/latest/ug/best_practices_mgn.html)。

## 史詩
<a name="migrate-microsoft-sql-server-always-on-group-using-mgn-epics"></a>

### 準備目標帳戶
<a name="prepare-the-target-account"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 初始化 AWS MGN。 | 在目標中初始化 AWS MGN AWS 區域。這會建立所需的 IAM 角色和政策。如需詳細資訊，請參閱[使用 主控台初始化 Application Migration Service](https://docs.aws.amazon.com/mgn/latest/ug/mgn-initialize-console.html)。 | 雲端管理員 | 
| 建立複寫和啟動範本。 | 設定複寫和啟動範本以搭配 AWS MGN 使用。如需詳細資訊，請參閱 AWS 文件中的[設定範本](https://docs.aws.amazon.com/mgn/latest/ug/mgn-initialization-templates.html)。 | 雲端管理員 | 
| 允許通訊連接埠。 | 若要啟用 AWS MGN 的網路通訊，請允許透過 TCP 連接埠 443 和 1500 的流量。如需詳細資訊，請參閱 AWS 文件中的 [Application Migration Service 的網路需求](https://docs.aws.amazon.com/mgn/latest/ug/Network-Requirements.html)。 | 雲端管理員、網路管理員 | 

### 準備來源伺服器
<a name="prepare-the-source-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證 AWS MGN 先決條件。 | 確認來源伺服器符合 AWS MGN 代理程式安裝的先決條件。如需詳細資訊，請參閱 AWS 文件中的[安裝需求](https://docs.aws.amazon.com/mgn/latest/ug/installation-requirements.html)。 | 遷移工程師 | 
| 安裝 AWS MGN 代理程式。 | 在來源伺服器上安裝 AWS MGN 代理程式。在安裝期間，選擇將遷移伺服器的 AWS 區域 。安裝後，代理程式會與服務通訊並開始複寫。如需詳細資訊，請參閱[在 Windows 伺服器上安裝複 AWS 寫代理](https://docs.aws.amazon.com/mgn/latest/ug/windows-agent.html)程式。 | 遷移工程師 | 
| 檢查來源伺服器狀態。 | 在 AWS MGN 主控台中，檢查來源伺服器的狀態。伺服器會在複寫開始時顯示**準備進行測試**。如果您遇到任何錯誤，請參閱 AWS MGN 文件中的[疑難排解通訊錯誤](https://docs.aws.amazon.com/mgn/latest/ug/Troubleshooting-Communication-Errors.html)。 | 雲端管理員、遷移工程師 | 
| 最佳化複寫設定。 | SQL Always On 叢集使用從主要伺服器到次要伺服器的高 I/O 同步複寫。若要最佳化複寫並避免延遲，請為每個 SQL Always On [伺服器使用專用的複寫](https://docs.aws.amazon.com/mgn/latest/ug/replication-settings-template.html)伺服器。如果資料庫大於 5 TB，請考慮選擇較大的複寫伺服器執行個體大小，例如 **m5.large**，而非預設的 **t3.small。** | 雲端管理員、遷移工程師 | 
| 更新啟動範本。 | 更新[啟動設定](https://docs.aws.amazon.com/mgn/latest/ug/launch-settings.html)，並選擇 SQL Always On 伺服器的子網路。SQL Always On 叢集伺服器會分散到不同的 ， AWS 可用區域 以獲得高可用性。 | 遷移工程師，遷移負責人 | 
| 更新啟動設定。 | 根據您的大小和效能需求，更新啟動設定中的執行個體類型和每秒輸入/輸出操作 (IOPS)。（選用） 在啟動設定中選擇現有的彈性網路界面。 | 遷移工程師，遷移負責人 | 

### 測試切換
<a name="test-cutover"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證來源伺服器。 | 在 AWS MGN 主控台中，確認來源伺服器狀態為**準備好進行測試**。 | 雲端管理員、遷移工程師 | 
| 啟動測試執行個體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-microsoft-sql-server-always-on-group-using-mgn.html) | 雲端管理員、遷移工程師 | 
| 測試連線能力和資料庫完整性。 | 測試測試執行個體的連線和資料庫完整性。然後在 AWS MGN 主控台中將來源伺服器標記為**準備好進行切換**。 | 雲端管理員、遷移工程師 | 

### 預遷移任務
<a name="pre-migration-tasks"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 測試資料庫完整性。 | 這有助於確保在遷移之前，來源沒有資料庫完整性問題。執行 `DBCC CHECKDB` 並指定 `WITH_PHYSICAL_ONLY`。在沒有 的情況下執行此檢查`WITH_PHYSICAL_ONLY`可能會導致來源的效能問題。若要維護資料庫完整性，請每週對資料庫執行完整檢查。這些命令會偵測潛在的損毀問題，以檢查資料庫的邏輯和實體完整性。檢查會驗證資料庫的結構，例如頁面、資料列、索引和系統資料表。 | 資料工程師，DBA | 
| 測試與連結伺服器的連線。 | 測試所有現有伺服器之間的連線，並記錄其狀態。這有助於確保連結的伺服器在遷移後可如預期運作。 | 資料工程師，DBA | 
| 驗證備份。 | 確認來源備份的完整性。 | 資料工程師，DBA | 

### AWS MGN 切換
<a name="aws-mgn-cutover"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止 SQL Server 和叢集服務。 | 停止所有 SQL 叢集節點上的 SQL Server 和 Microsoft 叢集服務。 | DBA，遷移工程師 | 
| 驗證伺服器。 | 在 AWS MGN 主控台中，確認來源伺服器的狀態已**就緒可供切換**，且資料複寫狀態為**良好**。 | 遷移工程師 | 
| 啟動切換。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-microsoft-sql-server-always-on-group-using-mgn.html)如需詳細資訊，請參閱 AWS MGN 文件中的[啟動切換執行個體](https://docs.aws.amazon.com/mgn/latest/ug/launch-cutover-gs.html)。 | 遷移工程師 | 
| 測試啟動的伺服器。 | 登入已啟動的 Amazon EC2 執行個體，並驗證叢集的運作狀態。確認伺服器位於正確的子網路中、執行個體大小和 IOPS 設定正確，而且可以存取見證伺服器。 | DBA，遷移工程師 | 

### 資料庫切換後任務
<a name="database-post-cutover-tasks"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 更新叢集 IP 地址。 | 使用目標子網路中的兩個預留 IP 地址更新 Windows 叢集的叢集 IP 地址。如需詳細資訊，請參閱[變更容錯移轉叢集執行個體的 IP 地址](https://learn.microsoft.com/en-us/sql/sql-server/failover-clusters/windows/change-the-ip-address-of-a-failover-cluster-instance?view=sql-server-2016)。 | DBA，遷移工程師 | 
| 更新 Always On 可用性群組接聽程式 IPs。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-microsoft-sql-server-always-on-group-using-mgn.html) | DBA，遷移工程師 | 
| 驗證連線。 | 使用 SSMS，連線至 Always On 可用性群組接聽程式，並確認連線成功。 | DBA，遷移工程師 | 
| 檢查 Always On 可用性群組的運作狀態。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-microsoft-sql-server-always-on-group-using-mgn.html) | DBA，遷移工程師 | 
| 檢查錯誤日誌。 | 開啟錯誤日誌，並驗證針對 SQL Server 執行個體報告的任何錯誤。確保所有資料庫的復原都已完成。 | DBA，遷移工程師 | 
| 測試連結的伺服器。 | 測試任何連結伺服器的連線能力。如果發生任何連線問題，請確定可存取目標伺服器和連接埠。 | DBA，遷移工程師 | 

### 完成切換
<a name="finalize-the-cutover"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 完成切換。 | 驗證目標 SQL Always On 叢集之後，請透過 AWS MGN 主控台[完成](https://docs.aws.amazon.com/mgn/latest/ug/launch-cutover-gs.html#revert-finalize-cutover-gs)切換。這會停止來源伺服器的資料複寫，並捨棄複寫伺服器的資料。它也會移除複寫伺服器及其相關聯的資源。 | 雲端管理員、遷移工程師 | 

## 疑難排解
<a name="migrate-microsoft-sql-server-always-on-group-using-mgn-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| AWS MGN 疑難排解 | 如需常見問題和解決方案，請參閱 AWS MGN 文件中的[故障診斷](https://docs.aws.amazon.com/mgn/latest/ug/troubleshooting.html)和[常見問答集](https://docs.aws.amazon.com/mgn/latest/ug/FAQ.html)一節。 | 

## 相關資源
<a name="migrate-microsoft-sql-server-always-on-group-using-mgn-resources"></a>

*AWS resources*
+ [Option-1 Rehost - AWS Application Migration Service (AWS)](https://catalog.us-east-1.prod.workshops.aws/workshops/c6bdf8dc-d2b2-4dbd-b673-90836e954745/en-US/04-application-migration/01-mgn)
+ [什麼是 AWS Application Migration Service？](https://docs.aws.amazon.com/mgn/latest/ug/what-is-application-migration-service.html)

*SQL Server 資源*
+ [什麼是 SQL Server Management Studio (SSMS)？](https://learn.microsoft.com/en-us/ssms/sql-server-management-studio-ssms)

## 其他資訊
<a name="migrate-microsoft-sql-server-always-on-group-using-mgn-additional"></a>

如需將工作負載遷移至 的標準安全需求 AWS 雲端，請參閱 AWS 網站上的[安全、身分和合規最佳實務](https://aws.amazon.com/architecture/security-identity-compliance/)。

# 使用分散式可用性群組將 SQL Server 遷移至 AWS
<a name="migrate-sql-server-to-aws-using-distributed-availability-groups"></a>

*Praveen Marthala，Amazon Web Services*

## 總結
<a name="migrate-sql-server-to-aws-using-distributed-availability-groups-summary"></a>

Microsoft SQL Server Always On 可用性群組為 SQL Server 提供高可用性 (HA) 和災難復原 (DR) 解決方案。可用性群組包含接受讀取/寫入流量的主要複本，以及最多八個接受讀取流量的次要複本。可用性群組是在具有兩個或多個節點的 Windows Server 容錯移轉叢集 (WSFC) 上設定。

Microsoft SQL Server Always On 分散式可用性群組提供解決方案，可在兩個獨立的 WFSCs之間設定兩個不同的可用性群組。屬於分散式可用性群組的可用性群組不必位於相同的資料中心。一個可用性群組可以是內部部署，另一個可用性群組可以是位於不同網域中 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的 Amazon Web Services (AWS) Cloud。 

此模式概述使用分散式可用性群組將屬於現有可用性群組一部分的內部部署 SQL Server 資料庫遷移至 SQL Server，並在 Amazon EC2 上設定可用性群組的步驟。透過遵循此模式，您可以將資料庫遷移至 AWS 雲端，並在切換期間將停機時間降至最低。在切換之後，AWS 會立即提供資料庫。您也可以使用此模式，將基礎作業系統從現場部署變更為 AWS，同時保留相同版本的 SQL Server。

## 先決條件和限制
<a name="migrate-sql-server-to-aws-using-distributed-availability-groups-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ AWS Direct Connect 或 AWS Site-to-Site VPN
+ 在 AWS 的兩個節點上安裝的相同 SQL Server 版本

**產品版本**
+ SQL Server 2016 版及更新版本
+ SQL Server Enterprise Edition

## Architecture
<a name="migrate-sql-server-to-aws-using-distributed-availability-groups-architecture"></a>

**來源技術堆疊**
+ 內部部署中具有 Always On 可用性群組的 Microsoft SQL Server 資料庫

**目標技術堆疊**
+ AWS 雲端上 Amazon EC2 上具有 Always On 可用性群組的 Microsoft SQL Server 資料庫

**遷移架構**

![\[內部部署和 AWS 上可用群組中具有同步複寫的 SQL Server。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6e229e30-9b11-4ccb-bccd-cbe6601139c0/images/79ee7911-d68f-4db7-9b94-113dcf09c28b.png)


*術語*
+ WSFC 1 – 內部部署的 WSFC
+ WSFC 2 – AWS 雲端上的 WSFC
+ AG 1 – 第一個可用性群組，位於 WSFC 1 中
+ AG 2 – 第二個可用性群組，位於 WSFC 2 中
+ SQL Server 主要複本 – AG 1 中的節點，被視為所有寫入的全域主要節點
+ SQL Server 轉送器 – AG 2 中的節點，以非同步方式從 SQL Server 主要複本接收資料
+ SQL Server 次要複本 – AG 1 或 AG 2 中從主要複本或轉送器同步接收資料的節點

## 工具
<a name="migrate-sql-server-to-aws-using-distributed-availability-groups-tools"></a>
+ [AWS Direct Connect](https://docs.aws.amazon.com/directconnect/latest/UserGuide/Welcome.html) – AWS Direct Connect 透過標準乙太網路光纖纜線，將您的內部網路連結至 AWS Direct Connect 位置。透過此連線，您可以直接建立與公有 AWS 服務的*虛擬介面*，繞過網路路徑中的網際網路服務供應商。
+ [Amazon EC2](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/concepts.html) – Amazon Elastic Compute Cloud (Amazon EC2) 在 AWS 雲端中提供可擴展的運算容量。您可以使用 Amazon EC2 視需要啟動任意數量或任意數量的虛擬伺服器，也可以向外擴展或向內擴展。
+ [AWS Site-to-Site VPN](https://docs.aws.amazon.com/vpn/latest/s2svpn/VPC_VPN.html) – AWS Site-to-Site VPN 支援建立site-to-site虛擬私有網路 (VPN)。您可以設定 VPN 在 AWS 上啟動的執行個體與您自己的遠端網路之間傳遞流量。
+ [Microsoft SQL Server Management Studio](https://docs.microsoft.com/en-us/sql/ssms/sql-server-management-studio-ssms?view=sql-server-ver15) – Microsoft SQL Server Management Studio (SSMS) 是管理 SQL Server 基礎設施的整合環境。它提供使用者介面和一組工具，其中包含與 SQL Server 互動的豐富指令碼編輯器。

## 史詩
<a name="migrate-sql-server-to-aws-using-distributed-availability-groups-epics"></a>

### 在 AWS 上設定第二個可用性群組
<a name="set-up-a-second-availability-group-on-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 AWS 上建立 WSFC。 | 在具有兩個 HA 節點的 Amazon EC2 執行個體上建立 WSFC 2。您將使用此容錯移轉叢集在 AWS 上建立第二個可用性群組 (AG 2)。 | 系統管理員、SysOps 管理員 | 
| 在 WSFC 2 上建立第二個可用性群組。 | 使用 SSMS，在 WSFC 2 中的兩個節點上建立 AG 2。WSFC 2 中的第一個節點將做為轉送器。WSFC 2 中的第二個節點將充當 AG 2 的次要複本。在此階段，AG 2 中沒有可用的資料庫。這是設定分散式可用性群組的起點。 | DBA、開發人員 | 
| 在 AG 2 上建立沒有復原選項的資料庫。 | 備份現場部署可用性群組 (AG 1) 上的資料庫。 在沒有復原選項的情況下，將資料庫還原至 AG 2 的轉寄站和次要複本。還原資料庫時，請為資料庫資料檔案和日誌檔案指定磁碟空間足夠的位置。在此階段，資料庫處於還原狀態。它們不屬於 AG 2 或分散式可用性群組，而且不會同步。 | DBA、開發人員 | 

### 設定分散式可用性群組
<a name="configure-the-distributed-availability-group"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 AG 1 上建立分散式可用性群組。 | 若要在 AG 1 上建立分散式可用性群組，請使用 `CREATE AVAILABILITY GROUP`搭配 `DISTRIBUTED`選項。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-sql-server-to-aws-using-distributed-availability-groups.html) | DBA、開發人員 | 
| 在 AG 2 上建立分散式可用性群組。 | 若要在 AG 2 上建立分散式可用性群組，請使用 `ALTER AVAILABILITY GROUP`搭配 `DISTRIBUTED`選項。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-sql-server-to-aws-using-distributed-availability-groups.html)分散式可用性群組是在 AG 1 和 AG 2 之間建立。AG 2 中的資料庫尚未設定為參與從 AG 1 到 AG 2 的資料流程。 | DBA、開發人員 | 
| 將資料庫新增至 AG 2 上的轉送器和次要複本。 | 使用 `ALTER DATABASE` 搭配 AG 2 上轉送器和次要複本中的 `SET HADR``AVAILABILITY GROUP`選項，將資料庫新增至分散式可用性群組。 這會在 AG 1 和 AG 2 上的資料庫之間啟動非同步資料流程。 全域主要會進行寫入、同步傳送資料至 AG 1 上的次要複本，以及非同步傳送資料至 AG 2 上的轉送器。AG 2 上的轉送器會將資料同步傳送至 AG 2 上的次要複本。 | DBA、開發人員 | 

### 監控 AG 1 和 AG 2 之間的非同步資料流程
<a name="monitor-asynchronous-data-flow-between-ag-1-and-ag-2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 DMVs和 SQL Server 日誌。 | 使用動態管理檢視 (DMVs) 和 SQL Server 日誌，監控兩個可用群組之間的資料流程狀態。 需要監控的 DMVs 包括 `sys.dm_hadr_availability_replica_states`和 `sys.dm_hadr_automatic_seeding`。對於轉送器同步狀態，請監控轉送器上 SQL Server 日誌中的*同步狀態*。 | DBA、開發人員 | 

### 執行最終遷移的切換活動
<a name="perform-cutover-activities-for-final-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止所有流向主要複本的流量。 | 停止傳入至 AG 1 中主要複本的流量，以便在資料庫上不會發生寫入活動，且資料庫已準備好進行遷移。 | 應用程式擁有者、開發人員 | 
| 變更 AG 1 上分散式可用性群組的可用性模式。 | 在主要複本上，將分散式可用性群組的可用性模式設定為同步。 將可用性模式變更為同步後，資料會從 AG 1 中的主要複本同步傳送至 AG 2 中的轉寄站。 | DBA、開發人員 | 
| 檢查兩個可用群組中的 LSNs。 | 檢查 AG 1 和 AG 2 中的最後一個日誌序號 (LSNs)。由於 AG 1 的主要複本中沒有發生寫入，因此資料會同步，且兩個可用性群組的最後一個 LSNs 應相符。 | DBA、開發人員 | 
| 將 AG 1 更新為次要角色。 | 當您將 AG 1 更新為次要角色時，AG 1 會失去主要複本角色，且不接受寫入，且兩個可用群組之間的資料流程會停止。 | DBA、開發人員 | 

### 容錯移轉至第二個可用性群組
<a name="fail-over-to-the-second-availability-group"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 手動容錯移轉至 AG 2。 | 在 AG 2 中的轉送器上，變更分散式可用性群組以允許資料遺失。由於您已檢查並確認 AG 1 和 AG 2 上的最後一個 LSNs 相符，因此資料遺失並非問題。當您在 AG 2 中允許轉送器上的資料遺失時，AG 1 和 AG 2 的角色會變更：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-sql-server-to-aws-using-distributed-availability-groups.html) | DBA、開發人員 | 
| 變更 AG 2 上分散式可用性群組的可用性模式。 | 在 AG 2 的主要複本上，將可用性模式變更為非同步。這會將資料從 AG 2 移動到 AG 1，從同步移動到非同步。此步驟是必要的，以避免 AG 2 和 AG 1 之間的網路延遲，如果有的話，而且不會影響資料庫的效能。 | DBA、開發人員 | 
| 開始將流量傳送至新的主要複本。 | 更新連線字串，以使用 AG 2 上的接聽程式 URL 端點將流量傳送至資料庫。AG 2 現在接受寫入並將資料傳送至 AG 1 中的轉寄站，以及將資料傳送至 AG 2 中自己的次要複本。資料從 AG 2 非同步移動到 AG 1。 | 應用程式擁有者、開發人員 | 

### 執行切換後活動
<a name="perform-post-cutover-activities"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 AG 2 上捨棄分散式可用性群組。 | 監控遷移的計劃時間量。然後捨棄 AG 2 上的分散式可用性群組，以移除 AG 2 和 AG 1 之間的分散式可用性群組設定。這會移除分散式可用性群組組態，而且從 AG 2 到 AG 1 的資料流程會停止。 此時，AG 2 可在 AWS 上高度使用，主要複本需要寫入，次要複本位於相同的可用性群組中。 | DBA、開發人員 | 
| 停用內部部署伺服器。 | 在屬於 AG 1 的 WSFC 1 中停用內部部署伺服器。 | 系統管理員、SysOps 管理員 | 

## 相關資源
<a name="migrate-sql-server-to-aws-using-distributed-availability-groups-resources"></a>
+ [分散式可用性群組](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-sql-server/distributed-groups.html)
+ [SQL 文件：分散式可用性群組](https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/distributed-availability-groups?view=sql-server-ver15)
+ [SQL 文件： Always On 可用性群組：高可用性和災難復原解決方案](https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/always-on-availability-groups-sql-server?view=sql-server-ver15)

# 在 上將關聯式資料庫遷移至 MongoDB Atlas AWS
<a name="migrate-relational-database-to-mongodb-atlas"></a>

*Battulga Purevragchaa 和 Igor Alekseev，Amazon Web Services*

*Babu Srinivasan，MongoDB*

## 摘要
<a name="migrate-relational-database-to-mongodb-atlas-summary"></a>

此模式說明從關聯式資料庫遷移到 中 MongoDB Atlas 的步驟，例如 SQL Server、MySQL 或 PostgreSQL AWS 雲端。它使用 [MongoDB Relational Migrator](https://www.mongodb.com/products/relational-migrator) 協助加速從關聯式資料庫到 MongoDB Atlas 的資料遷移。

模式隨附於 AWS 上的[遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/) 指南指南網站上的指南。它提供該指南中討論的其中一個遷移案例的實作步驟。如需其他遷移案例，請參閱 AWS 規範指引網站上的下列模式：
+ [在 上將自我託管的 MongoDB 環境遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud.html)
+ [在 上將資料從 IBM Db2、SAP、Sybase 和其他資料庫串流至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/stream-data-from-ibm-db2-to-mongodb-atlas.html)

此模式 適用於 [AWS System Integrator (SI) 合作夥伴](https://aws.amazon.com/managed-services/partners/)和 AWS 使用者。

## 先決條件和限制
<a name="migrate-relational-database-to-mongodb-atlas-prereqs"></a>

**先決條件**
+ 要遷移至 MongoDB Atlas 的來源關聯式資料庫 (Oracle Database、SQL Server、PostgreSQL、MySQL、SAP/Sybase ASE 等）。
+ 熟悉關聯式資料庫、MongoDB Atlas 和 AWS 服務。此模式說明一些高層級的遷移步驟。其他詳細資訊將在未來的版本中新增。

**產品版本**
+ MongoDB 5.0 版或更新版本

## Architecture
<a name="migrate-relational-database-to-mongodb-atlas-architecture"></a>

下圖顯示從關聯式資料庫管理系統 (RDBMS) 資料庫遷移至 MongoDB Atlas 的作業 AWS。

![\[從 RDBMS 遷移到 AWS 上 MongoDB Atlas 的架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/4e3ea0f1-21e8-4641-a9ee-732355f20baf/images/8eacf3ec-f480-4912-9002-6a50800fe9bf.png)


如需支援不同使用案例的 MongoDB Atlas 參考架構，請參閱 AWS Prescriptive Guidance 網站上的[遷移至 上的 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/architecture.html)。

## 工具
<a name="migrate-relational-database-to-mongodb-atlas-tools"></a>
+ [MongoDB Atlas](https://www.mongodb.com/atlas) 是全受管資料庫即服務 (DBaaS)，用於在雲端中部署和管理 MongoDB 資料庫。
+ [MongoDB Relational Migrator](https://www.mongodb.com/products/relational-migrator) 可將資料從傳統關聯式資料庫順暢地轉換為 MongoDB。它有助於自動化轉換程序，並將關聯式資料庫的結構化資料模型轉換為 MongoDB 提供的彈性文件格式。Relational Migrator 會保留資料完整性和關係，以簡化遷移。組織可以利用 MongoDB 提供的可擴展性、效能和多樣性優勢，同時保持現有資料的熟悉度。

## 最佳實務
<a name="migrate-relational-database-to-mongodb-atlas-best-practices"></a>

如需在 上使用 MongoDB 的最佳實務 AWS，請參閱 [AWS 合作夥伴網路部落格](https://aws.amazon.com/blogs/apn/tag/mongodb-atlas/)上的文章。

## 史詩
<a name="migrate-relational-database-to-mongodb-atlas-epics"></a>

### 探索和評估
<a name="discovery-and-assessment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 決定關聯式資料庫的參數和大小。 | 使用關聯式 Migrator 建議和來自 的資訊來估計工作集大小，`db.stats()`以取得總索引空間。假設經常存取您資料空間的百分比。此任務大約需要一週的時間。如需此範例和其他案例的詳細資訊和範例，請參閱[相關資源](#migrate-relational-database-to-mongodb-atlas-resources)一節。 | 應用程式擁有者，DBA | 
| 估計網路頻寬需求。 | 若要估算您的網路頻寬需求，請將平均文件大小乘以每秒提供的文件數量。請考慮叢集上任何節點所承擔的最大流量。若要計算從叢集到用戶端應用程式的下游資料傳輸率，請使用一段時間內傳回文件總數的總和。如果您的應用程式從次要節點讀取，請將總文件數除以可提供讀取操作的節點數。若要尋找資料庫的平均文件大小，請使用 `db.stats().avgObjSize`命令。此任務通常需要一天的時間。 | DBA | 
| 選取 Atlas 層。 | 遵循 [MongoDB 文件](https://www.mongodb.com/docs/atlas/sizing-tier-selection/)中的指示，選取正確的 Atlas 叢集層。 | DBA | 
| 規劃切換。 | 規劃應用程式切換。 | DBA、應用程式擁有者 | 

### 在 上設定新的 MongoDB Atlas 環境 AWS
<a name="set-up-a-new-mongodb-atlas-environment-on-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 上建立新的 MongoDB Atlas 叢集 AWS。 | 在 MongoDB Atlas 中，選擇**建置叢集**。在**建立新叢集**對話方塊中，選取 AWS 做為雲端供應商。 | DBA | 
| 選取 AWS 區域 和 全域叢集組態。 | 從 AWS 區域 Atlas 叢集可用的 清單中選取 。視需要設定全域叢集。 | DBA | 
| 選取叢集層。 | 選取您偏好的叢集層。您的方案選擇會決定記憶體、儲存體和 IOPS 規格等因素。 | DBA | 
| 設定其他叢集設定。 | 設定其他叢集設定，例如 MongoDB 版本、備份和加密選項。如需這些選項的詳細資訊，請參閱[相關資源](#migrate-relational-database-to-mongodb-atlas-resources)一節。 | DBA | 

### 設定安全與合規
<a name="configure-security-and-compliance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定存取清單。 | 若要連線至 Atlas 叢集，您必須將項目新增至專案的存取清單。Atlas 使用 TLS/SSL 來加密與資料庫虛擬私有雲端 (VPC) 的連線。若要設定專案的存取清單，以及有關此史詩中故事的詳細資訊，請參閱[相關資源](#migrate-relational-database-to-mongodb-atlas-resources)一節。 | DBA | 
| 驗證和授權使用者。 | 您必須建立和驗證將存取 MongoDB Atlas 叢集的資料庫使用者。若要存取專案中的叢集，使用者必須屬於該專案，而且可以屬於多個專案。 | DBA | 
| 建立自訂角色。 | （選用） 在內建 Atlas 資料庫使用者許可未涵蓋您想要的許可集的情況下，Atlas 支援建立自訂角色。 | DBA | 
| 設定 VPC 對等互連。 | （選用） Atlas 支援與其他 [VPC 對等互連](https://docs.aws.amazon.com/vpc/latest/peering/what-is-vpc-peering.html) AWS。 VPCs  | AWS 管理員 | 
| 設定 AWS PrivateLink 端點。 | （選用） 您可以使用 在 上設定私有端點 AWS AWS PrivateLink。如需詳細資訊，請參閱 [Amazon VPC 文件](https://docs.aws.amazon.com/vpc/latest/userguide/endpoint-services-overview.html)。 | AWS 管理員 | 
| 啟用雙重驗證。 | （選用） Atlas 支援雙重驗證 (2FA)，以協助使用者控制對其 Atlas 帳戶的存取。 | AWS 管理員 | 
| 使用 LDAP 設定使用者身分驗證和授權。 | （選用） Atlas 支援使用輕量型目錄存取通訊協定 (LDAP) 執行使用者身分驗證和授權。 | DBA | 
| 設定統一 AWS 存取。 | （選用） 某些 Atlas 功能，包括使用客戶金鑰管理的 Atlas Data Lake 和靜態加密，使用 AWS Identity and Access Management (IAM) 角色進行身分驗證。 | AWS 管理員 | 
| 使用 設定靜態加密 AWS KMS。 | （選用） Atlas 支援使用 AWS Key Management Service (AWS KMS) 加密儲存引擎和雲端供應商備份。 | AWS 管理員 | 
| 設定用戶端欄位層級加密。 | （選用） Atlas 支援用戶端欄位層級加密，包括欄位的自動加密。 | AWS 管理員 | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 MongoDB Relational Migrator 新增至存取清單。 | 將 Relational Migrator 新增至來源資料庫的存取清單。這有助於準備來源環境以連線到目標 Atlas 叢集。 | DBA | 
| 評估關聯式資料庫物件。 | 啟動 MongoDB Relational Migrator 並連線至您的關聯式資料庫。開始評估。 | DBA | 
| 接受遷移模式，或選擇根據您的業務需求進行修改。 | 您可以接受 Relational Migrator 根據初始評估和效能參數建議的資料庫模式，或選擇根據您的業務需求進行變更。 | DBA | 
| 在 MongoDB Atlas 中啟動您的目標複本集。 | 在 MongoDB Atlas 中啟動您的目標複本集。在關聯式 Migrator 中，選擇**我已準備好遷移**。 | DBA | 

### 設定操作整合
<a name="configure-operational-integration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 連線至 MongoDB Atlas 叢集。 | 請確定 MongoDB Atlas 叢集連線如預期般運作。 | 應用程式擁有者 | 
| 與叢集資料互動。 | 驗證叢集資料。 | DBA | 
| 監控您的叢集。 | 確認您的叢集設定正確。 | DBA | 
| 備份和還原叢集資料。 | 定期排程叢集資料的備份。 | DBA | 

## 相關資源
<a name="migrate-relational-database-to-mongodb-atlas-resources"></a>

除非另有說明，否則下列所有連結都會移至 MongoDB 文件中的網頁。

**遷移指南**
+ [在 上遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/) (AWS 方案指引）

**探索和評估**
+ [記憶體](https://docs.atlas.mongodb.com/sizing-tier-selection/#memory)
+ [使用 Atlas 範例資料集調整大小範例](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#example--the-service-sample-data-sets)
+ [行動應用程式的大小調整範例](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#example--mobile-app)
+ [網路流量](https://docs.atlas.mongodb.com/sizing-tier-selection/#network-traffic)
+ [叢集自動擴展](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#cluster-auto-scaling)
+ [Atlas 大小調整範本](https://view.highspot.com/viewer/5f438f47a4dfa042e97130c5)

**設定安全與合規**
+ [設定 IP 存取清單項目](https://docs.atlas.mongodb.com/security/ip-access-list/)
+ [設定資料庫使用者](https://docs.atlas.mongodb.com/security-add-mongodb-users/)
+ [設定對 Atlas UI 的存取](https://docs.atlas.mongodb.com/organizations-projects/)
+ [設定自訂資料庫角色](https://docs.atlas.mongodb.com/security-add-mongodb-roles)
+ [設定資料庫使用者](https://docs.atlas.mongodb.com/security-add-mongodb-users/#atlas-user-privileges)
+ [設定網路對等連線](https://docs.atlas.mongodb.com/security-vpc-peering/)
+ [了解 Atlas 中的私有端點](https://docs.atlas.mongodb.com/security-private-endpoint/)
+ [管理您的多重要素驗證選項](https://docs.atlas.mongodb.com/security-two-factor-authentication/)
+ [使用 LDAP 設定使用者身分驗證和授權](https://docs.atlas.mongodb.com/security-ldaps/)
+ [Atlas Data Lake](https://docs.mongodb.com/datalake/)
+ [使用客戶金鑰管理進行靜態加密](https://docs.atlas.mongodb.com/security-kms-encryption/)
+ [擔任角色的方法 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html)(IAM 文件）
+ [用戶端欄位層級加密](https://docs.mongodb.com/manual/core/security-client-side-encryption)
+ [自動加密](https://docs.mongodb.com/manual/core/security-automatic-client-side-encryption) 
+ [MongoDB Atlas 安全控制](https://webassets.mongodb.com/_com_assets/cms/MongoDB_Atlas_Security_Controls-v7k3rbhi3p.pdf)
+ [MongoDB 信任中心](https://www.mongodb.com/cloud/trust)
+ [設定叢集的安全功能](https://docs.atlas.mongodb.com/setup-cluster-security/)

**在 上設定新的 MongoDB Atlas 環境 ****AWS**
+ [雲端供應商和區域](https://docs.atlas.mongodb.com/cloud-providers-regions/)
+ [管理全域叢集](https://docs.atlas.mongodb.com/global-clusters/)
+ [選取叢集層](https://www.mongodb.com/docs/atlas/manage-clusters/#select-cluster-tier)
+ [設定其他設定](https://docs.atlas.mongodb.com/cluster-additional-settings/)
+ [Atlas 入門](https://docs.atlas.mongodb.com/getting-started/)
+ [設定對 Atlas UI 的存取](https://docs.atlas.mongodb.com/organizations-projects/)

**遷移資料**
+ [遷移或匯入資料](https://www.mongodb.com/docs/atlas/import/)

**監控叢集**
+ [監控您的叢集](https://docs.atlas.mongodb.com/monitoring-alerts/)

**整合 操作**
+ [連線至叢集](https://docs.atlas.mongodb.com/connect-to-cluster/)
+ [與您的資料互動](https://docs.atlas.mongodb.com/data-explorer/)
+ [監控您的叢集](https://docs.atlas.mongodb.com/monitoring-alerts/)
+ [備份、還原和封存資料](https://docs.atlas.mongodb.com/backup-restore-cluster/)

# 在 上將自我託管的 MongoDB 環境遷移至 MongoDB Atlas AWS
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud"></a>

*Battulga Purevragchaa 和 Igor Alekseev，Amazon Web Services*

*Babu Srinivasan，MongoDB*

## 摘要
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-summary"></a>

此模式說明從自我管理的 MongoDB 環境 （包括 MongoDB Community Server、Enterprise Server、Enterprise Advanced、mLab 或任何受管 MongoDB 叢集） 遷移至 中的 MongoDB Atlas 的步驟 AWS 雲端。它使用 [Atlas Live Migration Service](https://www.mongodb.com/cloud/atlas/migrate) 來協助加速從 MongoDB 到 MongoDB Atlas 的資料遷移。

模式隨附於 AWS 上的[遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/) 指南指南網站上的指南。它提供該指南中討論的其中一個遷移案例的實作步驟。如需其他遷移案例，請參閱 AWS 規範指引網站上的下列模式：
+ [在 上將關聯式資料庫遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-relational-database-to-mongodb-atlas.html)
+ [在 上將資料從 IBM Db2、SAP、Sybase 和其他資料庫串流至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/stream-data-from-ibm-db2-to-mongodb-atlas.html)

此模式適用於 [AWS Systems Integrator (SI) 合作夥伴](https://aws.amazon.com/managed-services/partners/)和 AWS 使用者。

## 先決條件和限制
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-prereqs"></a>

**先決條件**
+ 要遷移至 MongoDB Atlas 的來源 MongoDB Enterprise Advanced、Community Server 或其他自我管理的 MongoDB 環境。
+ 熟悉 MongoDB、MongoDB Atlas 和 AWS 服務。此模式說明一些高層級的遷移步驟。其他詳細資訊將在未來的版本中新增。

**產品版本**
+ MongoDB 6.0.13 版或更新版本

## Architecture
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-architecture"></a>

下圖顯示 Atlas Live Migration Service，用於將資料從 MongoDB Enterprise Advanced 資料庫和 MongoDB Community 資料庫遷移至 MongoDB Atlas AWS。當您需要將大型、複雜的資料庫遷移至 MongoDB Atlas 時，請使用此服務，將停機時間和持續資料同步降到最低。此模式使用 Atlas Live Migration Service。

![\[使用 MongoDB Atlas Live Migration Service 遷移資料。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/52cdb923-64ff-4ee2-b129-93b9a139e24b/images/372134c4-ba47-4e48-bd0d-8b43017773b8.png)


下圖顯示 MongoDB 鏡像服務 (`mongomirror`)，您也可以用來 AWS 透過安全[AWS PrivateLink](https://aws.amazon.com/privatelink/)連線將資料從 MongoDB Enterprise Advanced 資料庫和 MongoDB Community 資料庫遷移到 上的 MongoDB Atlas。`mongomirror` 用於內部部署 MongoDB 和 MongoDB Atlas 之間的持續資料複寫。此工具非常適合災難復原或分階段遷移，但超出此模式的範圍。

![\[使用 mongomirror 工具遷移資料。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/52cdb923-64ff-4ee2-b129-93b9a139e24b/images/53488a9b-2210-4b3d-b517-b618c1e0182c.png)


如需支援不同使用案例的更多 MongoDB Atlas 參考架構，請參閱 AWS 《 方案指引》網站上的[遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/architecture.html)。

## 工具
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-tools"></a>
+ [MongoDB Atlas](https://www.mongodb.com/atlas) 是全受管資料庫即服務 (DbaaS)，用於在雲端中部署和管理 MongoDB 資料庫。
+ [Atlas Live Migration Service](https://www.mongodb.com/cloud/atlas/migrate) 是免費的 MongoDB 公用程式，可協助將資料庫遷移至 Atlas。此服務會讓來源資料庫與目的地資料庫保持同步，直到切換為止。當您準備好切換時，您可以停止應用程式執行個體，將它們指向目的地 Atlas 叢集，然後重新啟動它們。若要存取此服務，請從 MongoDB Atlas 叢集中選擇**資料庫選項**。
+ [mongomirror](https://www.mongodb.com/docs/atlas/import/mongomirror/) 是一種工具，可將現有 MongoDB 複本集的資料手動遷移至 MongoDB Atlas 複本集。 `mongomirror`不需要您關閉現有的複本集或應用程式、不匯入使用者或角色資料，或複製組態資料庫。您可以從 `mongomirror` [MongoDB 文件](https://www.mongodb.com/docs/atlas/import/mongomirror/#download-mongomirror)下載 。

## 最佳實務
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-best-practices"></a>

如需在 上使用 MongoDB 的最佳實務 AWS，請參閱 [AWS 合作夥伴網路部落格](https://aws.amazon.com/blogs/apn/tag/mongodb-atlas/)上的文章。

## 史詩
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-epics"></a>

### 探索和評估
<a name="discovery-and-assessment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 決定叢集大小。 | 使用來自 的資訊估計工作集大小`db.stats()`，以取得總索引空間。假設經常存取您資料空間的百分比。或者，您可以根據自己的假設來預估記憶體需求。此任務大約需要一週的時間。如需此範例和其他案例的詳細資訊和範例，請參閱[相關資源](#migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-resources)一節。 | DBA、應用程式擁有者 | 
| 估計網路頻寬需求。 | 若要估算您的網路頻寬需求，請將平均文件大小乘以每秒提供的文件數量。請考慮叢集上任何節點所承擔的最大流量。若要計算從叢集到用戶端應用程式的下游資料傳輸率，請使用一段時間內傳回文件總數的總和。如果您的應用程式從次要節點讀取，請將總文件數除以可提供讀取操作的節點數。若要尋找資料庫的平均文件大小，請使用 `db.stats().avgObjSize`命令。此任務通常需要一天的時間。 | DBA | 
| 選取 Atlas 層。 | 遵循 [MongoDB 文件](https://www.mongodb.com/docs/atlas/sizing-tier-selection/)中的指示，選取正確的 Atlas 叢集層。 | DBA | 
| 規劃切換。 | 規劃應用程式切換。 | DBA、應用程式擁有者 | 

### 在 AWS 上設定新的 MongoDB Atlas 環境
<a name="set-up-a-new-mongodb-atlas-environment-on-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 上建立新的 MongoDB Atlas 叢集 AWS。 | 登入 Atlas 並開啟專案的**概觀**頁面。選擇**建立**按鈕來建立叢集。如需詳細資訊，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/atlas/tutorial/deploy-free-tier-cluster/)。 | DBA | 
| 選取 AWS 區域 和 全域叢集組態。 | 從 AWS 區域 Atlas 叢集可用的 清單中選取 。視需要設定全域叢集。如需詳細資訊，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/atlas/tutorial/deploy-free-tier-cluster/#select-your-preferred-region.)。 | DBA | 
| 選取叢集層。 | 選取您偏好的叢集層。您的方案選擇會決定記憶體、儲存體和 IOPS 規格等因素。 | DBA | 
| 設定其他叢集設定。 | 設定其他叢集設定，例如 MongoDB 版本、備份和加密選項。如需這些選項的詳細資訊，請參閱[相關資源](#migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-resources)一節。 | DBA | 

### 設定安全與合規
<a name="configure-security-and-compliance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證和授權使用者。 | 您必須建立和驗證將存取 MongoDB Atlas 叢集的資料庫使用者。若要存取專案中的叢集，使用者必須屬於該專案，而且可以屬於多個專案。 Atlas 也支援以 AWS Identity and Access Management (IAM) 為基礎的身分驗證。如需詳細資訊，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/atlas/security/aws-iam-authentication/#set-up-authentication-with-aws-iam)。 | DBA | 
| 建立自訂角色。 | （選用） 在內建 Atlas 資料庫使用者許可未涵蓋您想要的許可集的情況下，Atlas 支援建立自訂角色。 | DBA | 
| 設定 VPC 對等互連。 | （選用） Atlas 支援虛擬[私有雲端 (VPC) 與其他 VPC 對等互連](https://docs.aws.amazon.com/vpc/latest/peering/what-is-vpc-peering.html) AWS。 VPCs  | AWS 管理員 | 
| 設定 AWS PrivateLink 端點。 | （選用） 您可以使用 在 上設定私有端點 AWS AWS PrivateLink。如需詳細資訊，請參閱 [Amazon VPC 文件](https://docs.aws.amazon.com/vpc/latest/userguide/endpoint-services-overview.html)。 | AWS 管理員 | 
| 啟用雙重驗證。 | （選用） Atlas 支援雙重驗證 (2FA)，以協助使用者控制對其 Atlas 帳戶的存取。 | AWS 管理員 | 
| 使用 LDAP 設定使用者身分驗證和授權。 | （選用） Atlas 支援使用輕量型目錄存取通訊協定 (LDAP) 執行使用者身分驗證和授權。 | AWS 管理員 | 
| 設定統一 AWS 存取。 | （選用） 某些 Atlas 功能，包括使用客戶金鑰管理的 Atlas Data Lake 和靜態加密，請使用 IAM 角色進行身分驗證。 | AWS 管理員 | 
| 使用 設定靜態加密 AWS KMS。 | （選用） Atlas 支援使用 AWS Key Management Service (AWS KMS) 加密儲存引擎和雲端供應商備份。 | AWS 管理員 | 
| 設定用戶端欄位層級加密。 | （選用） Atlas 支援用戶端欄位層級加密，包括欄位的自動加密。 | AWS 管理員 | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 MongoDB Atlas 中選取您的目標複本集。 | 導覽至目的地 Atlas 叢集，然後選擇省略符號 (...) 按鈕。在叢集清單中，此按鈕會出現在叢集名稱下方。在叢集詳細資訊中，按鈕會出現在右側連線****和**組態**按鈕旁。如需詳細資訊，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/atlas/import/c2c-pull-live-migration/#procedure)。 | DBA | 
| 將 Atlas Live Migration Service 新增至存取清單。 | 將 Atlas Live Migration Service 新增至 AWS 來源叢集中的存取清單。這有助於準備來源環境以連線到目標 Atlas 叢集。 | DBA | 
| 使用 Atlas Live Migration Service 執行遷移。 | 選擇**開始遷移**。當**準備切換**按鈕變成綠色時，請執行切換。檢閱 Atlas 叢集效能指標。考慮更新所有應用程式層中的資料庫連線，以指向新的資料庫。 | DBA | 

### 設定操作整合
<a name="configure-operational-integration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 連線至 MongoDB Atlas 叢集。 | 確定 MongoDB Atlas 叢集連線如預期般運作。 | 應用程式擁有者 | 
| 與叢集資料互動。 | 測試叢集資料。 | DBA | 
| 監控您的叢集。 | 確認您的叢集已正確設定。 | DBA | 
| 備份和還原叢集資料。 | 定期排程叢集資料的備份。 | DBA | 

## 疑難排解
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 錯誤：無法連線到指定的來源 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud.html) | 
| 錯誤：無法解析主機名稱 | 找不到指定主機名稱的 IP 地址。確認指定的主機名稱正確且可公開存取。 | 
| 任何其他錯誤 | 如果您遇到任何其他錯誤，請參閱 MongoDB 文件中的[即時遷移 (Pull) 故障診斷](https://www.mongodb.com/docs/atlas/import/live-import-troubleshooting/)。 | 

## 相關資源
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-resources"></a>

除非另有說明，否則下列所有連結都會移至 MongoDB 文件中的網頁。

**遷移指南**
+ [在 上遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/) (AWS 方案指引）

**舊版遷移**
+ [MongoDB 舊版的遷移](https://www.mongodb.com/docs/atlas/legacy-migration/)

**探索和評估**
+ [記憶體](https://docs.atlas.mongodb.com/sizing-tier-selection/#memory)
+ [使用 Atlas 範例資料集調整大小範例](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#example--the-service-sample-data-sets)
+ [行動應用程式的大小調整範例](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#example--mobile-app)
+ [網路流量](https://docs.atlas.mongodb.com/sizing-tier-selection/#network-traffic)
+ [叢集自動擴展](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#cluster-auto-scaling)
+ [Atlas 大小調整範本](https://view.highspot.com/viewer/5f438f47a4dfa042e97130c5)

**設定安全與合規**
+ [設定 IP 存取清單項目](https://docs.atlas.mongodb.com/security/ip-access-list/)
+ [設定資料庫使用者](https://docs.atlas.mongodb.com/security-add-mongodb-users/)
+ [設定對 Atlas UI 的存取](https://docs.atlas.mongodb.com/organizations-projects/)
+ [設定自訂資料庫角色](https://docs.atlas.mongodb.com/security-add-mongodb-roles)
+ [設定資料庫使用者](https://docs.atlas.mongodb.com/security-add-mongodb-users/#atlas-user-privileges)
+ [設定網路對等連線](https://docs.atlas.mongodb.com/security-vpc-peering/)
+ [了解 Atlas 中的私有端點](https://docs.atlas.mongodb.com/security-private-endpoint/)
+ [管理您的多重要素驗證選項](https://docs.atlas.mongodb.com/security-two-factor-authentication/)
+ [使用 LDAP 設定使用者身分驗證和授權](https://docs.atlas.mongodb.com/security-ldaps/)
+ [Atlas Data Lake](https://docs.mongodb.com/datalake/)
+ [使用客戶金鑰管理進行靜態加密](https://docs.atlas.mongodb.com/security-kms-encryption/)
+ [擔任角色的方法 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html)(IAM 文件）
+ [用戶端欄位層級加密](https://docs.mongodb.com/manual/core/security-client-side-encryption)
+ [自動加密](https://docs.mongodb.com/manual/core/security-automatic-client-side-encryption) 
+ [MongoDB Atlas 安全控制](https://webassets.mongodb.com/_com_assets/cms/MongoDB_Atlas_Security_Controls-v7k3rbhi3p.pdf)
+ [MongoDB 信任中心](https://www.mongodb.com/cloud/trust)
+ [設定叢集的安全功能](https://docs.atlas.mongodb.com/setup-cluster-security/)

**在 上設定新的 MongoDB Atlas 環境 ****AWS**
+ [雲端供應商和區域](https://docs.atlas.mongodb.com/cloud-providers-regions/)
+ [管理全域叢集](https://docs.atlas.mongodb.com/global-clusters/)
+ [選取叢集層](https://www.mongodb.com/docs/atlas/manage-clusters/#select-cluster-tier)
+ [設定其他設定](https://docs.atlas.mongodb.com/cluster-additional-settings/)
+ [Atlas 入門](https://docs.atlas.mongodb.com/getting-started/)
+ [設定對 Atlas UI 的存取](https://docs.atlas.mongodb.com/organizations-projects/)

**遷移資料**
+ [遷移或匯入資料](https://www.mongodb.com/docs/atlas/import/)

**監控叢集**
+ [監控您的叢集](https://docs.atlas.mongodb.com/monitoring-alerts/)

**整合 操作**
+ [連線至叢集](https://docs.atlas.mongodb.com/connect-to-cluster/)
+ [與您的資料互動](https://docs.atlas.mongodb.com/data-explorer/)
+ [監控您的叢集](https://docs.atlas.mongodb.com/monitoring-alerts/)
+ [備份、還原和封存資料](https://docs.atlas.mongodb.com/backup-restore-cluster/)

**訓練**
+ [使用 MongoDB Atlas 即時遷移](https://learn.mongodb.com/courses/live-migration-with-mongodb-atlas)

## 其他資訊
<a name="migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud-additional"></a>

如需詳細資訊，請參閱 MongoDB 文件中的下列主題：
+ 若要將資料移至無伺服器執行個體，[請使用 Compass 匯出和匯入資料](https://www.mongodb.com/docs/compass/current/import-export/)，或使用自我管理工具遷移資料。若要進一步了解，請參閱[無伺服器執行個體限制](https://www.mongodb.com/docs/atlas/reference/serverless-instance-limitations/)。
+ 若要將資料載入 Atlas 中的新叢集，請參閱[將資料載入 Atlas。](https://www.mongodb.com/docs/atlas/sample-data/#std-label-sample-data)
+ 若要複製叢集以供測試之用，請參閱[自我管理部署的備份方法](https://www.mongodb.com/docs/manual/core/backups/)。
+ 如果您想要遷移的應用程式需要接近連續的執行時間，請聯絡 [MongoDB Support](https://www.mongodb.com/docs/atlas/support/#std-label-request-support) 並分享您的執行時間需求和叢集組態。
+ 如需詳細資訊，請參閱[遷移或匯入資料](https://www.mongodb.com/docs/atlas/import/)。

# 使用 AWS DMS 將 Oracle 資料庫遷移至 Amazon DynamoDB
<a name="migrate-an-oracle-database-to-amazon-dynamodb-using-aws-dms"></a>

*Rambabu Karnena，Amazon Web Services*

## 總結
<a name="migrate-an-oracle-database-to-amazon-dynamodb-using-aws-dms-summary"></a>

此模式會逐步引導您使用 AWS Database Migration Service ([AWS DMS](https://aws.amazon.com/dms/)) 將 Oracle 資料庫遷移至 [Amazon DynamoDB](https://aws.amazon.com/dynamodb/) 的步驟。它涵蓋三種類型的來源資料庫：
+ 內部部署 Oracle 資料庫
+ Amazon Elastic Compute Cloud ([Amazon EC2](https://aws.amazon.com/ec2/)) 上的 Oracle 資料庫
+ Oracle 資料庫執行個體的 Amazon Relational Database Service ([Amazon RDS](https://aws.amazon.com/rds/))

在此概念驗證中，此模式著重於從 Amazon RDS for Oracle 資料庫執行個體遷移。

## 先決條件和限制
<a name="migrate-an-oracle-database-to-amazon-dynamodb-using-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 連線至 Amazon RDS for Oracle 資料庫的應用程式
+ 在來源 Amazon RDS for Oracle 資料庫中建立的資料表，其中包含主索引鍵和範例資料

**限制**
+ 由於 Amazon DynamoDB 不支援這些資料庫物件，因此不會考慮遷移 Oracle 資料庫物件，例如程序、函數、套件和觸發程序。

**產品版本**
+ 此模式適用於 AWS DMS 支援的所有 Oracle 資料庫版本。如需詳細資訊，請參閱使用 [Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)，以及使用 [Amazon DynamoDB 資料庫做為 AWS DMS 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.DynamoDB.html)。我們建議您使用最新版本的 AWS DMS，以獲得最全面的版本和功能支援。

## Architecture
<a name="migrate-an-oracle-database-to-amazon-dynamodb-using-aws-dms-architecture"></a>

**來源技術堆疊**
+ Amazon RDS for Oracle 資料庫執行個體、Amazon EC2 上的 Oracle 或內部部署 Oracle 資料庫

**目標技術堆疊**
+ Amazon DynamoDB

**AWS 資料遷移架構**

![\[資料從 Oracle 資料庫移至 AWS DMS 到 Amazon DynamoDB。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/463fc7d4-ec8d-473b-8c7f-1df31800ee03/images/180e7340-3887-455d-a591-b5850e22770a.png)


## 工具
<a name="migrate-an-oracle-database-to-amazon-dynamodb-using-aws-dms-tools"></a>
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) 是一項全受管 NoSQL 資料庫服務，可提供快速、可預期且可擴展的效能。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。此模式使用 Amazon RDS for Oracle。

## 史詩
<a name="migrate-an-oracle-database-to-amazon-dynamodb-using-aws-dms-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 VPC。 | 在您的 AWS 帳戶中，建立虛擬私有雲端 (VPC) 和私有子網路。 | 系統管理員 | 
| 建立安全群組和網路存取控制清單。 | 如需詳細資訊，請參閱 [AWS 文件](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html)。 | 系統管理員 | 
| 設定和啟動 Amazon RDS for Oracle 資料庫執行個體。 | 如需詳細資訊，請參閱 [AWS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html)。 | DBA，系統管理員 | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 IAM 角色以存取 DynamoDB。 | 在 AWS Identity and Access Management (IAM) 主控台中，建立角色、連接政策 `AmazonDynamoDBFullAccess to it`，然後選取 AWS DMS 做為服務。 | 系統管理員 | 
| 建立 AWS DMS 複寫執行個體以進行遷移。 | 複寫執行個體應與來源資料庫位於相同的可用區域和 VPC 中。 | 系統管理員 | 
| 在 AWS DMS 中建立來源和目標端點。 | 若要建立來源資料庫端點，您有兩個選項：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-an-oracle-database-to-amazon-dynamodb-using-aws-dms.html)若要建立目標資料庫端點，請從先前的任務中選擇角色 Amazon Resource Name (ARN)，以存取 DynamoDB。 | 系統管理員 | 
| 建立 AWS DMS 任務，將來源 Oracle 資料庫資料表載入 DynamoDB。 | 從先前的步驟中選擇來源和目的地端點名稱，以及複寫執行個體。類型可以是完全載入。選擇 Oracle 結構描述，並指定 **%** 來選取所有資料表。 | 系統管理員 | 
| 驗證 DynamoDB 中的資料表。 | 若要檢視遷移結果，請從 DynamoDB 主控台的左側導覽窗格中選擇**資料表**。 | DBA | 

### 遷移應用程式
<a name="migrate-the-application"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 修改應用程式程式碼。 | 若要連線至 DynamoDB 並從 DynamoDB 擷取資料，請更新應用程式程式碼。 | 應用程式擁有者、DBA、系統管理員 | 

### 切換
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 切換應用程式用戶端以使用 DynamoDB。 |  | DBA、應用程式擁有者、系統管理員 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉 AWS 資源。 | 例如， 關閉 Amazon RDS for Oracle 執行個體、DynamoDB 和 AWS DMS 複寫執行個體。 | DBA，系統管理員 | 
| 收集指標。 | 指標包括遷移時間、手動工作和工具執行工作的百分比，以及節省成本。 | DBA、應用程式擁有者、系統管理員 | 

## 相關資源
<a name="migrate-an-oracle-database-to-amazon-dynamodb-using-aws-dms-resources"></a>
+ [AWS Database Migration Service 和 Amazon DynamoDB：須知事項 ](https://aws.amazon.com/blogs/database/aws-database-migration-service-and-amazon-dynamodb-what-you-need-to-know/)（部落格文章）
+ [使用 Oracle 資料庫做為 AWS DMS 的來源](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)
+ [使用 Amazon DynamoDB 資料庫做為 AWS Database Migration Service 的目標](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.DynamoDB.html)
+ [從 RDBMS 遷移至 Amazon DynamoDB 的最佳實務](https://docs.aws.amazon.com/whitepapers/latest/best-practices-for-migrating-from-rdbms-to-dynamodb/welcome.html) （白皮書）

# 使用 SharePlex 和 AWS DMS 從 Oracle 8i 或 9i 遷移至 Amazon RDS for Oracle
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms"></a>

*Ramu Jagini，Amazon Web Services*

## 總結
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms-summary"></a>

此模式說明如何將內部部署 Oracle 8i 或 9i 資料庫遷移至適用於 Oracle 資料庫的 Amazon Relational Database Service (Amazon RDS)。您可以使用此模式，透過使用 Quest SharePlex 進行同步複寫，以縮短停機時間來完成遷移。

您必須使用中繼 Oracle 資料庫執行個體進行遷移，因為 AWS Database Migration Service (AWS DMS) 不支援 Oracle 8i 或 9i 作為來源環境。您可以使用 [SharePlex 7.6.3](https://www.quest.com/community/shareplex/f/forum/20700/where-can-download-7-6-3-or-support-9i-shareplex) 從先前的 Oracle 資料庫版本複寫到更新的 Oracle 資料庫版本。中繼 Oracle 資料庫執行個體與 SharePlex 7.6.3 的目標相容，並支援做為 AWS DMS 的來源或較新版本的 SharePlex。此支援可將資料後續複寫至 Amazon RDS for Oracle 目標環境。

請考慮數種已棄用資料類型和功能可能會影響從 Oracle 8i 或 9i 遷移至最新版 Oracle 資料庫。為了減輕此影響，此模式使用 Oracle 11.2.0.4 做為中繼資料庫版本，以協助在遷移至 Amazon RDS for Oracle 目標環境之前最佳化結構描述程式碼。

## 先決條件和限制
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署環境中的來源 Oracle 8i 或 9i 資料庫
+ Amazon Elastic Compute Cloud (Amazon EC2) 上的預備 [Oracle 資料庫 12c 版本](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/index.html) 2 (12CR2)Amazon EC2
+ Quest SharePlex 7.6.3 （商業等級）

**限制**
+ [RDS for Oracle 限制](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Oracle.Concepts.limitations.html)

**產品版本**
+ 來源資料庫的 Oracle 8i 或 9i
+ 預備資料庫的 Oracle 12CR2 （必須與 Amazon RDS for Oracle 版本相符）
+ 目標資料庫的 Oracle 12CR2 或更新版本 (Amazon RDS for Oracle)

## Architecture
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms-architecture"></a>

**來源技術堆疊**
+ Oracle 8i 或 9i 資料庫
+ SharePlex

**目標技術堆疊**
+ Amazon RDS for Oracle

**遷移架構**

下圖顯示如何將 Oracle 8i 或 9i 資料庫從內部部署環境遷移至 AWS 雲端中的 Amazon RDS for Oracle 資料庫執行個體。

![\[將現場部署 Oracle 資料庫遷移至 Amazon RDS on AWS 的工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/6e07d586-fd74-4f3d-8e81-79dd55c445c3/images/36e1a5ff-908b-4cb7-96f7-997eb105f1d6.png)


該圖顯示以下工作流程：

1. 使用封存日誌模式、強制記錄和補充記錄來啟用 Oracle 來源資料庫。

1. 使用 Recovery Manager (RMAN) point-in-time復原和 [FLASHBACK\$1SCN](https://docs.oracle.com/database/121/SUTIL/GUID-D408B112-1A81-4F68-BEFF-7403A9588DDB.htm#SUTIL849)，從 Oracle 來源資料庫還原 Oracle 預備資料庫。

1. 設定 SharePlex 使用 `FLASHBACK_SCN`（用於 RMAN) 從 Oracle 來源資料庫讀取重做日誌。

1. 啟動 SharePlex 複寫，將資料從 Oracle 來源資料庫同步到 Oracle 預備資料庫。

1. 使用 EXPDP 和 IMPDP 搭配 來還原 Amazon RDS for Oracle 目標資料庫`FLASHBACK_SCN`。

1. 使用 `FLASHBACK_SCN`（用於 EXPDP) 將 AWS DMS 及其來源任務設定為 Oracle 預備資料庫，並將 Amazon RDS for Oracle 設定為目標資料庫。

1. 啟動 AWS DMS 任務，將資料從 Oracle 預備資料庫同步至 Oracle 目標資料庫。

## 工具
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms-tools"></a>
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [Quest SharePlex](https://support.quest.com/shareplex/11.0/technical-documents) 是一種 Oracle-to-Oracle的資料複寫工具，可在最短的停機時間下移動資料，而不會遺失資料。
+ [Recovery Manager (RMAN)](https://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmquick.htm) 是 Oracle 資料庫用戶端，可在資料庫上執行備份和復原任務。它可大幅簡化資料庫檔案的備份、還原和復原。
+ [Data Pump Export](https://docs.oracle.com/cd/E11882_01/server.112/e22490/dp_export.htm#SUTIL823) 可協助您將資料和中繼資料上傳到一組稱為傾印檔案集的作業系統檔案中。傾印檔案集只能由 [Data Pump Import](https://docs.oracle.com/cd/E11882_01/server.112/e22490/dp_import.htm#SUTIL300) 公用程式或 [DBMS\$1DATAPUMP](https://docs.oracle.com/database/121/ARPLS/d_datpmp.htm#ARPLS356) 套件匯入。

## 史詩
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms-epics"></a>

### 在 Amazon EC2 上設定 SharePlex 和 Oracle 預備資料庫
<a name="set-up-shareplex-and-the-oracle-staging-database-on-amazon-ec2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 EC2 執行個體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms.html) | Oracle 管理 | 
| 準備預備資料庫。 | 透過從 Oracle 8i 或 9i 資料庫來源環境取得 RMAN 備份，在 Oracle 12CR2 上準備還原為升級的 Oracle 預備資料庫。如需詳細資訊，請參閱 [Oracle 文件中的 Oracle 9i Recovery Manager 使用者指南](https://docs.oracle.com/cd/B10500_01/server.920/a96566/toc.htm)和[資料庫備份與復原使用者指南](https://docs.oracle.com/database/121/BRADV/rcmcomre.htm#BRADV8005)。 | Oracle 管理 | 
| 設定 SharePlex。 | 將 SharePlex 來源設定為內部部署 Oracle 8i 或 9i 資料庫，並將目標設定為 Amazon EC2 上託管的 Oracle 12CR2 預備資料庫。 Amazon EC2 | SharePlex、Oracle 管理 | 

### 將 Amazon RDS for Oracle 設定為您的目標環境
<a name="set-up-amazon-rds-for-oracle-as-your-target-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Oracle 資料庫執行個體。 | 建立 Amazon RDS for Oracle 資料庫，然後將 Oracle 12CR2 連線至資料庫。如需詳細資訊，請參閱[《Amazon RDS 文件》中的建立 Oracle 資料庫執行個體並連線至 Oracle 資料庫執行個體上的](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.Oracle.html)資料庫。 | DBA | 
| 從預備資料庫還原 Amazon RDS for Oracle。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms.html)如需詳細資訊，請參閱 Oracle 文件中的 [54 DBMS\$1DATAPUMP](https://docs.oracle.com/en/database/oracle/oracle-database/21/arpls/DBMS_DATAPUMP.html#GUID-AEA7ED80-DB4A-4A70-B199-592287206348)。 | DBA | 

### 設定 AWS DMS
<a name="set-up-aws-dms"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立資料庫的端點。 | 為 Oracle 預備資料庫建立來源端點，並為 Amazon RDS for Oracle 資料庫建立目標端點。如需詳細資訊，請參閱 [AWS 知識中心中的如何使用 AWS DMS 建立來源或目標端點？](https://aws.amazon.com/premiumsupport/knowledge-center/create-source-target-endpoints-aws-dms/)。 | DBA | 
| 建立複寫執行個體。 | 使用 AWS DMS 將 Oracle 預備資料庫的複寫執行個體啟動至 Amazon RDS for Oracle 資料庫。如需詳細資訊，請參閱 [AWS 知識中心中的如何建立 AWS DMS 複寫執行個體？](https://aws.amazon.com/premiumsupport/knowledge-center/create-aws-dms-replication-instance/)。 | DBA | 
| 建立並啟動複寫任務。 | 使用 `FLASHBACK_SCN` EXPDP （因為已透過 EXPDP 完全載入） 中的 建立變更資料擷取 (CDC) 的 AWS DMS 複寫任務。如需詳細資訊，請參閱 AWS DMS 文件中的[建立任務](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.Creating.html)。 | DBA | 

### 切換到 Amazon RDS for Oracle
<a name="cut-over-to-amazon-rds-for-oracle"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 停止應用程式工作負載。 | 在計劃的切換時段期間停止應用程式伺服器及其應用程式。 | 應用程式開發人員，DBA | 
| 驗證現場部署 Oracle 預備資料庫與 EC2 執行個體的同步。 | 透過在內部部署來源資料庫上執行幾個日誌切換，確認從 SharePlex 複寫執行個體複寫任務的所有訊息都已張貼到 Amazon EC2 上的 Oracle 預備資料庫。如需詳細資訊，請參閱 Oracle 文件中的 [6.4.2 切換日誌檔案。](https://docs.oracle.com/database/121/ADMQS/GUID-E30B4C65-2AC7-4A44-A58C-D3C121EB152F.htm#ADMQS12075) | DBA | 
| 使用 Amazon RDS for Oracle 資料庫驗證 Oracle 預備資料庫的同步。 | 確認您的所有 AWS DMS 任務沒有延遲和錯誤，然後檢查任務的驗證狀態。 | DBA | 
| 停止 SharePlex 和 Amazon RDS 的複寫。 | 如果 SharePlex 和 AWS DMS 複寫都未顯示任何錯誤，則停止這兩個複寫。 | DBA | 
| 將應用程式重新映射至 Amazon RDS。 | 與應用程式伺服器及其應用程式共用 Amazon RDS for Oracle 端點詳細資訊，然後啟動應用程式以繼續業務操作。 | 應用程式開發人員，DBA | 

### 測試 AWS 目標環境
<a name="test-the-aws-target-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 AWS 上測試 Oracle 預備資料庫環境。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms.html) | SharePlex、Oracle 管理 | 
| 測試 Amazon RDS 環境。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms.html)如需詳細資訊，請參閱 [Amazon RDS 文件中的 Amazon RDS for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html)。 | Oracle 管理 | 

## 相關資源
<a name="migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms-resources"></a>
+ [安心遷移](https://aws.amazon.com/cloud-migration/)
+ [Amazon EC2](https://aws.amazon.com/ec2/)
+ [Amazon RDS for Oracle](https://aws.amazon.com/rds/oracle/)
+ [AWS Database Migration Service](https://aws.amazon.com/dms/)
+ [偵錯 AWS DMS 遷移：發生錯誤時該怎麼做 （第 1 部分）](https://aws.amazon.com/blogs/database/debugging-your-aws-dms-migrations-what-to-do-when-things-go-wrong-part-1/)
+ [偵錯 AWS DMS 遷移：發生錯誤時該怎麼做 （第 2 部分）](https://aws.amazon.com/blogs/database/debugging-your-aws-dms-migrations-what-to-do-when-things-go-wrong-part-2/)
+ [偵錯 AWS DMS 遷移：發生問題時該怎麼辦？ （第 3 部分）](https://aws.amazon.com/blogs/database/debugging-your-aws-dms-migrations-what-to-do-when-things-go-wrong-part-3/)
+ [用於資料庫複寫的 SharePlex ](https://aws.amazon.com/marketplace/pp/B07943W4MJ)
+ [SharePlex：任何環境的資料庫複寫](https://www.youtube.com/watch?v=ygS_ouUaNus)

# 將內部部署 MySQL 資料庫遷移至 Amazon EC2
<a name="migrate-an-on-premises-mysql-database-to-amazon-ec2"></a>

*Lorenzo Mota，Amazon Web Services*

## 摘要
<a name="migrate-an-on-premises-mysql-database-to-amazon-ec2-summary"></a>

此模式提供將內部部署 MySQL 資料庫遷移至 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上 MySQL 資料庫的指引。模式討論使用 AWS Database Migration Service (AWS DMS) 或原生 MySQL 工具進行遷移，例如 **mysqldump**。它著重於完整資料庫遷移至 MySQL 資料庫執行個體。

模式主要用於DBAs解決方案架構師。它可用於小型或大型專案、測試或最終遷移階段。建議您在生產環境中使用此模式之前，至少執行一個測試週期。

## 先決條件和限制
<a name="migrate-an-on-premises-mysql-database-to-amazon-ec2-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 內部部署資料中心中的 MySQL 來源資料庫 

**產品版本**
+ MySQL 5.5 版及更新版本
+ Amazon EC2 支援的目標作業系統；請參閱 [Amazon EC2 FAQs](https://aws.amazon.com/ec2/faqs/)

## Architecture
<a name="migrate-an-on-premises-mysql-database-to-amazon-ec2-architecture"></a>

**來源 技術堆疊 **
+ 內部部署 MySQL 資料庫

**目標 技術堆疊 **
+ Amazon EC2 上的 MySQL 資料庫執行個體

**AWS 資料遷移方法**
+ AWS DMS
+ 原生 MySQL 工具，例如 [mysqldump](https://dev.mysql.com/doc/refman/en/mysqldump.html)，或第三方工具，例如 [Percona XtraBackup](https://www.percona.com/mysql/software/percona-xtrabackup)

**目標架構**

下圖說明切換後的目標 Amazon EC2 實作。

![\[Amazon EC2 上的 MySQL 資料庫執行個體，可複寫至待命 MySQL 資料庫執行個體。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/d22b3e25-4d3b-4bd7-ad07-501748d67752/images/34cab6f9-9107-4c3b-98ec-a6d7fa9f298a.png)


 

**AWS 資料遷移架構**

*使用 AWS DMS：*

下圖說明資料遷移工作流程，以 AWS DMS 為基礎，將完整和增量變更傳送至目標 MySQL 資料庫，直到切換為止。從內部部署到 的網路連線 AWS 取決於 SQL 用戶端的需求，且超出此模式的範圍。

![\[使用 AWS DMS 將資料傳送至 Amazon EC2 上的目標 MySQL 資料庫。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/d22b3e25-4d3b-4bd7-ad07-501748d67752/images/c906c45d-fac5-4bb9-b8c8-55e2f9f05fd8.png)


*使用其他 MySQL 工具：*

下圖說明使用 MySQL 工具從內部部署資料庫產生匯出傾印檔案的資料遷移工作流程。這些檔案會移至 Amazon Simple Storage Service (Amazon S3)，並在切換之前匯入目標 MySQL 資料庫。從內部部署到 的網路連線 AWS 取決於 SQL 用戶端的需求，且超出此模式的範圍。

![\[使用原生 MySQL 工具將資料傳送至 Amazon EC2 上的目標 MySQL 資料庫。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/d22b3e25-4d3b-4bd7-ad07-501748d67752/images/18e88877-7879-4a99-b985-25c56bf7c35f.png)


備註：
+ 根據停機時間考量和最終切換的資料庫大小，您可以使用 AWS DMS 或其他變更資料擷取 (CDC) 工具，將切換時間降至最低。當您使用 等 CDC 工具時 AWS DMS，您可以在幾分鐘內遷移至目標資料庫。 
+ 如果資料庫大小和網路延遲允許短暫的切換遷移時段，則 **mysqldump** 的離線策略就足夠了。（我們建議您執行測試以取得大約的時間。)
+ 通常，與離線選項相比，透過 的 CDC 策略 AWS DMS 需要更多的監控和複雜性。

## 工具
<a name="migrate-an-on-premises-mysql-database-to-amazon-ec2-tools"></a>

**AWS 服務**
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 支援數個來源和目標資料庫。如需 支援的 MySQL 來源和目標資料庫的相關資訊 AWS DMS，請參閱[使用 MySQL 相容資料庫做為 的來源 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.MySQL.html)和[使用 MySQL 相容資料庫做為 的目標 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Target.MySQL.html)。如果您的來源資料庫不受 支援 AWS DMS，您必須選擇其他方法來遷移資料。

**其他工具**
+ [mysqldump](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html) 是一種 MySQL 公用程式，可從 MySQL 資料庫建立傾印檔案，以供備份或遷移之用。
+ [Percona XtraBackup](https://www.percona.com/mysql/software/percona-xtrabackup) 是一種開放原始碼公用程式，可在 MySQL 資料庫上執行非封鎖備份。

## 史詩
<a name="migrate-an-on-premises-mysql-database-to-amazon-ec2-epics"></a>

### 規劃遷移
<a name="plan-the-migration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證資料庫版本。 | 驗證來源和目標資料庫的版本。如需有關 支援的 MySQL 版本的資訊 AWS DMS，請參閱 AWS DMS 文件中的 [的來源 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Introduction.Sources.html)和 [的目標 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Introduction.Targets.html)。 | DBA | 
| 識別目標作業系統。 | 判斷目標作業系統的版本。如需 Amazon EC2 支援的目標作業系統清單，請參閱 [Amazon EC2 FAQs](https://aws.amazon.com/ec2/faqs/)。 | DBA，系統管理員 | 
| 識別硬體需求。 | 根據 MySQL 相容性清單和容量需求，判斷[目標伺服器執行個體](https://aws.amazon.com/rds/instance-types/)的硬體需求。 | DBA，系統管理員 | 
| 識別儲存需求。 | 判斷目標資料庫的儲存類型和容量。 | DBA，系統管理員 | 
| 識別網路需求。 | 判斷網路需求，例如延遲和頻寬。 | DBA，系統管理員 | 
| 選擇目標執行個體類型。 | 根據容量、儲存功能和網路功能選擇[目標執行個體類型](https://aws.amazon.com/rds/instance-types/)。 | DBA，系統管理員 | 
| 識別安全需求。 | 判斷來源和目標資料庫的網路或主機存取安全需求。 | DBA，系統管理員 | 
| 識別使用者。 | 決定 MySQL 軟體安裝的作業系統使用者清單。如需詳細資訊，請參閱 [MySQL 文件](https://dev.mysql.com/doc/mysql-security-excerpt/en/access-control.html)。 | DBA，系統管理員 | 
| 決定備份策略。 |  | DBA | 
| 判斷可用性需求。 |  | DBA | 
| 識別應用程式遷移或切換策略。 |  | DBA，系統管理員 | 

### 設定基礎設施
<a name="configure-the-infrastructure"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立虛擬私有雲端 (VPC) 和子網路。 | 設定路由表、網際網路閘道、NAT 閘道和子網路。如需詳細資訊，請參閱 Amazon [VPC 文件中的 VPC 組態選項](https://docs.aws.amazon.com/vpc/latest/userguide/create-vpc-options.html)。 | 系統管理員 | 
| 建立安全群組和網路存取控制清單 ACLs)。 | 根據您的需求設定連接埠 (MySQL 的預設值為 3306) 和 CIDR 範圍或特定 IPs。 | 系統管理員 | 
| 設定和啟動 EC2 執行個體。 | 如需說明，請參閱 Amazon [ EC2 文件中的啟動 EC2 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/LaunchingAndUsingInstances.html)。 Amazon EC2  | 系統管理員 | 

### 安裝 MySQL 軟體
<a name="install-mysql-software"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立使用者和群組。 | 建立需要存取伺服器和資料庫的作業系統使用者和群組。如需詳細資訊，請參閱 MySQL 文件中的[存取控制和帳戶管理](https://dev.mysql.com/doc/refman/en/access-control.html)。 | DBA，系統管理員 | 
| 下載 MySQL。 | 下載 MySQL 軟體。如需指示和二進位檔，請參閱 [ MySQL 文件中的安裝](https://dev.mysql.com/doc/refman/en/installing.html) MySQL。 | DBA，系統管理員 | 
| 在 EC2 執行個體上安裝 MySQL 並設定伺服器。 | 連接至 EC2 執行個體並安裝 MySQL 軟體。如需詳細資訊，請參閱 Amazon [ EC2 文件中的連線至 EC2 執行個體](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect.html)。 Amazon EC2  | DBA，系統管理員 | 

### 遷移資料 – 選項 1
<a name="migrate-data-option-1"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用原生 MySQL 或第三方工具遷移資料。 | 此選項使用原生 MySQL 工具或第三方工具來遷移資料庫物件和資料。如需說明，請參閱 [mysqldump](https://dev.mysql.com/doc/refman/en/mysqldump.html) 或 [Percona XtraBackup](https://docs.percona.com/percona-xtrabackup/2.4/index.html) 的文件 （適用於實體遷移）。如需使用這些工具的詳細資訊，請參閱 [ MySQL 到 Amazon RDS for MySQL 或 Amazon Aurora MySQL 的遷移選項](https://aws.amazon.com/blogs/database/migration-options-for-mysql-to-amazon-rds-for-mysql-or-amazon-aurora-mysql/) AWS 部落格文章。 | DBA | 

### 遷移資料 – 選項 2
<a name="migrate-data-option-2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 遷移資料 AWS DMS。 | 如需詳細資訊，請參閱 AWS DMS 文件中的 [的高階檢視 AWS DMS](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Introduction.HighLevelView.html)。 | DBA | 

### 準備切換
<a name="prepare-for-cutover"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 收集物件計數。 | 從來源資料庫和新目標資料庫收集物件計數。修正目標資料庫中的任何差異。 | DBA | 
| 檢查相依性。 | 確認往返其他資料庫的相依性 （連結） 仍然有效且正常運作。 | DBA | 
| 測試。 | 如果這是一個測試週期，請執行查詢測試、收集指標並修正任何問題。 | DBA | 

### 剪下
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 移動用戶端。 | 將應用程式用戶端切換到新的基礎設施。 | DBA、應用程式擁有者、系統管理員 | 
| 提供支援。 | 在功能應用程式測試期間提供支援。 | DBA | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉資源。 | 關閉 AWS DMS 複寫執行個體和其他暫時 AWS 資源。 | DBA，系統管理員 | 
| 檢閱和專案文件。 | 檢閱並驗證專案文件。 | DBA、應用程式擁有者、系統管理員 | 
| 收集指標。 | 收集遷移時間、與工具輔助變更相比的手動變更百分比，以及節省成本等指標。 | DBA、應用程式擁有者、系統管理員 | 
| 關閉專案。 | 關閉遷移專案並提供意見回饋。 | DBA、應用程式擁有者、系統管理員 | 
| 停用來源資料庫。 | 停用內部部署 MySQL 資料庫。 | DBA，系統管理員 | 

## 相關資源
<a name="migrate-an-on-premises-mysql-database-to-amazon-ec2-resources"></a>

**參考**
+ [Amazon EC2 文件](https://docs.aws.amazon.com/ec2/)
+ [AWS DMS 文件](https://docs.aws.amazon.com/dms/)
+ [Amazon EC2 定價](https://aws.amazon.com/ec2/pricing/)
+ [AWS DMS Step-by-Step演練](https://docs.aws.amazon.com/dms/latest/sbs/DMS-SBS-Welcome.html)
+ [mysqldump](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html)
+ [Percona XtraBackup](https://www.percona.com/mysql/software/percona-xtrabackup)

**教學課程和影片**
+ [入門 AWS DMS](https://aws.amazon.com/dms/getting-started/)
+ [Amazon EC2 簡介 – Elastic Cloud Server & Hosting with AWS](https://www.youtube.com/watch?v=TsRBftzZsQo) （影片）

# 在沒有加密的情況下監控 Amazon Aurora 是否有執行個體
<a name="monitor-amazon-aurora-for-instances-without-encryption"></a>

*Mansi Suratwala，Amazon Web Services*

## 總結
<a name="monitor-amazon-aurora-for-instances-without-encryption-summary"></a>

此模式提供 Amazon Web Services (AWS) CloudFormation 範本，您可以部署該範本，以在未開啟加密的情況下建立 Amazon Aurora 執行個體時設定自動通知。

Aurora 為全受管關聯式資料庫引擎，可與 MySQL 和 PostgreSQL 相容。透過一些工作負載，Aurora 可提供 MySQL 最多五倍的輸送量和 PostgreSQL 最多三倍的輸送量，而不需變更您的多數現有應用程式。

CloudFormation 範本會建立 Amazon CloudWatch Events 事件和 AWS Lambda 函數。事件使用 AWS CloudTrail 來監控任何 Aurora 執行個體的建立或現有執行個體的時間點還原。Cloudwatch Events 事件會啟動 Lambda 函數，以檢查是否啟用加密。如果未開啟加密，Lambda 函數會傳送 Amazon Simple Notification Service (Amazon SNS) 通知，通知您違規。 

## 先決條件和限制
<a name="monitor-amazon-aurora-for-instances-without-encryption-prereqs"></a>

**先決條件******
+ 作用中的 AWS 帳戶

**限制**
+ 此服務控制僅適用於 Amazon Aurora 執行個體。它不支援其他 Amazon Relational Database Service (Amazon RDS) 執行個體。
+ CloudFormation 範本必須僅針對 `CreateDBInstance`****和 `RestoreDBClusterToPointInTim`**e** 部署。 

**產品版本**
+ Amazon Aurora 支援的 PostgreSQL 版本
+ Amazon Aurora 支援的 MySQL 版本

## Architecture
<a name="monitor-amazon-aurora-for-instances-without-encryption-architecture"></a>

**目標技術堆疊**
+ Amazon Aurora
+ AWS CloudTrail
+ Amazon CloudWatch
+ AWS Lambda
+ Amazon Simple Storage Service (Amazon S3)
+ Amazon SNS

**目標架構**

![\[Aurora 在沒有加密的情況下啟動 CloudTrail、CloudWatch Events、Lambda 和 SNS 訊息。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/de1528b8-a5a4-4c66-8ab3-7d9863572cbc/images/7dcab41a-d805-4bb0-99d1-1dcef37c4e55.png)


**自動化和擴展**

您可以針對不同的區域和帳戶多次使用 CloudFormation 範本。您只需要在每個區域或帳戶中執行一次。

## 工具
<a name="monitor-amazon-aurora-for-instances-without-encryption-tools"></a>

**工具**
+ [Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html) – Amazon Aurora 是全受管關聯式資料庫引擎，與 MySQL 和 PostgreSQL 相容。
+ [AWS CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html) – AWS CloudTrail 可協助您管理 AWS 帳戶的控管、合規以及操作和風險稽核。使用者、角色或 AWS 服務採取的動作會在 CloudTrail 中記錄為事件。 
+ [Amazon CloudWatch Events](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html) – Amazon CloudWatch Events 提供near-real-time的系統事件串流，說明 AWS 資源的變更。 
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) – AWS Lambda 是一種運算服務，支援執行程式碼，無需佈建或管理伺服器。Lambda 只有在需要時才會執行程式碼，可自動從每天數項請求擴展成每秒數千項請求。 
+ [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/gsg/GetStartedWithS3.html) – Amazon Simple Storage Service (Amazon S3) 是一種高度可擴展的物件儲存服務，可用於各種儲存解決方案，包括網站、行動應用程式、備份和資料湖。
+ [Amazon SNS](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) – Amazon Simple Notification Service (Amazon SNS) 是一種受管服務，使用 Lambda、HTTP、電子郵件、行動推播通知和行動文字訊息 (SMS) 提供訊息傳遞。 

**Code**

專案的 .zip 檔案可做為附件使用。

## 史詩
<a name="monitor-amazon-aurora-for-instances-without-encryption-epics"></a>

### 建立 Lambda 指令碼的 S3 儲存貯體
<a name="create-the-s3-bucket-for-the-lambda-script"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 定義 S3 儲存貯體。 | 開啟 Amazon S3 主控台，然後選擇或建立 S3 儲存貯體。此 S3 儲存貯體將託管 Lambda 程式碼 .zip 檔案。您的 S3 儲存貯體必須與 Aurora 位於相同的區域。S3 儲存貯體名稱不能包含正斜線。 | 雲端架構師 | 

### 將 Lambda 程式碼上傳至 S3 儲存貯體
<a name="upload-the-lambda-code-to-the-s3-bucket"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 上傳 Lambda 程式碼。 | 將*附件*區段中提供的 Lambda 程式碼 .zip 檔案上傳至您定義的 S3 儲存貯體。 | 雲端架構師 | 

### 部署 CloudFormation 範本
<a name="deploy-the-cloudformation-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 部署 CloudFormation 範本。 | 在 CloudFormation 主控台上，部署做為此模式附件提供的 `RDS_Aurora_Encryption_At_Rest.yml` CloudFormation 範本。在下一個 Epic 中，提供範本參數的值。 | 雲端架構師 | 

### 完成 CloudFormation 範本中的參數
<a name="complete-the-parameters-in-the-cloudformation-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 提供 S3 儲存貯體名稱。 | 輸入您在第一個特徵中建立或選擇的 S3 儲存貯體名稱。 | 雲端架構師  | 
| 提供 S3 金鑰。 | 提供 Lambda 程式碼 .zip 檔案在 S3 儲存貯體中的位置，不帶正斜線 （例如 `<directory>/<file-name>.zip`)。 | 雲端架構師  | 
| 提供電子郵件地址。 | 提供作用中的電子郵件地址以接收 Amazon SNS 通知。 | 雲端架構師  | 
| 定義記錄層級。 | 定義 Lambda 函數的記錄層級和頻率。 會`Info`指定應用程式進度的詳細資訊訊息。 會`Error`指定仍可允許應用程式繼續執行的錯誤事件。 會`Warning`指定可能有害的情況。 | 雲端架構師 | 

### 確認訂閱
<a name="confirm-the-subscription"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 確認訂閱。 | 當範本成功部署時，它會傳送訂閱電子郵件訊息到提供的電子郵件地址。若要接收通知，您必須確認此電子郵件訂閱。  | 雲端架構師 | 

## 相關資源
<a name="monitor-amazon-aurora-for-instances-without-encryption-resources"></a>
+ [建立 S3 儲存貯體](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/create-bucket.html)
+ [將檔案上傳至 S3 儲存貯體](https://docs.aws.amazon.com/AmazonS3/latest/user-guide/upload-objects.html) 
+ [建立 Amazon Aurora 資料庫叢集](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.CreateInstance.html)
+ [建立使用 AWS CloudTrail 在 AWS API 呼叫上觸發的 CloudWatch Events 規則 CloudTrail](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/Create-CloudWatch-Events-CloudTrail-Rule.html)

## 附件
<a name="attachments-de1528b8-a5a4-4c66-8ab3-7d9863572cbc"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/de1528b8-a5a4-4c66-8ab3-7d9863572cbc/attachments/attachment.zip)

# 使用 Amazon CloudWatch 監控 Oracle GoldenGate 日誌
<a name="monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch"></a>

*Chithra Krishnamurthy，Amazon Web Services*

## 摘要
<a name="monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch-summary"></a>

Oracle GoldenGate 可在 Amazon Relational Database Service (Amazon RDS) for Oracle 資料庫之間或在 Amazon Elastic Compute Cloud (Amazon EC2) 上託管的 Oracle 資料庫之間提供即時複寫。它支援單向和雙向複寫。

當您使用 GoldenGate 進行複寫時，監控對於驗證 GoldenGate 程序是否啟動並執行至關重要，以確保來源和目標資料庫處於同步狀態。

此模式說明針對 GoldenGate 錯誤日誌實作 Amazon CloudWatch 監控的步驟，以及如何設定警示來傳送特定事件的通知，例如 `STOP`或 ，`ABEND`以便您可以採取適當動作快速恢復複寫。

## 先決條件和限制
<a name="monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch-prereqs"></a>

**先決條件 **
+ 在 EC2 執行個體上安裝和設定 GoldenGate，因此您可以在這些 EC2 執行個體上設定 CloudWatch 監控。如果您想要監控跨 AWS 區域的 GoldenGate 以進行雙向複寫，您必須在執行 GoldenGate 程序的每個 EC2 執行個體中安裝 CloudWatch 代理程式。

**限制 **
+ 此模式說明如何使用 CloudWatch 監控 GoldenGate 程序。CloudWatch 不會在複寫期間監控複寫延遲或資料同步問題。您必須執行個別的 SQL 查詢來監控複寫延遲或資料相關錯誤，如 [GoldenGate 文件](https://docs.oracle.com/en/middleware/goldengate/core/19.1/index.html)所述。

**產品版本**
+ 本文件是以 Oracle GoldenGate 19.1.0.0.4 for Oracle on Linux x86-64 的實作為基礎。不過，此解決方案適用於所有主要版本的 GoldenGate。

## Architecture
<a name="monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch-architecture"></a>

**目標技術堆疊**
+ EC2 執行個體上安裝的 Oracle GoldenGate 二進位檔
+ Amazon CloudWatch
+ Amazon Simple Notification Service (Amazon SNS)

**目標架構**

![\[用於監控 AWS 上 GoldenGate 日誌的目標架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/973a71d5-b6b3-4a2b-813e-cb4d8fd51ba5/images/1781aa9b-77b3-40c4-bc54-3cb91400899c.png)


## 工具
<a name="monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch-tools"></a>

**AWS 服務**
+ [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) 是一項監控服務，用於此模式來監控 GoldenGate 錯誤日誌。
+ [Amazon SNS](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html) 是一項訊息通知服務，用於此模式來傳送電子郵件通知。

**其他工具**
+ [Oracle GoldenGate ](https://docs.oracle.com/en/middleware/goldengate/core/19.1/index.html) 是一種資料複寫工具，可用於 Amazon RDS for Oracle 資料庫或託管於 Amazon EC2 的 Oracle 資料庫。

**高階實作步驟**

1. 為 CloudWatch 代理程式建立 AWS Identity and Access Management (IAM) 角色。

1. 將 IAM 角色連接至產生 GoldenGate 錯誤日誌的 EC2 執行個體。

1. 在 EC2 執行個體上安裝 CloudWatch 代理程式。

1. 設定 CloudWatch 代理程式組態檔案： `awscli.conf`和 `awslogs.conf`。

1. 啟動 CloudWatch 代理程式。

1. 在日誌群組中建立指標篩選條件。

1. 設定 Amazon SNS。

1. 建立指標篩選條件的警示。當這些篩選條件擷取事件時，Amazon SNS 會傳送電子郵件提醒。

如需詳細說明，請參閱下一節。

## 史詩
<a name="monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch-epics"></a>

### 步驟 1. 為 CloudWatch 代理程式建立 IAM 角色
<a name="step-1-create-an-iam-role-for-the-cloudwatch-agent"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 IAM 角色。 | 存取 AWS 資源需要許可，因此您可以建立 IAM 角色，以包含每個伺服器執行 CloudWatch 代理程式所需的許可。若要建立 IAM 角色：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch.html) | AWS 一般 | 

### 步驟 2. 將 IAM 角色連接至 GoldenGate EC2 執行個體
<a name="step-2-attach-the-iam-role-to-the-goldengate-ec2-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 將 IAM 角色連接至產生 GoldenGate 錯誤日誌的 EC2 執行個體。 | GoldenGate 產生的錯誤日誌必須填入 CloudWatch 並進行監控，因此您需要將您在步驟 1 中建立的 IAM 角色連接到 GoldenGate 執行所在的 EC2 執行個體。若要將 IAM 角色連接至執行個體：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch.html) | AWS 一般 | 

### 步驟 3-5。在 Goldengate EC2 執行個體上安裝和設定 CloudWatch 代理程式
<a name="steps-3-5-install-and-configure-the-cloudwatch-agent-on-the-goldengate-ec2-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 GoldenGate EC2 執行個體上安裝 CloudWatch 代理程式。 | 若要安裝代理程式，請執行 命令：<pre>sudo yum install -y awslogs</pre> | AWS 一般 | 
| 編輯代理程式組態檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch.html) | AWS 一般 | 
| 啟動 CloudWatch 代理程式。 | 若要啟動代理程式，請使用下列命令。<pre>$ sudo service awslogsd start</pre>啟動代理程式後，您可以在 CloudWatch 主控台中檢視日誌群組。日誌串流將具有 檔案的內容。 | AWS 一般 | 

### 步驟 6. 建立日誌群組的指標篩選條件
<a name="step-6-create-metric-filters-for-the-log-group"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立關鍵字 ABEND 和 STOPPED 的指標篩選條件。 | 當您為日誌群組建立指標篩選條件時，只要在錯誤日誌中識別篩選條件，就會啟動警示，並根據 Amazon SNS 組態傳送電子郵件通知。若要建立指標篩選條件：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch.html) | CloudWatch | 

### 步驟 7. 設定 Amazon SNS
<a name="step-7-set-up-amazon-sns"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 SNS 主題。 | 在此步驟中，您會設定 Amazon SNS 為指標篩選條件建立警示。若要建立 SNS 主題：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch.html) | Amazon SNS | 
| 建立訂閱。 | 若要建立 主題的訂閱：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch.html)Amazon SNS 會開啟您的 web 瀏覽器，並顯示含有您的訂閱 ID 的訂閱確認。 | Amazon SNS | 

### 步驟 8. 建立警示以傳送指標篩選條件的通知
<a name="step-8-create-an-alarm-to-send-notifications-for-the-metric-filters"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 SNS 主題的警示。 | 若要根據日誌群組指標篩選條件建立警示：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch.html)完成這些步驟後，只要在您監控的 GoldenGate 錯誤日誌檔 (`ggserr.log`) 中偵測到這些模式，您就會收到電子郵件通知。 | CloudWatch | 

## 疑難排解
<a name="monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| GoldenGate 錯誤日誌中的日誌串流不會流入 CloudWatch。 | 檢查 `/etc/awslogs/awslogs.conf` 檔案以驗證檔案名稱、日誌群組名稱和日期/時間格式。您必須指定日期/時間，以符合 中的日期格式`ggserror.log`。否則，日誌串流不會流入 CloudWatch。 | 

## 相關資源
<a name="monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch-resources"></a>
+ [Amazon CloudWatch 文件](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)
+ [使用 CloudWatch 代理程式收集指標和日誌](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html)
+ [Amazon SNS 文件](https://docs.aws.amazon.com/sns/latest/dg/welcome.html)

# 在 Amazon RDS for Oracle 上將 Oracle Database Enterprise Edition 轉換為 Standard Edition 2
<a name="replatform-oracle-database-enterprise-edition-to-standard-edition-2-on-amazon-rds-for-oracle"></a>

*Lanre (Lan-Ray) showunmi 和 Tarun Chawla，Amazon Web Services*

## 總結
<a name="replatform-oracle-database-enterprise-edition-to-standard-edition-2-on-amazon-rds-for-oracle-summary"></a>

Oracle Database Enterprise Edition (EE) 是許多企業中執行應用程式的熱門選擇。不過，在某些情況下，應用程式使用很少或沒有 Oracle 資料庫 EE 功能，因此缺乏產生大量授權成本的正當理由。當您遷移至 Amazon RDS 時，您可以將此類資料庫降級為 Oracle Database Standard Edition 2 (SE2)，以節省成本。

此模式說明如何在從現場部署遷移至 [Amazon RDS for Oracle 時，從 Oracle 資料庫 EE 降級至 Oracle](https://aws.amazon.com/rds/oracle/) 資料庫 SE2。如果您的 EE Oracle 資料庫已在 Amazon RDS 或 [Amazon Elastic Compute Cloud](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) (Amazon EC2) 執行個體上執行，則此模式中顯示的步驟也適用。

如需詳細資訊，請參閱 AWS 規範指引指南，了解如何[評估 Oracle 資料庫降級至 AWS 上的 Standard Edition 2](https://docs.aws.amazon.com/prescriptive-guidance/latest/evaluate-downgrading-oracle-edition/welcome.html)。

## 先決條件和限制
<a name="replatform-oracle-database-enterprise-edition-to-standard-edition-2-on-amazon-rds-for-oracle-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ Oracle 資料庫企業版
+ 用戶端工具，例如 [Oracle SQL Developer](https://www.oracle.com/database/sqldeveloper/) 或 SQL\$1Plus，用於在 Oracle 資料庫上連接和執行 SQL 命令
+ 執行評估的資料庫使用者；例如，下列其中一項：
  + 具有足夠[權限](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.html#CHAP_Source.Oracle.Permissions)執行 [AWS Schema Conversion Tool (AWS SCT)](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) 評估的使用者
  + 具有足夠權限可在 Oracle 資料庫字典資料表上執行 SQL 查詢的使用者
+ 執行資料庫遷移的資料庫使用者；例如，下列其中一項：
  + 具有足夠[權限](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html#CHAP_Source.Oracle.Self-Managed)執行 [AWS Database Migration Service (AWS DMS) ](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)的使用者
  + 具有足夠[權限可執行 Oracle Data Pump 匯出和匯入](https://docs.oracle.com/database/121/SUTIL/GUID-8B6975D3-3BEC-4584-B416-280125EEC57E.htm#SUTIL807)的使用者
  + 具有足夠[權限可執行 Oracle GoldenGate](https://docs.oracle.com/goldengate/1212/gg-winux/GIORA/user_assignment.htm#GIORA546) 的使用者

**限制**
+ Amazon RDS for Oracle 具有資料庫大小上限。如需詳細資訊，請參閱 [Amazon RDS 資料庫執行個體儲存體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html)。

**產品版本**

本文件所述的一般邏輯適用於 9i 及更新版本的 Oracle。如需自我管理和 Amazon RDS for Oracle 資料庫的支援版本，請參閱 [AWS DMS 文件](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.Oracle.html)。

若要在不支援 AWS SCT 的情況下識別功能用量，請在來源資料庫上執行 SQL 查詢。若要從不支援 AWS DMS 和 Oracle Data Pump 的舊版 Oracle 遷移，請使用 [Oracle Export and Import 公用程式](https://docs.oracle.com/cd/B19306_01/server.102/b14215/exp_imp.htm)。

如需支援版本的最新清單，請參閱 AWS 文件中的 [Oracle on Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html)。如需定價和支援執行個體類別的詳細資訊，請參 [Amazon RDS for Oracle 定價](https://aws.amazon.com/rds/oracle/pricing/)。

## Architecture
<a name="replatform-oracle-database-enterprise-edition-to-standard-edition-2-on-amazon-rds-for-oracle-architecture"></a>

**來源技術堆疊**
+ 在內部部署或 Amazon EC2 上執行的 Oracle Database Enterprise Edition

**使用原生 Oracle 工具鎖定技術堆疊**
+ 執行 Oracle Database SE2 的 Amazon RDS for Oracle

![\[從內部部署 Oracle 資料庫遷移至 Amazon RDS 的三個步驟程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/a1b28050-9bab-4de6-b2a9-b97b3e5070bd/images/bf765c5b-4b12-4a8c-b27c-c5e0bd605dd1.png)


 

1. 使用 Oracle Data Pump 匯出資料。

1. 透過資料庫連結將傾印檔案複製到 Amazon RDS。

1. 使用 Oracle Data Pump 將傾印檔案匯入 Amazon RDS。

**使用 AWS DMS 鎖定技術堆疊**
+ 執行 Oracle Database SE2 的 Amazon RDS for Oracle
+ AWS DMS

![\[使用 AWS DMS 從內部部署 Oracle 資料庫遷移至 Amazon RDS 的四步驟程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/a1b28050-9bab-4de6-b2a9-b97b3e5070bd/images/fef4eced-1acb-4303-baaa-5c1c29650935.png)


1. 搭配 FLASHBACK\$1SCN 使用 Oracle Data Pump 匯出資料。

1. 透過資料庫連結將傾印檔案複製到 Amazon RDS。

1. 使用 Oracle Data Pump 將傾印檔案匯入 Amazon RDS。

1. 使用 AWS DMS [變更資料擷取 (CDC)](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Task.CDC.html)。

## 工具
<a name="replatform-oracle-database-enterprise-edition-to-standard-edition-2-on-amazon-rds-for-oracle-tools"></a>

**AWS 服務**
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移至 AWS 雲端，或在雲端和內部部署設定的組合之間遷移。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。此模式使用 Amazon RDS for Oracle。
+ [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html)** **提供專案型使用者介面，可自動評估、轉換來源 Oracle 資料庫的資料庫結構描述，並將其複製到與 Amazon RDS for Oracle 相容的格式。AWS SCT 可讓您分析可透過將授權類型從 Enterprise 變更為 Standard Edition of Oracle 來實現的潛在成本節省。AWS SCT 報告**的授權評估和雲端支援**區段提供使用中 Oracle 功能的詳細資訊，讓您可以在遷移至 Amazon RDS for Oracle 時做出明智的決定。

**其他工具**
+ 原生 Oracle 匯入和匯出公用程式支援將 Oracle 資料移入和移出 Oracle 資料庫。Oracle 提供兩種類型的資料庫匯入和匯出公用程式：[原始匯出和匯入](https://docs.oracle.com/cd/B19306_01/server.102/b14215/exp_imp.htm) （適用於舊版） 和 [Oracle Data Pump 匯出和匯入](https://docs.oracle.com/cd/B19306_01/server.102/b14215/part_dp.htm#CEGJCCHC) （適用於 Oracle Database 10g 版本 1 和更新版本）。
+ [Oracle GoldenGate](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.OracleGoldenGate.html) 提供即時複寫功能，讓您可以在初始載入後同步目標資料庫。此選項有助於減少應用程式上線期間的停機時間。

## 史詩
<a name="replatform-oracle-database-enterprise-edition-to-standard-edition-2-on-amazon-rds-for-oracle-epics"></a>

### 進行遷移前評估
<a name="make-a-pre-migration-assessment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證應用程式的資料庫需求。 | 確保您的應用程式已通過認證，可在 Oracle Database SE2 上執行。直接與軟體廠商、開發人員或應用程式文件確認。 | 應用程式開發人員、DBA、應用程式擁有者 | 
| 直接在資料庫中調查 EE 功能的使用。 | 若要判斷 EE 功能使用情況，請執行下列其中一項操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replatform-oracle-database-enterprise-edition-to-standard-edition-2-on-amazon-rds-for-oracle.html) | 應用程式擁有者、DBA、應用程式開發人員 | 
| 識別操作活動使用 EE 功能。 | 資料庫或應用程式管理員有時會依賴僅限 EE 的功能來進行操作活動。常見範例包括線上維護活動 （索引重建、資料表移動），以及依批次任務使用平行處理。可以盡可能修改您的操作來減輕這些相依性。識別這些功能的使用方式，並根據成本與優點做出決策。使用[比較 Oracle 資料庫 EE 和 SE2 功能](https://docs.aws.amazon.com/prescriptive-guidance/latest/evaluate-downgrading-oracle-edition/compare-features.html)資料表做為指南，以識別 Oracle Database SE2 中可用的功能。 | 應用程式開發人員、DBA、應用程式擁有者 | 
| 檢閱 EE Oracle 資料庫的工作負載模式。 | Oracle Database SE2 會隨時自動將用量限制為最多 16 個 CPU 執行緒。如果您的 Oracle EE 資料庫已獲授權使用 Oracle Diagnostic Pack，請使用自動工作負載儲存庫 (AWR) 工具或 DBA\$1HIST\$1\$1 檢視來分析資料庫工作負載模式，以判斷當您降級至 SE2 時，16 個 CPU 執行緒的上限是否會對服務層級造成負面影響。確保您的評估涵蓋尖峰活動期間，例如打烊、月或年處理。 | 應用程式擁有者、DBA、應用程式開發人員 | 

### 在 AWS 上準備目標基礎設施
<a name="prepare-the-target-infrastructure-on-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 部署和設定聯網基礎設施。 | 建立[虛擬私有雲端 (VPC) 和子網路](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Subnets.html)、[安全群組](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html)和[網路存取控制清單](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html)。 | AWS 管理員、雲端架構師、網路管理員、DevOps 工程師 | 
| 佈建 Amazon RDS for Oracle SE2 資料庫。 | 佈建目標 [Amazon RDS for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.Oracle.html) SE2 資料庫，以符合應用程式的效能、可用性和安全性需求。我們建議生產工作負載使用異地同步備份組態。不過，為了改善遷移效能，您可以延遲[啟用異地](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/create-multi-az-db-cluster.html)同步備份，直到資料遷移之後。 | 雲端管理員、雲端架構師、DBA、DevOps 工程師、AWS 管理員 | 
| 自訂 Amazon RDS 環境。 | 設定自訂[參數](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithParamGroups.html)和[選項](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithOptionGroups.html)，並啟用其他[監控](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MonitoringOverview.html)。如需詳細資訊，請參閱[遷移至 Amazon RDS for Oracle 的最佳實務](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/best-practices.html)。 | AWS 管理員、AWS 系統管理員、雲端管理員、DBA、雲端架構師 | 

### 執行遷移試轉和應用程式測試
<a name="perform-the-migration-dry-run-and-application-testing"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 遷移資料 （試執行）。 | 使用最適合您特定環境的方法，將資料從來源 Oracle EE 資料庫遷移至 Amazon RDS for Oracle SE2 資料庫執行個體。根據大小、複雜性和可用停機時間時段等因素，選取遷移策略。使用下列其中一項或組合：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replatform-oracle-database-enterprise-edition-to-standard-edition-2-on-amazon-rds-for-oracle.html) | DBA | 
| 驗證目標資料庫。 | 執行資料庫儲存體和程式碼物件的遷移後驗證。檢閱遷移日誌，並修正任何已識別的問題。如需詳細資訊，請參閱將 [Oracle 資料庫遷移至 AWS 雲端](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/best-practices.html#post-import)指南。 | DBA | 
| 測試應用程式。 | 應用程式和資料庫管理員應視需要執行功能、效能和操作測試。如需詳細資訊，請參閱[遷移至 Amazon RDS for Oracle 的最佳實務](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/best-practices.html#test-migration)。最後，從利益相關者取得測試結果的簽署。 | 應用程式開發人員、應用程式擁有者、DBA、遷移工程師、遷移負責人 | 

### 切換
<a name="cut-over"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從 Oracle 資料庫 EE 重新整理資料。 | 根據應用程式可用性需求選取資料重新整理方法。如需詳細資訊，請參閱將 [Oracle 資料庫遷移至 AWS 的策略中的遷移](https://docs.aws.amazon.com/whitepapers/latest/strategies-migrating-oracle-db-to-aws/data-migration-methods.html)方法。例如，您可以使用 Oracle GoldenGate 或 AWS DMS 等工具搭配持續複寫，達到幾近零的停機時間。如果停機時間時段允許，您可以使用 Oracle Data Pump 或原始匯出匯入公用程式等離線方法執行最終資料切換。 | 應用程式擁有者、Cutover Lead、DBA、遷移工程師、遷移負責人 | 
| 將應用程式指向目標資料庫執行個體。 | 更新應用程式和其他用戶端中的連線參數，以指向 Amazon RDS for Oracle SE2 資料庫。 | 應用程式開發人員、應用程式擁有者、遷移工程師、遷移負責人、切換負責人 | 
| 執行遷移後活動。 | 執行資料遷移後任務，例如啟用異地同步備份、資料驗證和其他檢查。 | DBA，遷移工程師 | 
| 執行切換後監控。 | 使用 [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/monitoring-cloudwatch.html) 和 Amazon [RDS Performance Insights](https://aws.amazon.com/rds/performance-insights/) 等工具來監控 Amazon RDS for Oracle SE2 資料庫。 | 應用程式開發人員、應用程式擁有者、AWS 管理員、DBA、遷移工程師 | 

## 相關資源
<a name="replatform-oracle-database-enterprise-edition-to-standard-edition-2-on-amazon-rds-for-oracle-resources"></a>

**AWS 方案指引**
+ [將 Oracle 資料庫遷移至 AWS 雲端 ](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/welcome.html)（指南）
+ [評估在 AWS 上將 Oracle 資料庫降級至 Standard Edition 2](https://docs.aws.amazon.com/prescriptive-guidance/latest/evaluate-downgrading-oracle-edition/welcome.html) （指南）
+ [將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.html?did=pg_card&trk=pg_card) （模式）
+ [使用 Oracle Data Pump 將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump.html?did=pg_card&trk=pg_card) (模式)

**部落格文章**
+ [使用 AWS DMS 以接近零的停機時間遷移 Oracle 資料庫](https://aws.amazon.com/blogs/database/migrating-oracle-databases-with-near-zero-downtime-using-aws-dms/)
+ [使用 Amazon RDS for Oracle 在 Oracle SE 中分析效能管理](https://aws.amazon.com/blogs/database/analyzing-performance-management-in-oracle-se-using-amazon-rds-for-oracle/)
+ [使用 Amazon RDS for Oracle 在 Oracle SE 中管理您的 SQL 計劃](https://aws.amazon.com/blogs/database/managing-your-sql-plan-in-oracle-se-with-amazon-rds-for-oracle/)
+ [在 Oracle Standard Edition 中實作資料表分割：第 1 部分](https://aws.amazon.com/blogs/database/implementing-table-partitioning-in-oracle-standard-edition-part-1/)

# 使用 Precisely Connect 將大型主機資料庫複寫至 AWS
<a name="replicate-mainframe-databases-to-aws-by-using-precisely-connect"></a>

*Lucio Pereira、Sayantan Giri 和 Balaji Mohan，Amazon Web Services*

## 總結
<a name="replicate-mainframe-databases-to-aws-by-using-precisely-connect-summary"></a>

此模式概述使用 Precisely Connect，以近乎即時的方式將資料從大型主機資料庫複寫至 Amazon 資料存放區的步驟。它使用 Amazon Managed Streaming for Apache Kafka (Amazon MSK) 和雲端中的自訂資料庫連接器實作事件型架構，以改善可擴展性、彈性和效能。

Precisely Connect 是一種複寫工具，可從舊版大型主機系統擷取資料並將其整合到雲端環境中。使用具有低延遲和高輸送量異質資料管道的近乎即時訊息流程，透過變更資料擷取 (CDC)，將資料從大型主機複寫到 AWS。 

此模式也涵蓋具有多區域資料複寫和容錯移轉路由的彈性資料管道的災難復原策略。

## 先決條件和限制
<a name="replicate-mainframe-databases-to-aws-by-using-precisely-connect-prereqs"></a>

**先決條件**
+ 您要複寫至 AWS 雲端的現有大型主機資料庫，例如 IBM DB2、IBM 資訊管理系統 (IMS) 或虛擬儲存存取方法 (VSAM)
+ 作用中的 [AWS 帳戶](https://aws.amazon.com/account/)
+ 從公司環境到 AWS 的 AWS [Direct Connect](https://aws.amazon.com/directconnect/) 或 [AWS Virtual Private Network (AWS VPN](https://aws.amazon.com/vpn/))
+ 具有可由舊版平台連線之子網路的[虛擬私有雲端](https://aws.amazon.com/vpc/) 

## Architecture
<a name="replicate-mainframe-databases-to-aws-by-using-precisely-connect-architecture"></a>

**來源技術堆疊**

大型主機環境，至少包含下列其中一個資料庫：
+ IBM IMS 資料庫
+ IBM DB2 資料庫
+ VSAM 檔案

**目標技術堆疊**
+ Amazon MSK
+ Amazon Elastic Kubernetes Service (Amazon EKS) 和 Amazon EKS Anywhere
+ Docker
+ AWS 關聯式或 NoSQL 資料庫，如下所示：
  + Amazon DynamoDB
  + Oracle、Amazon RDS for PostgreSQL 或 Amazon Aurora 的 Amazon Relational Database Service (Amazon RDS)
  + Amazon ElastiCache for Redis
  + Amazon Keyspaces (適用於 Apache Cassandra)

**目標架構**

*將大型主機資料複寫至 AWS 資料庫*

下圖說明將大型主機資料複寫至 DynamoDB、Amazon RDS、Amazon ElastiCache 或 Amazon Keyspaces 等 AWS 資料庫。在內部部署大型主機環境中使用 Precisely Capture 和 Publisher、在內部部署分散式環境中使用 Precisely Dispatcher on Amazon EKS Anywhere，以及在 AWS 雲端中精確套用引擎和資料庫連接器，即可近乎即時地進行複寫。 

![\[將大型主機資料複寫至 AWS 資料庫\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/17ac53b7-86d5-4a8c-a55f-56b6338a1af3/images/777dd7da-48ed-4510-b8fa-9041be042671.png)


該圖顯示以下工作流程：

1. 精確擷取會從 CDC 日誌取得大型主機資料，並在內部暫時性儲存體中維護資料。

1. Precisely Publisher 會監聽內部資料儲存體中的變更，並透過 TCP/IP 連線將 CDC 記錄傳送至 Precisely Dispatcher。

1. Precisely Dispatcher 會從發佈者接收 CDC 記錄，並將其傳送至 Amazon MSK。Dispatcher 會根據使用者組態和多個工作者任務建立 Kafka 金鑰，以平行推送資料。當記錄存放在 Amazon MSK 中時，發送者會將確認回發佈者。

1. Amazon MSK 會將 CDC 記錄保留在雲端環境中。主題的分割區大小取決於您的交易處理系統 (TPS) 對輸送量的需求。Kafka 金鑰是進一步轉換和交易排序的必要項目。

1. 精確套用引擎會接聽來自 Amazon MSK 的 CDC 記錄，並根據目標資料庫需求轉換資料 （例如，透過篩選或映射）。您可以將自訂邏輯新增至 Precisely SQD 指令碼。(SQD 是 Precisely 的專屬語言。) 精確套用引擎會將每個 CDC 記錄轉換為 Apache Avro 或 JSON 格式，並根據您的需求將其分發至不同的主題。

1. 目標 Kafka 主題會根據目標資料庫在多個主題中保留 CDC 記錄，而 Kafka 會根據定義的 Kafka 金鑰促進交易排序。分割區索引鍵與對應的分割區對齊，以支援循序程序。 

1. 資料庫連接器 （自訂 Java 應用程式） 從 Amazon MSK 接聽 CDC 記錄，並將其存放在目標資料庫中。

1. 您可以根據您的需求選取目標資料庫。此模式同時支援 NoSQL 和關聯式資料庫。

*災難復原*

業務持續性是組織成功的關鍵。AWS 雲端提供高可用性 (HA) 和災難復原 (DR) 的功能，並支援組織的容錯移轉和備用計畫。此模式遵循主動/被動 DR 策略，並提供實作符合您 RTO 和 RPO 需求的 DR 策略的高階指引。

下圖說明 DR 工作流程。

![\[在 AWS 上複寫大型主機資料的災難復原工作流程\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/17ac53b7-86d5-4a8c-a55f-56b6338a1af3/images/9cccba7a-7a25-411e-829f-7cd5a7a20ab4.png)


上圖顯示以下項目：

1. 如果 AWS 區域 1 發生任何故障，則需要半自動容錯移轉。如果區域 1 發生故障，系統必須啟動路由變更，才能將 Precisely Dispatcher 連線至區域 2。 

1. Amazon MSK 透過區域之間的鏡像複寫資料。因此，在容錯移轉期間，區域 2 中的 Amazon MSK 叢集必須提升為主要領導者。 

1. 精確套用引擎和資料庫連接器是可在任何區域中運作的無狀態應用程式。 

1. 資料庫同步處理取決於目標資料庫。例如，DynamoDB 可以使用全域資料表，而 ElastiCache 可以使用全域資料存放區。

*透過資料庫連接器進行低延遲和高輸送量處理*

資料庫連接器是此模式中的關鍵元件。連接器遵循以接聽程式為基礎的方法來從 Amazon MSK 收集資料，並透過關鍵任務應用程式 （第 0 層和第 1 層） 的高輸送量和低延遲處理將交易傳送至資料庫。下圖說明此程序。

![\[使用資料庫連接器複寫 AWS 上的大型主機資料\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/17ac53b7-86d5-4a8c-a55f-56b6338a1af3/images/79479634-becb-4212-bbfc-1a3b17ae1bed.png)


此模式支援透過多執行緒處理引擎開發具有單一執行緒耗用量的自訂應用程式。

1. 連接器主執行緒會使用來自 Amazon MSK 的 CDC 記錄，並將其傳送至執行緒集區進行處理。

1. 執行緒集區中的執行緒會處理 CDC 記錄，並將其傳送至目標資料庫。

1. 如果所有執行緒都忙碌，執行緒佇列會保留 CDC 記錄。

1. 主要執行緒會等待從執行緒佇列清除所有記錄，並將偏移遞交至 Amazon MSK。

1. 子執行緒處理失敗。如果在處理期間發生失敗，則失敗的訊息會傳送至 DLQ （無效字母佇列） 主題。

1. 子執行緒會根據大型主機時間戳記啟動條件式更新 （請參閱 DynamoDB 文件中的[條件表達](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ConditionExpressions.html)式），以避免資料庫中有任何重複或out-of-order的更新。

如需有關如何使用多執行緒功能實作 Kafka 消費者應用程式的資訊，請參閱 Confluent 網站上的部落格文章 [Apache Kafka 消費者的多執行緒訊息使用](https://www.confluent.io/blog/kafka-consumer-multi-threaded-messaging/)。

## 工具
<a name="replicate-mainframe-databases-to-aws-by-using-precisely-connect-tools"></a>

**AWS 服務**
+ [Amazon Managed Streaming for Apache Kafka (Amazon MSK)](https://docs.aws.amazon.com/msk/latest/developerguide/what-is-msk.html) 是一種全受管服務，可協助您建置和執行使用 Apache Kafka 處理串流資料的應用程式。
+ [Amazon Elastic Kubernetes Service (Amazon EKS)](https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html) 可協助您在 AWS 上執行 Kubernetes，而無需安裝或維護您自己的 Kubernetes 控制平面或節點。
+ [Amazon EKS Anywhere](https://anywhere.eks.amazonaws.com/docs/) 可協助您部署、使用和管理在您自己的資料中心執行的 Kubernetes 叢集。
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) 是一項全受管 NoSQL 資料庫服務，可提供快速、可預期且可擴展的效能。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 AWS 雲端中設定、操作和擴展關聯式資料庫。
+ [Amazon ElastiCache](https://docs.aws.amazon.com/elasticache/) 可協助您在 AWS 雲端中設定、管理和擴展分散式記憶體內快取環境。
+ [Amazon Keyspaces （適用於 Apache Cassandra)](https://docs.aws.amazon.com/keyspaces/latest/devguide/what-is-keyspaces.html) 是一種受管資料庫服務，可協助您在 AWS 雲端中遷移、執行和擴展 Cassandra 工作負載。

**其他工具**
+ [Precisely Connect](https://www.precisely.com/product/precisely-connect/connect) 將 VSAM 資料集或 IBM 大型主機資料庫等舊版大型主機系統的資料整合到新一代雲端和資料平台。

## 最佳實務
<a name="replicate-mainframe-databases-to-aws-by-using-precisely-connect-best-practices"></a>
+ 尋找 Kafka 分割區和多執行緒連接器的最佳組合，以平衡最佳效能和成本。由於較高的 MIPS （每秒百萬個指令） 使用量，多個精確擷取和發送器執行個體可能會增加成本。
+ 避免將資料處理和轉換邏輯新增至資料庫連接器。為此，請使用精確套用引擎，以微秒為單位提供處理時間。
+ 在資料庫連接器中建立資料庫 (*心跳） *的定期請求或運作狀態檢查呼叫，以經常暖機連線並降低延遲。
+ 實作執行緒集區驗證邏輯，以了解執行緒佇列中的待定任務，並等待所有執行緒完成，再進行下一次 Kafka 輪詢。這有助於避免節點、容器或程序當機時遺失資料。
+ 透過運作狀態端點公開延遲指標，透過儀表板和追蹤機制增強可觀測性功能。

## 史詩
<a name="replicate-mainframe-databases-to-aws-by-using-precisely-connect-epics"></a>

### 準備來源環境 （內部部署）
<a name="prepare-the-source-environment-on-premises"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定大型主機程序 （批次或線上公用程式），從大型主機資料庫啟動 CDC 程序。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | 大型主機工程師 | 
| 啟用大型主機資料庫日誌串流。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | 大型主機資料庫專家 | 
| 使用擷取元件來擷取 CDC 記錄。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | 大型主機工程師，精確連線 SME | 
| 設定發佈者元件以接聽擷取元件。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | 大型主機工程師，精確連線 SME | 
| 在內部部署分散式環境中佈建 Amazon EKS Anywhere。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | DevOps 工程師 | 
| 在分散式環境中部署和設定 Dispatcher 元件，以在 AWS 雲端中發佈主題。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | DevOps 工程師，精確連線中小企業 | 

### 準備目標環境 (AWS)
<a name="prepare-the-target-environment-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在指定的 AWS 區域中佈建 Amazon EKS 叢集。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | DevOps 工程師、網路管理員 | 
| 佈建 MSK 叢集並設定適用的 Kafka 主題。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | DevOps 工程師、網路管理員 | 
| 設定 Apply Engine 元件以聆聽複寫的 Kafka 主題。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | 精確連線 SME | 
| 在 AWS 雲端中佈建資料庫執行個體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | 資料工程師、DevOps 工程師 | 
| 設定和部署資料庫連接器，以聆聽套用引擎發佈的主題。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | 應用程式開發人員、雲端架構師、資料工程師 | 

### 設定業務持續性和災難復原
<a name="set-up-business-continuity-and-disaster-recovery"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為您的業務應用程式定義災難復原目標。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | 雲端架構師、資料工程師、應用程式擁有者 | 
| 根據定義的 RTO/RPO 設計災難復原策略。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | 雲端架構師、資料工程師 | 
| 佈建災難復原叢集和組態。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | DevOps 工程師、網路管理員、雲端架構師 | 
| 測試 CDC 管道的災難復原。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/replicate-mainframe-databases-to-aws-by-using-precisely-connect.html) | 應用程式擁有者、資料工程師、雲端架構師 | 

## 相關資源
<a name="replicate-mainframe-databases-to-aws-by-using-precisely-connect-resources"></a>

**AWS 資源**
+ [Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html)
+ [Amazon DynamoDB 的條件表達式](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ConditionExpressions.html)
+ [Amazon EKS](https://docs.aws.amazon.com/eks/index.html)
+ [Amazon EKS Anywhere](https://anywhere.eks.amazonaws.com/docs/)
+ [Amazon ElasticCache](https://docs.aws.amazon.com/elasticache/index.html)
+ [Amazon Keyspaces](https://docs.aws.amazon.com/keyspaces/?icmpid=docs_homepage_databases)
+ [Amazon MSK](https://docs.aws.amazon.com/msk/latest/developerguide/getting-started.html)
+ [Amazon RDS 和 Amazon Aurora](https://docs.aws.amazon.com/rds/index.html)
+ [Amazon VPC](https://docs.aws.amazon.com/vpc/index.html)

**精確連線資源**
+ [精確連線概觀](https://www.precisely.com/product/precisely-connect/connect)
+ [使用 Precisely Connect 變更資料擷取](https://help.precisely.com/r/Connect-CDC-SQData/4.1/en-US/Connect-CDC-SQData-Installation/Connect-CDC-SQData-Architecture)

**Confluent 資源**
+ [Apache Kafka 消費者的多執行緒訊息使用量](https://www.confluent.io/blog/kafka-consumer-multi-threaded-messaging/)

# 使用 Lambda 和 Secrets Manager 來排程 Amazon RDS for PostgreSQL 和 Aurora PostgreSQL 的任務
<a name="schedule-jobs-for-amazon-rds-for-postgresql-and-aurora-postgresql-by-using-lambda-and-secrets-manager"></a>

*Yaser Raja，Amazon Web Services*

## 總結
<a name="schedule-jobs-for-amazon-rds-for-postgresql-and-aurora-postgresql-by-using-lambda-and-secrets-manager-summary"></a>

對於內部部署資料庫和託管在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上的資料庫，資料庫管理員通常會使用 **cron** 公用程式來排程任務。

例如，可以使用 **Cron** 輕鬆排程資料擷取任務或資料清除任務。對於這些任務，資料庫登入資料通常是硬式編碼或存放在屬性檔案中。不過，當您遷移至 Amazon Relational Database Service (Amazon RDS) 或 Amazon Aurora PostgreSQL 相容版本時，將無法登入主機執行個體來排程 **Cron** 任務。 

此模式說明如何使用 AWS Lambda 和 AWS Secrets Manager 在遷移後排程 Amazon RDS for PostgreSQL 和 Aurora PostgreSQL 相容資料庫的任務。 

## 先決條件和限制
<a name="schedule-jobs-for-amazon-rds-for-postgresql-and-aurora-postgresql-by-using-lambda-and-secrets-manager-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ Amazon RDS for PostgreSQL 或 Aurora PostgreSQL 相容資料庫

**限制**
+ 任務必須在 15 分鐘內完成，也就是 Lambda 函數逾時限制。如需其他限制，請參閱 [AWS Lambda 文件](https://docs.aws.amazon.com/lambda/latest/dg/limits.html)。
+ 任務程式碼必須以 [Lambda 支援的語言](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)撰寫。

## Architecture
<a name="schedule-jobs-for-amazon-rds-for-postgresql-and-aurora-postgresql-by-using-lambda-and-secrets-manager-architecture"></a>

**來源技術堆疊**

此堆疊以 Bash、Python 和 Java 等語言撰寫的任務為特色。資料庫登入資料會存放在 屬性檔案中，並使用 Linux **cron** 排程任務。

**目標技術堆疊**

此堆疊具有 Lambda 函數，使用存放在 Secrets Manager 中的登入資料來連線至資料庫並執行活動。Lambda 函數是使用 Amazon CloudWatch Events 在排程間隔啟動。

**目標架構**

![\[CloudWatch 事件會啟動 Lambda 函數，以排程 RDS 資料庫執行個體的任務。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/8e0d1c90-0599-4909-a800-26a89b87f686/images/61f9ca34-9157-4565-96ba-5234d389ac2a.png)


## 工具
<a name="schedule-jobs-for-amazon-rds-for-postgresql-and-aurora-postgresql-by-using-lambda-and-secrets-manager-tools"></a>
+ [Amazon CloudWatch Events](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html) 提供近乎即時的系統事件串流，描述 AWS 資源的變更。使用您可以快速設定的簡單規則，您可以比對事件並將它們路由到一或多個目標函數或串流。CloudWatch Events 在操作變更時會查覺到。它會回應這些操作變更，並視需要採取修正動作，透過傳送訊息來回應環境、啟用 函數、進行變更，以及擷取狀態資訊。您也可以使用 CloudWatch Events 來排程使用 **Cron** 或 **Rate** 表達式在特定時間自行啟動的自動化動作。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一種運算服務，讓您無需設定或管理伺服器即可運行程式碼。Lambda 只有在需要時才會執行程式碼，可自動從每天數項請求擴展成每秒數千項請求。您只需為使用的運算時間付費；程式碼未執行時無需付費。使用 Lambda，您可以為幾乎任何類型的應用程式或後端服務執行程式碼，無需管理。Lambda 在高可用性運算基礎設施上執行程式碼，並管理所有運算資源，包括伺服器和作業系統維護、容量佈建和自動擴展、程式碼監控和記錄。您只需使用 [Lambda 支援](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)的語言之一提供程式碼即可。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您保護存取應用程式、服務和 IT 資源的秘密。您可以在資料庫憑證、API 金鑰和其他秘密的整個生命週期中輕鬆輪換、管理和擷取。使用者和應用程式透過呼叫 Secrets Manager APIs 來擷取秘密，無需以純文字硬式編碼敏感資訊。Secrets Manager 提供秘密輪換與 Amazon RDS、Amazon Redshift 和 Amazon DocumentDB 的內建整合。此服務可延伸至其他類型的秘密，包括 API 金鑰和 OAuth 權杖。Secrets Manager 可讓您使用精細的許可控制對秘密的存取，並針對 AWS 雲端、第三方服務和內部部署中的資源集中稽核秘密輪換。

## 史詩
<a name="schedule-jobs-for-amazon-rds-for-postgresql-and-aurora-postgresql-by-using-lambda-and-secrets-manager-epics"></a>

### 在 Secrets Manager 中存放資料庫登入資料
<a name="store-database-credentials-in-asm"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 為 Lambda 函數建立資料庫使用者。 | 最佳實務是針對應用程式的不同部分使用不同的資料庫使用者。如果您的 Cron 任務已存在不同的資料庫使用者，請使用它。否則，請建立新的資料庫使用者。如需詳細資訊，請參閱[管理 PostgreSQL 使用者和角色](https://aws.amazon.com/blogs/database/managing-postgresql-users-and-roles/) (AWS 部落格文章）。 | DBA | 
| 在 Secrets Manager 中將資料庫登入資料儲存為秘密。 | 遵循[建立資料庫秘密](https://docs.aws.amazon.com/secretsmanager/latest/userguide/create_database_secret.html) (Secrets Manager 文件） 中的指示。 | DBA、DevOps | 

### 編寫 Lambda 函數的程式碼
<a name="author-the-code-for-the-lam-function"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 選擇 Lambda 支援的程式設計語言。 | 如需支援的語言清單，請參閱 [Lambda 執行時間 ](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)(Lambda 文件）。 | 開發人員 | 
| 撰寫邏輯以從 Secrets Manager 擷取資料庫登入資料。 | 如需範例程式碼，請參閱[如何使用 安全地提供資料庫登入資料給 Lambda 函數 AWS Secrets Manager](https://aws.amazon.com/blogs/security/how-to-securely-provide-database-credentials-to-lambda-functions-by-using-aws-secrets-manager/)(AWS 部落格文章）。 | 開發人員 | 
| 撰寫邏輯以執行排定的資料庫活動。 | 將您現場部署使用之排程任務的現有程式碼遷移至 Lambda 函數。如需詳細資訊，請參閱[部署 Lambda 函數](https://docs.aws.amazon.com/lambda/latest/dg/lambda-deploy-functions.html) (Lambda 文件）。 | 開發人員 | 

### 部署程式碼並建立 Lambda 函數
<a name="deploy-the-code-and-create-the-lam-function"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Lambda 函數部署套件。 | 此套件包含程式碼及其相依性。如需詳細資訊，請參閱[部署套件](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html) (Lambda 文件）。 | 開發人員 | 
| 建立 Lambda 函數。 | 在 Lambda 主控台中，選擇**建立函數**，輸入函數名稱，選擇執行時間環境，然後選擇**建立函數**。 | DevOps | 
| 上傳部署套件。 | 選擇您建立的 Lambda 函數以開啟其組態。您可以直接在程式碼區段中撰寫程式碼，或上傳部署套件。若要上傳套件，請前往**函數程式碼**區段，選擇**程式碼項目類型**以上傳 .zip 檔案，然後選取套件。 | DevOps | 
| 根據您的需求設定 Lambda 函數。 | 例如，您可以將**逾時**參數設定為您預期 Lambda 函數需要的持續時間。如需詳細資訊，請參閱[設定函數選項](https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html) (Lambda 文件）。 | DevOps | 
| 設定 Lambda 函數角色的許可，以存取 Secrets Manager。 | 如需說明，請參閱[在 AWS Lambda 函數中使用秘密](https://docs.aws.amazon.com/secretsmanager/latest/userguide/retrieving-secrets_lambda.html) (Secrets Manager 文件）。 | DevOps | 
| 測試 Lambda 函數。 | 手動啟動 Lambda 函數，以確保其如預期般運作。 | DevOps | 

### 使用 CloudWatch Events 排程 Lambda 函數
<a name="schedule-the-lam-function-by-using-cwe"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立規則以依排程執行 Lambda 函數。 | 使用 CloudWatch Events 排程 Lambda 函數。如需說明，請參閱[使用 CloudWatch Events 排程 Lambda 函數](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html) (CloudWatch Events 教學課程）。 | DevOps | 

## 相關資源
<a name="schedule-jobs-for-amazon-rds-for-postgresql-and-aurora-postgresql-by-using-lambda-and-secrets-manager-resources"></a>
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html)
+ [Lambda 入門](https://docs.aws.amazon.com/lambda/latest/dg/getting-started.html)
+ [建立在事件上觸發的 CloudWatch 事件規則](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/Create-CloudWatch-Events-Rule.html)
+ [AWS Lambda 限制](https://docs.aws.amazon.com/lambda/latest/dg/limits.html)
+ [從無伺服器應用程式查詢 AWS 資料庫 ](https://aws.amazon.com/blogs/database/query-your-aws-database-from-your-serverless-application/)（部落格文章）

# 使用內部部署 SMTP 伺服器和 Database Mail 傳送 Amazon RDS for SQL Server 資料庫執行個體的通知
<a name="send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail"></a>

*Nishad Mankar，Amazon Web Services*

## 總結
<a name="send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail-summary"></a>

[Database Mail](https://learn.microsoft.com/en-us/sql/relational-databases/database-mail/database-mail?view=sql-server-ver16) (Microsoft 文件） 使用 Simple Mail Transfer Protocol (SMTP) 伺服器，從 Microsoft SQL Server 資料庫傳送電子郵件訊息，例如通知或提醒。Amazon Relational Database Service (Amazon RDS) for Microsoft SQL Server 文件提供使用 Amazon Simple Email Service (Amazon SES) 做為 Database Mail SMTP 伺服器的說明。如需詳細資訊，請參閱[在 Amazon RDS for SQL Server 上使用 Database Mail](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.DBMail.html)。做為替代組態，此模式說明如何使用內部部署 SMTP 伺服器做為郵件伺服器，將 Database Mail 設定為從 Amazon RDS for SQL Server 資料庫 (DB) 執行個體傳送電子郵件。

## 先決條件和限制
<a name="send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 執行 SQL Server 標準版或企業版的 Amazon RDS 資料庫執行個體
+ 內部部署 SMTP 伺服器的 IP 地址或主機名稱
+ 傳入[安全群組規則](https://docs.aws.amazon.com/vpc/latest/userguide/security-group-rules.html#working-with-security-group-rules)，允許從 SMTP 伺服器的 IP 地址連線至 Amazon RDS for SQL Server 資料庫執行個體
+ 內部部署網路與包含 Amazon RDS 資料庫執行個體的虛擬私有雲端 (VPC) 之間的連線，例如 [AWS Direct Connect](https://docs.aws.amazon.com/directconnect/latest/UserGuide/Welcome.html) 連線

**限制**
+ 不支援 SQL Server 的 Express 版本。
+ 如需限制的詳細資訊，請參閱《*Amazon RDS 文件》中的在 Amazon RDS for SQL Server 上使用資料庫郵件*中的[限制](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html#SQLServer.Concepts.General.FeatureSupport.Limits)。

**產品版本**
+ [RDS 中支援的 SQL Server 版本](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html#SQLServer.Concepts.General.VersionSupport)標準版和企業版

## Architecture
<a name="send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail-architecture"></a>

**目標技術堆疊**
+ Amazon RDS for SQL Server 資料庫執行個體
+ Amazon Route 53 轉送規則
+ 資料庫郵件
+ 內部部署 SMTP 伺服器
+ Microsoft SQL Server Management Studio (SSMS)

**目標架構**

下圖顯示此模式的目標架構。發生事件或動作啟動有關資料庫執行個體的通知或提醒時，Amazon RDS for SQL Server 會使用 Database Mail 傳送電子郵件通知。Database Mail 使用內部部署 SMTP 伺服器來傳送電子郵件。

![\[Amazon RDS for SQL Server 使用內部部署 SMTP 伺服器傳送電子郵件通知給使用者。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/e5599724-43cf-4fe1-8c5a-8fca1a424993/images/47efb12f-3505-4a60-ac43-194a176e71c8.png)


## 工具
<a name="send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail-tools"></a>

**AWS 服務**
+ [適用於 Microsoft SQL Server 的 Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html) 可協助您在 AWS 雲端中設定、操作和擴展 SQL Server 關聯式資料庫。
+ [Amazon Route 53](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/Welcome.html) 是一種可用性高、可擴展性強的 DNS Web 服務。

**其他工具**
+ [Database Mail](https://learn.microsoft.com/en-us/sql/relational-databases/database-mail/database-mail) 是一種工具，可將通知和提醒等電子郵件訊息從 SQL Server 資料庫引擎傳送給使用者。
+ [Microsoft SQL Server Management Studio (SSMS)](https://docs.microsoft.com/en-us/sql/ssms/sql-server-management-studio-ssms) 是一種用於管理 SQL Server 的工具，包括存取、設定和管理 SQL Server 元件。在此模式中，您可以使用 SSMS 執行 SQL 命令，在 Amazon RDS for SQL Server 資料庫執行個體上設定 Database Mail。 

## 史詩
<a name="send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail-epics"></a>

### 啟用與內部部署 SMTP 伺服器的網路連線
<a name="enable-network-connectivity-with-the-on-premises-smtp-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 從 RDS 資料庫執行個體移除異地同步備份。 | 如果您使用的是多區域 RDS 資料庫執行個體，請將多可用區域執行個體轉換為單一可用區域執行個體。當您完成設定 Database Mail 後，會將資料庫執行個體轉換回異地同步備份部署。Database Mail 組態接著可在主要節點和次要節點中運作。如需說明，請參閱[從 Microsoft SQL Server 資料庫執行個體移除異地](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_SQLServerMultiAZ.html#USER_SQLServerMultiAZ.Removing)同步備份。 | DBA | 
| 在內部部署 SMTP 伺服器上建立 Amazon RDS 端點或 IP 地址的允許清單。 | SMTP 伺服器位於 AWS 網路之外。在內部部署 SMTP 伺服器上，建立允許清單，允許伺服器與 Amazon RDS 執行個體或 Amazon RDS 上託管的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體的傳出端點或 IP 地址進行通訊。此程序因組織而異。如需資料庫執行個體端點的詳細資訊，請參閱[尋找資料庫執行個體端點和連接埠號碼](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToMicrosoftSQLServerInstance.html#sqlserver-endpoint)。 | DBA | 
| 移除連接埠 25 限制。 | 根據預設，AWS 會限制 EC2 執行個體上的連接埠 25。若要移除連接埠 25 限制，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail.html)[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail.html) | 一般 AWS | 
| 新增 Route 53 規則來解析 SMTP 伺服器的 DNS 查詢。 | 使用 Route 53 解析 AWS 資源與內部部署 SMTP 伺服器之間的 DNS 查詢。您必須建立將 DNS 查詢轉送至 SMTP 伺服器網域的規則，例如 `example.com`。如需說明，請參閱 Route 53 文件中的[建立轉送規則](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resolver-rules-managing.html#resolver-rules-managing-creating-rules)。 | 網路管理員 | 

### 在 Amazon RDS for SQL Server 資料庫執行個體上設定 Database Mail
<a name="set-up-database-mail-on-the-amazon-rds-for-sql-server-db-instance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟用資料庫郵件。 | 建立 Database Mail 的參數群組，將 `database mail xps` 參數設定為 `1`，然後將 Database Mail 參數群組與目標 RDS 資料庫執行個體建立關聯。如需說明，請參閱 Amazon RDS 文件中的[啟用資料庫郵件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.DBMail.html#SQLServer.DBMail.Enable)。請勿繼續進行這些說明中的*設定資料庫郵件*一節。內部部署 SMTP 伺服器的組態與 Amazon SES 不同。 | DBA | 
| 連線到資料庫執行個體。 | 從堡壘主機，使用 Microsoft SQL Server Management Studio (SSMS) 連線至 Amazon RDS for SQL Server 資料庫執行個體。如需說明，請參閱[連線至執行 Microsoft SQL Server 資料庫引擎的資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToMicrosoftSQLServerInstance.html)。如果您遇到任何錯誤，請參閱[相關資源](#send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail-resources)區段中的連線故障診斷參考。 | DBA | 
| 建立設定檔。 | 在 SSMS 中，輸入下列 SQL 陳述式來建立 Database Mail 設定檔。取代以下的值：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail.html)如需此預存程序及其引數的詳細資訊，請參閱 Microsoft 文件中的 [sysmail\$1add\$1profile\$1sp](https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sysmail-add-profile-sp-transact-sql)。<pre>EXECUTE msdb.dbo.sysmail_add_profile_sp<br /> @profile_name = 'SQL Alerts profile',<br /> @description = 'Profile used for sending outgoing notifications using OM SMTP Server.';</pre> | DBA | 
| 將主體新增至設定檔。 | 輸入下列 SQL 陳述式，將公有或私有主體新增至 Database Mail 設定檔。*主體*是可以要求 SQL Server 資源的實體。取代以下的值：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail.html)如需此預存程序及其引數的詳細資訊，請參閱 Microsoft 文件中的 [sysmail\$1add\$1principalprofile\$1sp](https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sysmail-add-principalprofile-sp-transact-sql)。<pre>EXECUTE msdb.dbo.sysmail_add_principalprofile_sp<br /> @profile_name = 'SQL Alerts profile',<br /> @principal_name = 'public',<br /> @is_default = 1 ;</pre> | DBA | 
| 建立 帳戶。 | 輸入下列 SQL 陳述式來建立 Database Mail 帳戶。取代以下的值：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail.html)如需此預存程序及其引數的詳細資訊，請參閱 Microsoft 文件中的 [sysmail\$1add\$1account\$1sp](https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sysmail-add-account-sp-transact-sql)。<pre>EXECUTE msdb.dbo.sysmail_add_account_sp<br /> @account_name = 'SQL Alerts account',<br /> @description = 'Database Mail account for sending outgoing notifications.',<br /> @email_address = 'xyz@example.com',<br /> @display_name = 'xyz@example.com',<br /> @mailserver_name = 'test_smtp.example.com',<br /> @port = 25,<br /> @enable_ssl = 1,<br /> @username = 'SMTP-username',<br /> @password = 'SMTP-password';</pre> | DBA | 
| 將帳戶新增至設定檔。 | 輸入下列 SQL 陳述式，將 Database Mail 帳戶新增至 Database Mail 設定檔。取代以下的值：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail.html)如需此預存程序及其引數的詳細資訊，請參閱 Microsoft 文件中的 [sysmail\$1add\$1profileaccount\$1sp](https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sysmail-add-profileaccount-sp-transact-sql)。<pre>EXECUTE msdb.dbo.sysmail_add_profileaccount_sp<br /> @profile_name = 'SQL Alerts profile',<br /> @account_name = 'SQL Alerts account',<br /> @sequence_number = 1;</pre> | DBA | 
| （選用） 將異地同步備份新增至 RDS 資料庫執行個體。 | 如果您想要使用資料庫鏡像 (DBM) 或 Always On 可用性群組 (AGs) 新增異地同步備份，請參閱[將異地同步備份新增至 Microsoft SQL Server 資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_SQLServerMultiAZ.html#USER_SQLServerMultiAZ.Adding)中的指示。 | DBA | 

## 相關資源
<a name="send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail-resources"></a>
+ [在 Amazon RDS for SQL Server 上使用資料庫郵件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.DBMail.html) (Amazon RDS 文件）
+ [使用檔案附件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.DBMail.html#SQLServer.DBMail.MAZ) (Amazon RDS 文件）
+ [針對 SQL Server 資料庫執行個體的連線進行故障診斷 ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToMicrosoftSQLServerInstance.html#USER_ConnectToMicrosoftSQLServerInstance.Troubleshooting)(Amazon RDS 文件）
+ [無法連線至 Amazon RDS 資料庫執行個體 ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Troubleshooting.html#CHAP_Troubleshooting.Connecting)(Amazon RDS 文件）

# 在 AWS 上設定 SAP on IBM Db2 的災難復原
<a name="set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws"></a>

*Ambarish Satarkar and Debasis Sahoo，Amazon Web Services*

## 總結
<a name="set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws-summary"></a>

此模式概述使用 IBM Db2 做為資料庫平台，在 Amazon Web Services (AWS) 雲端上執行，為 SAP 工作負載設定災難復原 (DR) 系統的步驟。目標是提供低成本的解決方案，以便在發生中斷時提供業務持續性。

模式使用[指示燈方法](https://aws.amazon.com/blogs/architecture/disaster-recovery-dr-architecture-on-aws-part-iii-pilot-light-and-warm-standby/)。透過在 AWS 上實作指示燈 DR，您可以減少停機時間並維持業務連續性。指示燈方法著重於在 AWS 中設定最小 DR 環境，包括與生產環境同步的 SAP 系統和待命 Db2 資料庫。

此解決方案可擴展。您可以視需要將其擴展到完整規模的災難復原環境。

## 先決條件和限制
<a name="set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws-prereqs"></a>

**先決條件**
+ 在 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上執行的 SAP 執行個體
+ IBM Db2 資料庫
+ SAP 產品可用性矩陣 (PAM) 支援的作業系統
+ 生產和待命資料庫主機的不同實體資料庫主機名稱
+ 每個啟用跨區域複寫 (CRR) 的 AWS 區域中的 Amazon Simple Storage Service (Amazon S3) 儲存貯體 [https://docs.aws.amazon.com/AmazonS3/latest/userguide/replication.html](https://docs.aws.amazon.com/AmazonS3/latest/userguide/replication.html) 

**產品版本**
+ IBM Db2 資料庫版本 11.5.7 或更新版本

## Architecture
<a name="set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws-architecture"></a>

**目標技術堆疊**
+ Amazon EC2
+ Amazon Simple Storage Service (Amazon S3)
+ Amazon Virtual Private Cloud (VPC 對等互連）
+ Amazon Route 53
+ IBM Db2 高可用性災難復原 (HADR)

**目標架構**

此架構會使用 Db2 做為資料庫平台，為 SAP 工作負載實作 DR 解決方案。生產資料庫部署在 AWS 區域 1，待命資料庫則部署在第二個區域。待命資料庫稱為 DR 系統。Db2 資料庫支援多個待命資料庫 （最多三個）。它使用 Db2 HADR 來設定 DR 資料庫，並在生產和待命資料庫之間自動化日誌運送。

如果發生使區域 1 無法使用的災難，DR 區域中的待命資料庫會接管生產資料庫角色。SAP 應用程式伺服器可以事先建置，或使用 [AWS Elastic Disaster Recovery](https://aws.amazon.com/disaster-recovery/) 或 Amazon Machine Image (AMI) 來滿足復原時間目標 (RTO) 需求。此模式使用 AMI。

Db2 HADR 實作生產待命設定，其中生產做為主要伺服器，且所有使用者都與其連線。所有交易都會寫入日誌檔案，這些檔案會使用 TCP/IP 傳輸到待命伺服器。待命伺服器透過轉傳傳輸的日誌記錄來更新其本機資料庫，這有助於確保其與生產伺服器保持同步。

使用 VPC 對等互連，以便生產區域和 DR 區域中的執行個體可以互相通訊。Amazon Route 53 會將最終使用者路由至網際網路應用程式。

![\[具有跨區域複寫的 AWS 上的 Db2\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/06edfa4c-0827-4d05-95cf-2d2651e74323/images/e77c1e4e-36f3-4af4-89d0-8eec72348f0a.png)


1. [在區域 ](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html#creating-an-ami)1 中建立應用程式伺服器的 AMI[，並將 AMI 複製到](https://repost.aws/knowledge-center/copy-ami-region)區域 2。發生災難時，使用 AMI 在區域 2 中啟動伺服器。

1. 在生產資料庫 （區域 1) 和待命資料庫 （區域 2) 之間設定 Db2 HADR 複寫。

1. 變更 EC2 執行個體類型，以符合發生災難時的生產執行個體。

1. 在區域 1 中， `LOGARCHMETH1` 設定為 `db2remote: S3 path`。

1. 在區域 2 中， `LOGARCHMETH1` 設定為 `db2remote: S3 path`。

1. 跨區域複寫會在 S3 儲存貯體之間執行。

## 工具
<a name="set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Amazon Route 53](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/Welcome.html) 是一種可用性高、可擴展性強的 DNS Web 服務。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。
+ [Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) 可協助您在已定義的虛擬網路中啟動 AWS 資源。這個虛擬網路類似於您在自己的資料中心內操作的傳統網路，具有使用可擴展的 AWS 基礎設施的優勢。此模式使用 [VPC 對等](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-peering.html)互連。

## 最佳實務
<a name="set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws-best-practices"></a>
+ 網路在決定 HADR 複寫模式時扮演重要角色。對於跨 AWS 區域的 DR，我們建議您使用 Db2 HADR ASYNC 或 SUPERASYNC 模式。 
+ 如需 Db2 HADR 複寫模式的詳細資訊，請參閱 [IBM 文件](https://ibm.github.io/db2-hadr-wiki/hadrSyncMode.html#Description_of_the_Modes)。
+ 您可以使用 AWS 管理主控台或 AWS 命令列界面 (AWS CLI) 來[建立現有 SAP 系統的新 AMI](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html#creating-an-ami)。然後，您可以使用 AMI 來復原現有的 SAP 系統或建立複製。
+ [AWS Systems Manager Automation](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html) 可協助 EC2 執行個體和其他 AWS 資源的常見維護和部署任務。
+ AWS 提供多個原生服務來監控和管理 AWS 上的基礎設施和應用程式。Amazon CloudWatch 和 AWS CloudTrail 等服務可以分別用來監控基礎基礎設施和 API 操作。如需詳細資訊，請參閱 [SAP on AWS – IBM Db2 HADR with Pacemaker](https://docs.aws.amazon.com/sap/latest/sap-AnyDB/sap-ibm-pacemaker.html)。

## 史詩
<a name="set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws-epics"></a>

### 準備環境
<a name="prepare-the-environment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢查系統和日誌。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.html) | AWS 管理員、SAP Basis 管理員 | 

### 設定伺服器和複寫
<a name="set-up-the-servers-and-replication"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 SAP 和資料庫伺服器。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.html)在還原完整備份之後，依預設會設定向前滾動擱置狀態。向前移動擱置狀態表示資料庫正在還原中，而且可能需要套用一些變更。如需詳細資訊，請參閱 [IBM 文件](https://www.ibm.com/docs/en/db2/11.5?topic=commands-rollforward-database)。 | SAP Basis 管理員 | 
| 檢查組態。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.html) | AWS 管理員、SAP Basis 管理員 | 
| 設定從生產資料庫到 DR 資料庫的複寫 （使用 ASYNC 模式）。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.html) | SAP Basis 管理員 | 

### 測試 DR 容錯移轉任務
<a name="test-dr-failover-tasks"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 規劃 DR 測試的生產業務停機時間。 | 請務必在生產環境中規劃必要的業務停機時間，以測試 DR 容錯移轉案例。 | SAP Basis 管理員 | 
| 建立測試使用者。 | 建立可在 DR 主機中驗證的測試使用者 （或任何測試變更），以確認 DR 容錯移轉後的日誌複寫。 | SAP Basis 管理員 | 
| 在 主控台上，停止生產 EC2 執行個體。 | 在此步驟中會啟動不規律關機，以模擬災難案例。 | AWS 系統管理員 | 
| 擴展 DR EC2 執行個體以符合需求。 | 在 EC2 主控台上，變更 DR 區域中的執行個體類型。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.html) | SAP 基礎管理員 | 
| 啟動接管。 | 從 DR 系統 (`host2`) 啟動接管程序，並將 DR 資料庫做為主要資料庫。<pre>db2 takeover hadr on database <SID> by force</pre>或者，您可以設定下列參數，根據執行個體類型自動調整資料庫記憶體配置。值`INSTANCE_MEMORY`可以根據要配置給 Db2 資料庫的記憶體專用部分來決定。<pre>db2 update db cfg for <SID> using INSTANCE_MEMORY <FIXED VALUE> IMMEDIATE;<br />db2 get db cfg for <SID> | grep -i DATABASE_MEMORY AUTOMATIC IMMEDIATE; <br />db2 update db cfg for <SID> using self_tuning_mem ON IMMEDIATE;</pre>使用以下命令驗證變更。<pre>db2 get db cfg for <SID> | grep -i MEMORY<br />db2 get db cfg for <SID> | grep -i self_tuning_mem</pre> | SAP Basis 管理員 | 
| 在 DR 區域中啟動 SAP 的應用程式伺服器。 | 使用您從生產系統建立的 AMI，在 DR 區域中[啟動新的額外應用程式伺服器](https://aws.amazon.com/premiumsupport/knowledge-center/launch-instance-custom-ami/)。 | SAP Basis 管理員 | 
| 在啟動 SAP 應用程式之前執行驗證。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.html) | AWS 管理員、SAP Basis 管理員 | 
| 在 DR 系統上啟動 SAP 應用程式。 | 使用 `<sid>adm`使用者在 DR 系統上啟動 SAP 應用程式。使用下列程式碼，其中 `XX`代表 SAP ABAP SAP Central Services (ASCS) 伺服器的執行個體編號，而 `YY`代表 SAP 應用程式伺服器的執行個體編號。<pre>sapconrol -nr XX -function StartService <SID><br />sapconrol -nr XX -function StartSystem<br />sapconrol -nr YY -function StartService <SID><br />sapconrol -nr YY -function StartSystem</pre> | SAP Basis 管理員 | 
| 執行 SAP 驗證。 | 這是做為 DR 測試來執行，以提供證據或檢查 DR 區域的資料複寫成功。 | 測試工程師 | 

### 執行 DR 容錯回復任務
<a name="perform-dr-failback-tasks"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 啟動生產 SAP 和資料庫伺服器。 | 在 主控台上，啟動在生產系統中託管 SAP 和資料庫的 EC2 執行個體。 | SAP Basis 管理員 | 
| 啟動生產資料庫並設定 HADR。 | 使用下列命令登入生產系統 (`host1`) 並確認資料庫處於復原模式。<pre>db2start<br />db2 start HADR on db P3V as standby<br />db2 connect to <SID></pre>確認 HADR 狀態為 `connected`。複寫狀態應為 `peer`。<pre>db2pd -d <SID> -hadr</pre>如果資料庫不不一致，且未處於 `connected` 和 `peer` 狀態，則備份和還原可能需要讓資料庫 （位於 `host1`) 與目前作用中的資料庫 (`host2`位於 DR 區域中） 同步。在這種情況下，請將資料庫備份從 DR `host2` 區域中的資料庫還原至`host1`生產區域中的資料庫。 | SAP Basis 管理員 | 
| 將資料庫容錯移轉回生產區域。 | 在正常business-as-usual情況下，此步驟會在排程的停機時間中執行。在 DR 系統上執行的應用程式會停止，且資料庫會失敗回生產區域 （區域 1)，以從生產區域恢復操作。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.html) | SAP Basis 管理員 | 
| 在啟動 SAP 應用程式之前執行驗證。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.html) | AWS 管理員、SAP Basis 管理員 | 
| 啟動 SAP 應用程式。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.html) | SAP Basis 管理員 | 

## 疑難排解
<a name="set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 用於排除 HADR 相關問題的金鑰日誌檔案和命令 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.html) | 
| 疑難排解 Db2 UDB 上 HADR 問題的 SAP 注意事項 | 請參閱 SAP [Note 1154013 - DB6：HADR 環境中的資料庫問題](https://service.sap.com/sap/support/notes/1154013)。（您需要 SAP 入口網站登入資料才能存取此備註。) | 

## 相關資源
<a name="set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws-resources"></a>
+ [AWS 上 Db2 資料庫的災難復原方法](https://aws.amazon.com/blogs/architecture/disaster-recovery-approaches-for-db2-databases-on-aws/) （部落格文章）
+ [SAP on AWS – IBM Db2 HADR 搭配 Pacemaker](https://docs.aws.amazon.com/sap/latest/sap-AnyDB/sap-ibm-pacemaker.html)
+ [在DB2 資料庫之間設定 HADR 複寫的逐步程序](https://www.ibm.com/support/pages/step-step-procedure-set-hadr-replication-between-db2-databases)
+ [Db2 HADR Wiki](https://ibm.github.io/db2-hadr-wiki/index.html)

## 其他資訊
<a name="set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws-additional"></a>

使用此模式，您可以為在 Db2 資料庫上執行的 SAP 系統設定災難復原系統。在災難情況下，業務應該能夠在您定義的復原時間目標 (RTO) 和復原點目標 (RPO) 要求內繼續：
+ **RTO** 是服務中斷和服務還原之間的最大可接受延遲。這會決定可接受的服務無法使用之時間長度。
+ **RPO** 是自上次資料復原點以來可接受的時間上限。這會決定最後一個復原點與服務中斷之間可接受的資料遺失。

如需 HADR 相關的FAQs，請參閱 [SAP 備註 \$11612105 - DB6：Db2 高可用性災難復原 (HADR) 的常見問答集](https://launchpad.support.sap.com/#/notes/1612105)。（您需要 SAP 入口網站登入資料才能存取此備註。)

# 使用 Terraform 設定資料庫遷移的 CI/CD 管道
<a name="set-up-ci-cd-pipeline-for-db-migration-with-terraform"></a>

*Rahul Sharad Gaikwad、Ashish Bhatt、Aniket Dekate、Ruchika Modi、Tamilselvan P、Nadeem Rahaman、Aarti Rajput 和 Naveen Suthar、Amazon Web Services*

## 總結
<a name="set-up-ci-cd-pipeline-for-db-migration-with-terraform-summary"></a>

此模式旨在建立持續整合和持續部署 (CI/CD) 管道，以可靠且自動化的方式管理資料庫遷移。它涵蓋了佈建必要基礎設施、遷移資料以及使用 Terraform 自訂結構描述變更的程序，Terraform 是一種基礎設施即程式碼 (IaC) 工具。

具體而言， 模式會設定 CI/CD 管道，將內部部署 Microsoft SQL Server 資料庫遷移至 上的 Amazon Relational Database Service (Amazon RDS) AWS。您也可以使用此模式，將虛擬機器 (VM) 或其他雲端環境中的 SQL Server 資料庫遷移至 Amazon RDS。

此模式可解決下列與資料庫管理和部署相關的挑戰：
+ 手動資料庫部署非常耗時、容易出錯，而且缺乏跨環境的一致性。
+ 協調基礎設施佈建、資料遷移和結構描述變更可能很複雜且難以管理。
+ 確保資料完整性並將資料庫更新期間的停機時間降至最低，對生產系統至關重要。

此模式提供下列優點：
+ 透過實作資料庫遷移的 CI/CD 管道，簡化更新和部署資料庫變更的程序。這可降低錯誤風險、確保跨環境的一致性，並將停機時間降至最低。
+ 有助於改善可靠性、效率和協同合作。可在資料庫更新期間加快上市時間並減少停機時間。
+ 協助您針對資料庫管理採用現代 DevOps 實務，進而在軟體交付程序中提高敏捷性、可靠性和效率。

## 先決條件和限制
<a name="set-up-ci-cd-pipeline-for-db-migration-with-terraform-prereqs"></a>

**先決條件**
+ 作用中 AWS 帳戶
+ 本機電腦上已安裝 Terraform 0.12 或更新版本 （如需說明，請參閱 [Terraform 文件](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli))
+ 來自 HashiCorp 的 Terraform AWS Provider 3.0.0 版或更新版本 （請參閱此供應商的 [GitHub 儲存庫](https://github.com/hashicorp/terraform-provider-aws))
+ 最低權限 AWS Identity and Access Management (IAM) 政策 （請參閱部落格文章[撰寫最低權限 IAM 政策的技術](https://aws.amazon.com/blogs/security/techniques-for-writing-least-privilege-iam-policies/))

## Architecture
<a name="set-up-ci-cd-pipeline-for-db-migration-with-terraform-architecture"></a>

此模式實作下列架構，為資料庫遷移程序提供完整的基礎設施。

![\[CI/CD 管道架構，用於將內部部署 SQL Server 資料庫遷移至 AWS 上的 Amazon RDS。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/87845d9f-8e6e-4c51-b9ee-9e7833671d05/images/a1e95458-419a-4de9-85ef-b17d8340700a.png)


在此架構中：
+ 來源資料庫是現場部署、虛擬機器 (VM) 或由其他雲端供應商託管的 SQL Server 資料庫。此圖假設來源資料庫位於內部部署資料中心。
+ 內部部署資料中心和 透過 VPN 或 AWS 連線進行 AWS Direct Connect 連線。這可提供來源資料庫與 AWS 基礎設施之間的安全通訊。
+ 目標資料庫是在資料庫佈建管道的協助 AWS 下，託管在 虛擬私有雲端 (VPC) 內的 Amazon RDS 資料庫。
+ AWS Database Migration Service (AWS DMS) 會將您的內部部署資料庫複寫到 AWS。它用於設定來源資料庫到目標資料庫的複寫。

下圖顯示設定不同層級資料庫遷移程序的基礎設施，其中包含佈建、 AWS DMS 設定和驗證。

![\[從內部部署到 AWS 的遷移程序 CI/CD 管道詳細資訊。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/87845d9f-8e6e-4c51-b9ee-9e7833671d05/images/3aca17e5-6fd7-4317-b578-ab5e485c6efb.png)


在此程序中：
+ 驗證管道會驗證所有檢查。當所有必要的驗證完成時，整合管道會移至下一個步驟。
+ 資料庫佈建管道由各種階段組成，這些 AWS CodeBuild 階段會對資料庫提供的 Terraform 程式碼執行 Terraform 動作。當這些步驟完成時，它會在目標中部署資源 AWS 帳戶。
+  AWS DMS 管道包含各種 CodeBuild 階段，這些階段會執行測試，然後使用 IaC 佈建執行遷移的 AWS DMS 基礎設施。

## 工具
<a name="set-up-ci-cd-pipeline-for-db-migration-with-terraform-tools"></a>

**AWS 服務 和 工具**
+ [AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/welcome.html) 是一種全受管持續整合服務，可編譯原始程式碼、執行測試，並產生ready-to-deploy的軟體套件。
+ [AWS CodePipeline](https://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html) 是一種全受管持續交付服務，可協助您自動化發行管道，以實現快速可靠的應用程式和基礎設施更新。
+ [Amazon Relational Database Service (Amazon RDS)](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html) 可協助您在 中設定、操作和擴展關聯式資料庫 AWS 雲端。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種物件儲存服務，可提供可擴展性、資料可用性、安全性和效能。
+ [AWS Database Migration Service (AWS DMS)](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html) 可協助您將資料存放區遷移到 AWS 雲端 或在雲端和內部部署設定的組合之間遷移。

**其他服務**
+ [Terraform](https://www.terraform.io/) 是 HashiCorp 的 IaC 工具，可協助您建立和管理雲端和內部部署資源。

**程式碼儲存庫**

此模式的程式碼可在 GitHub [Database Migration DevOps Framework 中使用 Terraform 範例](https://github.com/aws-samples/aws-terraform-db-migration-framework-samples)儲存庫。

## 最佳實務
<a name="set-up-ci-cd-pipeline-for-db-migration-with-terraform-best-practices"></a>
+ 實作資料庫遷移的自動化測試，以驗證結構描述變更和資料完整性的正確性。這包括單元測試、整合測試和end-to-end測試。
+ 為您的資料庫實作強大的備份和還原策略，特別是在遷移之前。這可確保資料完整性，並在發生故障時提供備用選項。
+ 實作強大的復原策略，以在遷移期間發生故障或問題時還原資料庫變更。這可能包括轉返到先前的資料庫狀態或還原個別遷移指令碼。
+ 設定監控和記錄機制，以追蹤資料庫遷移的進度和狀態。這可協助您快速識別和解決問題。

## 史詩
<a name="set-up-ci-cd-pipeline-for-db-migration-with-terraform-epics"></a>

### 設定您的本機工作站
<a name="set-up-your-local-workstation"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在本機工作站上設定 Git。 | 遵循 Git 文件中的指示，[在本機工作站上安裝和設定 Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)。 | DevOps 工程師 | 
| 建立專案資料夾，並從 GitHub 儲存庫新增檔案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-ci-cd-pipeline-for-db-migration-with-terraform.html) | DevOps 工程師 | 

### 佈建目標架構
<a name="provision-the-target-architecture"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 更新必要的參數。 | `ssm-parameters.sh` 檔案會存放所有必要 AWS Systems Manager 的參數。您可以使用專案的自訂值來設定這些參數。在本機工作站的 `setup/db-ssm-params` 資料夾中，開啟 `ssm-parameters.sh` 檔案並設定這些參數，再執行 CI/CD 管道。 | DevOps 工程師 | 
| 初始化 Terraform 組態。 | 在 `db-cicd-integration`資料夾中，輸入下列命令來初始化包含 Terraform 組態檔案的工作目錄：<pre>terraform init</pre> | DevOps 工程師 | 
| 預覽 Terraform 計劃。 | 若要建立 Terraform 計劃，請輸入下列命令：<pre>terraform plan -var-file="terraform.sample"  </pre>Terraform 會評估組態檔案，以判斷宣告資源的目標狀態。然後，它會比較目標狀態與目前狀態，並建立計劃。 | DevOps 工程師 | 
| 驗證計劃。 | 檢閱計劃並確認其已在您的目標中設定所需的架構 AWS 帳戶。 | DevOps 工程師 | 
| 部署解決方案。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-ci-cd-pipeline-for-db-migration-with-terraform.html) | DevOps 工程師 | 

### 驗證部署
<a name="verify-the-deployment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 驗證部署。 | 驗證`db-cicd-integration`管道的狀態，以確認資料庫遷移已完成。1. 登入 AWS 管理主控台，然後開啟 [AWS CodePipeline 主控台](https://console.aws.amazon.com/codesuite/codepipeline/home)。2. 在導覽窗格中，選擇**管道**。3. 選擇`db-cicd-integration`管道。4. 驗證管道執行是否成功完成。 | DevOps 工程師 | 

### 使用後清除基礎設施
<a name="clean-up-infrastructure-after-use"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 清除基礎設施。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/set-up-ci-cd-pipeline-for-db-migration-with-terraform.html) | DevOps 工程師 | 

## 相關資源
<a name="set-up-ci-cd-pipeline-for-db-migration-with-terraform-resources"></a>

**AWS 文件**
+ [Terraform 產品入門](https://docs.aws.amazon.com/servicecatalog/latest/adminguide/getstarted-Terraform.html)

**Terraform 文件**
+ [Terraform 安裝](https://learn.hashicorp.com/tutorials/terraform/install-cli)
+ [Terraform 後端組態](https://developer.hashicorp.com/terraform/language/backend)
+ [Terraform AWS 提供者文件](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)

# 使用 FSx for Windows File Server 在 Amazon EC2 上設定 Microsoft SQL Server 容錯移轉叢集
<a name="microsoft-sql-failover-cluster-on-amazon-ec2"></a>

*Sweta Krishna 和 Ramesh Babu Donti，Amazon Web Services*

## 總結
<a name="microsoft-sql-failover-cluster-on-amazon-ec2-summary"></a>

具有容錯移轉叢集執行個體 (FCI) 的 Microsoft SQL Server Standard 版可以為 SQL Server Enterprise 提供更具成本效益的替代方案。設定 SQL FCI 需要在節點之間共用檔案儲存，Amazon [FSx for Windows File Server](https://aws.amazon.com/fsx/windows/) 提供全受管儲存，可自動跨可用區域同步複寫。Amazon FSx 透過對一般用途檔案共享使用內建的重複資料刪除來降低儲存成本，因此無需維護第三方解決方案。Amazon FSx 也支援下列項目：
+ 只需為您使用的項目付費，無需預付費用或承諾。
+ 使用 FSx 手動設定 FCI 做為共用儲存。
+ 使用 FSx 做為 SQL 叢集的檔案共享見證。
+ Amazon FSx for Windows File Server 支援持續可用的檔案共用的伺服器訊息區塊 (SMB) 3.0，因此適合 SQL Server FCI 部署。

## 先決條件和限制
<a name="microsoft-sql-failover-cluster-on-amazon-ec2-prereqs"></a>

**先決條件**
+ 作用中 [AWS 帳戶](https://aws.amazon.com/account/)。
+ 建立和管理 Amazon Virtual Private Cloud (Amazon VPC) 資源、Amazon Elastic Compute Cloud (Amazon EC2) 執行個體、安全群組和 AWS Identity and Access Management (IAM) 角色的許可。
+ AWS Managed Microsoft AD 或您自己的內部部署 Active Directory。
+ 具備設定容錯移轉叢集[必要許可](https://learn.microsoft.com/en-us/windows-server/failover-clustering/configure-failover-cluster-accounts)的 Active Directory 網域使用者。
+ SQL Server FCI 和 [Microsoft Active Directory 連接埠](https://docs.aws.amazon.com/whitepapers/latest/access-workspaces-with-access-cards/ip-address-and-port-requirements.html)的安全群組規則，用於安全混合連線。
+ Active Directory for SQL Server 中的[服務帳戶](https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/configure-windows-service-accounts-and-permissions?view=sql-server-ver16#sql-server-failover-cluster-instance)，已跨 SQL 節點設定適當的許可。
+ 容錯移轉叢集中的 Amazon FSx for Windows File Server。
+ SQL Server 安裝二進位檔。

**限制**
+ 有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額頁面](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)，然後選擇服務的連結。

**產品版本**
+ Amazon EC2 for Windows Server 2012 R2 或更新版本
+ 具有所有目前 Windows Server 版本的 Amazon FSx for Windows File Server
+ Amazon FSx for NetApp ONTAP 作為共用儲存的替代方案
+ SQL Server 2012/2016/2019/2022

## Architecture
<a name="microsoft-sql-failover-cluster-on-amazon-ec2-architecture"></a>

**技術堆疊**
+ Amazon EC2
+ Amazon FSx for Windows File Server
+ Amazon VPC
+ AWS Directory Service
+ AWS Systems Manager
+ IAM

**目標架構**

下圖顯示使用 Amazon FSx for Windows File Server 在 Amazon EC2 上 Microsoft SQL Server FCI 的高階架構。 FSx 

![\[使用 Amazon FSx for Windows File Server 的 Amazon EC2 上的 Microsoft Server FCI 架構圖。 FSx\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/208bf64a-8fef-4019-944a-723372450885/images/ba0c9169-9536-41c3-ae8e-7264dcc3e1ad.png)


**網路基礎設施**
+ Amazon VPC 提供跨越三個可用區域的網路容器。
+ 私有子網路在每個可用區域中提供隔離的子網路，以部署資源。

**運算層**
+ Amazon EC2 包含 SQL Server 叢集節點 1，部署在可用區域 1 中，做為 Windows Server 容錯移轉叢集 (WSFC) 的一部分。
+ Amazon EC2 包含 SQL Server 叢集節點 2，部署在可用區域 2 中做為 WSFC 的一部分。
+ WSFC 叢集會連接兩個 SQL Server 節點以進行容錯移轉功能。

**Amazon FSx for Windows File Server 的儲存層**

**異地同步備份 FSx 部署 （跨越可用區域 1 和 2)**
+ 可用區域 1 中的主要 FSx 檔案系統託管作用中的 SQL Server 資料和日誌檔案。
+ 可用區域 2 中的次要 FSx 檔案系統提供自動容錯移轉功能。
+ 共用 SMB 檔案共用 (\$1\$1fsx.domain\$1sqlshare)，可供 SQL Server 資料庫的兩個叢集節點存取。

**單一可用區 FSx 部署 （在 AZ3 中）**
+ 可用區域 3 中的 Amazon FSx 檔案伺服器見證充當叢集仲裁見證。
+ 檔案共享見證 (`\\fsx.domain\witness`) 會維護叢集仲裁，並防止大腦分割案例。

**目錄服務**
+ AWS Managed Microsoft AD 提供叢集功能所需的 Windows 身分驗證和網域服務。

**高可用性功能**
+ 多可用區域元件提供跨可用區域的容錯能力。
+ 如果主要伺服器故障，FSx 待命檔案伺服器會提供自動容錯移轉。
+ 檔案共享見證會在可用區域 3 中提供叢集仲裁管理，以協助確保在故障期間執行適當的叢集操作。
+ 網域已與 整合 AWS Managed Microsoft AD ，以進行無縫 Windows 身分驗證。

## 工具
<a name="microsoft-sql-failover-cluster-on-amazon-ec2-tools"></a>

**AWS 服務**
+ [Amazon Elastic Compute Cloud (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 在 AWS 雲端中提供可擴展的運算容量。您可以視需要啟動任意數量的虛擬伺服器，，並快速進行擴展或縮減。
+ [Amazon FSx](https://docs.aws.amazon.com/fsx/?id=docs_gateway) 提供檔案系統，可支援業界標準的連線通訊協定，並提供高可用性和跨的複寫功能 AWS 區域。
+ [Amazon Virtual Private Cloud (Amazon VPC)](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html) 可協助您在已定義的虛擬網路中啟動 AWS 資源。此虛擬網路與您在自己的資料中心中操作的傳統網路相似，且具備使用 AWS可擴展基礎設施的優勢。
+ [AWS Directory Service for Microsoft Active Directory](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/directory_microsoft_ad.html) 可讓您的目錄感知工作負載 AWS 和資源在 中使用 Microsoft Active Directory AWS 雲端。
+ [AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 透過控制已驗證並獲授權使用的人員，協助您安全地管理對 AWS 資源的存取。
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) 可協助您管理在 中執行的應用程式和基礎設施 AWS 雲端。它可簡化應用程式和資源管理、縮短偵測和解決操作問題的時間，並協助您大規模安全地管理 AWS 資源。

## 最佳實務
<a name="microsoft-sql-failover-cluster-on-amazon-ec2-best-practices"></a>
+ 將資料庫執行個體放在私有子網路中，以防止它們從網際網路公開存取，同時仍允許它們連線到 AWS 服務 並執行更新。
+ 如需一般最佳實務，請參閱在 [Amazon EC2 上部署 Microsoft SQL Server 的最佳實務](https://docs.aws.amazon.com/prescriptive-guidance/latest/sql-server-ec2-best-practices/welcome.html)。
+ 若要使用 PowerShell 來管理 Amazon FSx for Windows File Server，請參閱[管理 FSx for Windows 檔案系統](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/administering-file-systems.html)。

## 史詩
<a name="microsoft-sql-failover-cluster-on-amazon-ec2-epics"></a>

### 建立和設定 SQL Server 的 Amazon EC2 節點
<a name="create-and-configure-ec2-nodes-for-sql-server"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 新增名稱和標籤。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html) | DBA | 
| 選擇 Windows AMI。 | 選擇符合 SQL Server 需求的 Amazon Machine Image (AMI) for Windows。 | DBA | 
| 選取執行個體類型。 | 選取符合您需求的 Amazon EC2 執行個體類型。 | DBA | 
| 使用金鑰對。 | 您可以使用金鑰對安全地連線至執行個體。在啟動執行個體之前，請確定您能夠存取選取的金鑰對。 | DBA | 
| 設定網路設定。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html) | DBA | 
| 設定進階網路設定。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html) | DBA | 
| 設定儲存體。 | 設定所需的總儲存體，然後選擇所需的儲存體類型。 | DBA | 
| 設定進階詳細資訊並啟動執行個體。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html) | DBA | 
| 建立節點 2。 | 重複這些步驟來建立和設定節點 2。 | DBA | 

### 在節點 1 和 2 上安裝和設定 Windows Server 容錯移轉叢集
<a name="install-and-configure-windows-server-failover-cluster-on-nodes-1-and-2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 登入節點 1。 | 以管理員身分登入 Windows Amazon EC2 執行個體。 | DBA | 
| 在節點 1 上安裝 FCI 功能。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html)<pre>Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools</pre>[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html) | DBA | 
| 登入節點 2。 | 以管理員身分登入 Windows Amazon EC2 執行個體。 | DBA | 
| 在節點 2 上安裝 FCI 功能。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html)<pre>Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools</pre>[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html) | DBA | 
| 將節點新增至叢集。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html) | DBA | 
| 讓叢集上線。 | 若要讓叢集上線，請更新兩個節點的靜態 IP 地址：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html) | DBA | 
| 驗證叢集。 | 導覽至**容錯移轉叢集管理員**，並確認叢集核心資源在線上。 | DBA | 

### 在節點 1 和 2 上安裝 SQL Server
<a name="install-sql-server-on-nodes-1-and-2"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 登入 伺服器。 | 以管理員身分登入 Amazon EC2 執行個體。 | DBA | 
| 掛載 SQL 二進位檔。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html) |  | 
| 將節點 2 新增至容錯移轉叢集。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html) | DBA | 

### 設定 Amazon FSx 檔案共享見證
<a name="configure-the-fsx-file-share-witness"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定規定人數設定。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/microsoft-sql-failover-cluster-on-amazon-ec2.html) | DBA | 
| 擷取 DNS 詳細資訊。 | 在 Amazon FSx 主控台中，選擇 **Managed AD**，然後選擇**連接**。DNS 應該具有下列格式： `\\example.example.net\share` | DBA | 
| 設定檔案共享見證。 | 選擇 **Amazon FSx 檔案共用路徑**，然後選擇**完成**。 | DBA | 

## 相關資源
<a name="microsoft-sql-failover-cluster-on-amazon-ec2-resources"></a>

**AWS resources**
+ [Amazon FSx for Windows File Server](https://www.youtube.com/watch?v=IMDWTIShlyI) （影片）
+ [深入了解 Amazon FSx for Windows File Server](https://www.youtube.com/watch?v=_x_Geur93oc) （影片）
+ [如何在 Windows Server 上使用 Amazon EBS Multi-Attach 部署 SQL Server 容錯移轉叢集](https://aws.amazon.com/blogs/modernizing-with-aws/how-to-deploy-a-sql-server-failover-cluster-with-amazon-ebs-multi-attach-on-windows-server/) (AWS 部落格文章）
+ [使用 Amazon FSx for Windows File Server 簡化 Microsoft SQL Server 高可用性部署](https://aws.amazon.com/blogs/storage/simplify-your-microsoft-sql-server-high-availability-deployments-using-amazon-fsx-for-windows-file-server/) (AWS 部落格文章）
+ [使用 Amazon FSx for NetApp ONTAP 的 SQL Server 高可用性部署](https://aws.amazon.com/blogs/modernizing-with-aws/sql-server-high-availability-amazon-fsx-for-netapp-ontap/) (AWS 部落格文章）
+ [搭配 Microsoft SQL Server 使用 FSx for Windows File Server](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/sql-server.html)
+ [什麼是 FSx for Windows File Server？](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/what-is.html)

**其他資源**
+ [建立容錯移轉叢集](https://learn.microsoft.com/en-us/windows-server/failover-clustering/create-failover-cluster?pivots=windows-admin-center)

## 其他資訊
<a name="microsoft-sql-failover-cluster-on-amazon-ec2-additional"></a>

**設定檔案共享見證**

透過在允許傳入連線的 Amazon FSx 安全群組中新增規則，確保您從兩個節點連線到檔案系統。應允許 SMB 連接埠。例如，如果 DNS 名稱為 `\\example.example.com\share`，請使用 `\\example.example.com\share`。對 Always On 可用性叢集中的檔案共享見證使用相同的值。完成下列步驟以設定檔案共享見證：

1. 使用 RDP 連線到您的 Amazon EC2 執行個體。

1. 導覽至**容錯移轉叢集管理員**。

1. 開啟內容 （按一下滑鼠右鍵） 選單，然後選擇**更多動作**。

1. 選擇**設定叢集規定人數設定**。

1. 選擇**下一步**。

1. 選取**配額組態**並設定檔案共享見證。

1. 提供 DNS 名稱。

1. 檢閱摘要，然後選擇**完成**。檔案共享見證應該在線上的**叢集核心**資源區段中。

# 使用作用中待命資料庫為 Amazon RDS Custom 上的 Oracle 電子商務套件設定 HA/DR 架構
<a name="set-up-an-ha-dr-architecture-for-oracle-e-business-suite-on-amazon-rds-custom-with-an-active-standby-database"></a>

*Simon Cunningham、Jaydeep Nandy 和 Nitin Saxena，Amazon Web Services*

## 總結
<a name="set-up-an-ha-dr-architecture-for-oracle-e-business-suite-on-amazon-rds-custom-with-an-active-standby-database-summary"></a>

此模式說明如何在 Amazon Relational Database Service (Amazon RDS) Custom 上架構 Oracle E-Business 解決方案，以便在另一個 Amazon Web Services (AWS) 可用區域中設定 Amazon RDS Custom 僅供讀取複本資料庫，並將其轉換為作用中待命資料庫，以獲得高可用性 (HA) 和災難復原 (DR)。Amazon RDS Custom 僅供讀取複本的建立是透過 AWS 管理主控台完全自動化。

此模式不會討論新增其他應用程式層和共用檔案系統的步驟，這也可能是 HA/DR 架構的一部分。如需這些主題的詳細資訊，請參閱下列 Oracle 支援備註：1375769.1、1375670.1 和 1383621.1 （第 5 節，*進階複製選項*)。（存取需要 [Oracle Support](https://support.oracle.com/portal/) 帳戶。)

若要將 E-Business Suite 系統遷移至 Amazon Web Services (AWS) 上的單一層級單一可用區架構，請參閱將 [Oracle E-Business Suite 遷移至 Amazon RDS Custom](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-oracle-e-business-suite-to-amazon-rds-custom.html) 模式。

Oracle E-Business Suite 是一種企業資源規劃 (ERP) 解決方案，可自動化整個企業的流程，例如財務、人力資源、供應鏈和製造。它具有三層架構：用戶端、應用程式和資料庫。先前，您必須在自我管理的 [Amazon Elastic Compute Cloud (Amazon EC2) 執行個體上執行 E-Business Suite 資料庫，](https://aws.amazon.com/ec2/)但您現在可以受益於 [Amazon RDS Custom](https://aws.amazon.com/rds/custom/)。 

## 先決條件和限制
<a name="set-up-an-ha-dr-architecture-for-oracle-e-business-suite-on-amazon-rds-custom-with-an-active-standby-database-prereqs"></a>

**先決條件**
+ Amazon RDS Custom 上現有的 E-Business Suite 安裝；請參閱將 [Oracle E-Business Suite 遷移至 Amazon RDS Custom](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-oracle-e-business-suite-to-amazon-rds-custom.html) 的模式
+ 如果您想要將僅供讀取複本變更為唯讀，並使用它將報告卸載至待命，則為 [Oracle Active Data Guard 資料庫授權](https://www.oracle.com/corporate/pricing/) （請參閱 *Oracle Technology 商業價目表*)

**限制**
+ [Amazon RDS Custom 上 Oracle 資料庫](https://docs.amazonaws.cn/en_us/AmazonRDS/latest/UserGuide/custom-reqs-limits.html#custom-reqs-limits.limits)的限制和不支援的組態
+ 與 [Amazon RDS Custom for Oracle 僅供讀取複本](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-rr.html#custom-rr.limitations)相關聯的限制

**產品版本**

對於 Amazon RDS Custom 支援的 Oracle 資料庫版本和執行個體類別，請參閱 [Amazon RDS Custom for Oracle 的要求和限制](https://docs.amazonaws.cn/en_us/AmazonRDS/latest/UserGuide/custom-reqs-limits.html)。

## Architecture
<a name="set-up-an-ha-dr-architecture-for-oracle-e-business-suite-on-amazon-rds-custom-with-an-active-standby-database-architecture"></a>

下圖說明 AWS 上 E-Business Suite 的代表性架構，其中包含作用中/被動設定中的多個可用區域和應用程式層。資料庫使用 Amazon RDS Custom 資料庫執行個體和 Amazon RDS Custom 僅供讀取複本。僅供讀取複本使用 Active Data Guard 複寫到另一個可用區域。您也可以使用僅供讀取複本卸載主要資料庫上的讀取流量，並用於報告目的。

![\[AWS 上適用於 Oracle E-Business Suite 的異地同步備份架構\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/a17947e8-56b1-4d92-91df-096c02ff4c19/images/ffdaa2d4-123b-44a0-8d52-b1352a4eee44.png)


如需詳細資訊，請參閱《[Amazon RDS 文件》中的使用 Amazon RDS Custom for Oracle 的僅供讀取複本](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-rr.html)。 

根據預設，Amazon RDS Custom 僅供讀取複本會建立為掛載。不過，如果您想要將部分唯讀工作負載卸載至待命資料庫，以減少主要資料庫的負載，您可以依照 [Epics](#set-up-an-ha-dr-architecture-for-oracle-e-business-suite-on-amazon-rds-custom-with-an-active-standby-database-epics) 區段中的步驟，手動將掛載複本的模式變更為唯讀。典型的使用案例是從待命資料庫執行您的報告。變更為唯讀需要作用中的待命資料庫授權。 

當您在 AWS 上建立僅供讀取複本時，系統會在封面下使用 Oracle Data Guard 代理程式。 此組態會自動產生並在最高效能模式中設定，如下所示：

```
DGMGRL> show configuration
Configuration - rds_dg
  Protection Mode: MaxPerformance
  Members:
  vis_a - Primary database
    vis_b - Physical standby database 
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS   (status updated 58 seconds ago)
```

## 工具
<a name="set-up-an-ha-dr-architecture-for-oracle-e-business-suite-on-amazon-rds-custom-with-an-active-standby-database-tools"></a>

**AWS 服務**
+ [Amazon RDS Custom for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/working-with-custom-oracle.html) 是一種受管資料庫服務，適用於需要存取基礎作業系統和資料庫環境的舊版、自訂和封裝應用程式。它可自動化資料庫管理任務和操作，同時讓身為資料庫管理員的您能夠存取和自訂資料庫環境和作業系統。 

**其他工具**
+ Oracle Data Guard 是一種工具，可協助您建立和管理 Oracle 待命資料庫。此模式使用 Oracle Data Guard 在 Amazon RDS Custom 上設定作用中待命資料庫。

## 史詩
<a name="set-up-an-ha-dr-architecture-for-oracle-e-business-suite-on-amazon-rds-custom-with-an-active-standby-database-epics"></a>

### 建立僅供讀取複本
<a name="create-a-read-replica"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon RDS Custom 資料庫執行個體的僅供讀取複本。 | 若要建立僅供讀取複本，請遵循 [Amazon RDS 文件](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html#USER_ReadRepl.Create)中的指示，並使用您建立的 Amazon RDS Custom 資料庫執行個體 （請參閱[先決條件](#set-up-an-ha-dr-architecture-for-oracle-e-business-suite-on-amazon-rds-custom-with-an-active-standby-database-prereqs)一節） 做為來源資料庫。根據預設，Amazon RDS Custom 僅供讀取複本會建立為實體待命，且處於掛載狀態。這是為了確保符合 Oracle Active Data Guard 授權。請依照下列步驟，將僅供讀取複本轉換為唯讀模式。 | DBA | 

### 將僅供讀取複本變更為唯讀作用中待命
<a name="change-the-read-replica-to-a-read-only-active-standby"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 連線至 Amazon RDS Custom 僅供讀取複本。 | 使用以下命令將實體待命資料庫轉換為作用中待命資料庫。 這些命令需要 Oracle 作用中待命授權。若要取得授權，請聯絡您的 Oracle 代表。<pre>$ sudo su - rdsdb<br />-bash-4.2$ sql<br />SQL> select process,status,sequence# from v$managed_standby;<br /><br />PROCESS    STATUS        SEQUENCE#<br />--------- ------------ ----------<br />ARCH       CLOSING            3956<br />ARCH       CONNECTED             0<br />ARCH       CLOSING            3955<br />ARCH       CLOSING            3957<br />RFS        IDLE                  0<br />RFS        IDLE               3958<br />MRP0       APPLYING_LOG       3958<br />SQL> select name, database_role, open_mode from v$database;<br /><br />NAME       DATABASE_ROLE    OPEN_MODE<br />--------- ---------------- --------------------<br />VIS        PHYSICAL STANDBY MOUNTED<br />SQL> alter database recover managed standby database cancel;<br />Database altered.<br />Open the standby database<br />SQL> alter database open;<br />Database altered.<br />SQL> select name, database_role, open_mode from v$database;<br /><br />NAME       DATABASE_ROLE    OPEN_MODE<br />--------- ---------------- --------------------<br />VIS        PHYSICAL STANDBY READ ONLY</pre> | DBA | 
| 使用即時日誌啟動媒體復原。 | 若要啟用即時日誌套用功能，請使用下列命令。這些轉換和驗證待命 （僅供讀取複本） 為作用中待命資料庫，因此您可以連接和執行唯讀查詢。<pre>SQL>   alter database recover managed standby database using current logfile disconnect from session;<br />Database altered</pre> | DBA | 
| 檢查資料庫狀態。 | 若要檢查資料庫的狀態，請使用下列命令。<pre>SQL> select name, database_role, open_mode from v$database;<br />NAME      DATABASE_ROLE    OPEN_MODE<br />--------- ---------------- --------------------<br />VIS       PHYSICAL STANDBY READ ONLY WITH APPLY</pre> | DBA | 
| 檢查重做套用模式。 | 若要檢查重做套用模式，請使用下列命令。<pre>SQL> select process,status,sequence# from v$managed_standby;<br />PROCESS    STATUS        SEQUENCE#<br />--------- ------------ ----------<br />ARCH       CLOSING            3956<br />ARCH       CONNECTED             0<br />ARCH       CLOSING            3955<br />ARCH       CLOSING            3957<br />RFS        IDLE                  0<br />RFS        IDLE               3958<br />MRP0       APPLYING_LOG       3958<br /> <br />SQL> select open_mode from v$database;<br />OPEN_MODE<br />--------------------<br />READ ONLY WITH APPLY</pre> | DBA | 

## 相關資源
<a name="set-up-an-ha-dr-architecture-for-oracle-e-business-suite-on-amazon-rds-custom-with-an-active-standby-database-resources"></a>
+ [將 Oracle 電子商務套件遷移至 Amazon RDS Custom](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-oracle-e-business-suite-to-amazon-rds-custom.html) (AWS 方案指引）
+ [使用 Amazon RDS Custom](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-custom.html) (Amazon RDS 文件）
+ [使用 Amazon RDS Custom for Oracle 的僅供讀取複本](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-rr.html) (Amazon RDS 文件）
+ [Amazon RDS Custom for Oracle – 資料庫環境中的新控制功能 ](https://aws.amazon.com/blogs/aws/amazon-rds-custom-for-oracle-new-control-capabilities-in-database-environment/)(AWS 新聞部落格）
+ [在 AWS 上遷移 Oracle 電子商務套件](https://d1.awsstatic.com/whitepapers/migrate-oracle-e-business-suite.pdf) (AWS 白皮書）
+ [AWS 上的 Oracle E-Business Suite 架構](https://docs.aws.amazon.com/whitepapers/latest/overview-oracle-e-business-suite/oracle-e-business-suite-architecture-on-aws.html) (AWS 白皮書）

# 在 上將資料從 IBM Db2、SAP、Sybase 和其他資料庫串流至 MongoDB Atlas AWS
<a name="stream-data-from-ibm-db2-to-mongodb-atlas"></a>

*Battulga Purevragchaa 和 Igor Alekseev，Amazon Web Services*

*Babu Srinivasan，MongoDB*

## 摘要
<a name="stream-data-from-ibm-db2-to-mongodb-atlas-summary"></a>

此模式說明將資料從 IBM Db2 和其他資料庫遷移至 上的 MongoDB Atlas 的步驟，例如大型主機資料庫和 Sybase AWS 雲端。它使用 [AWS Glue](https://aws.amazon.com/glue/) 來協助加速資料遷移至 MongoDB Atlas。

模式隨附於 上的[遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/) 指南，請參閱 AWS 方案指引網站。它提供該指南中討論的其中一個遷移案例的實作步驟。如需其他遷移案例，請參閱 AWS 規範指引網站上的下列模式：
+ [在 上將自我託管的 MongoDB 環境遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-a-self-hosted-mongodb-environment-to-mongodb-atlas-on-the-aws-cloud.html)
+ [在 上將關聯式資料庫遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/migrate-relational-database-to-mongodb-atlas.html)

模式 適用於 [AWS Managed Services 合作夥伴](https://aws.amazon.com/managed-services/partners/)和 AWS 使用者。

## 先決條件和限制
<a name="stream-data-from-ibm-db2-to-mongodb-atlas-prereqs"></a>

**先決條件**
+ 要遷移至 MongoDB Atlas 的來源資料庫，例如 SAP、Sybase、IBM Db2 等。
+ 熟悉 SAP、Sybase、IBM Db2、MongoDB Atlas 和 等資料庫 AWS 服務。

**產品版本**
+ MongoDB 5.0 版或更新版本。

## Architecture
<a name="stream-data-from-ibm-db2-to-mongodb-atlas-architecture"></a>

下圖說明使用 AWS Glue Studio、Amazon Kinesis Data Streams 和 MongoDB Atlas 的批次資料載入和資料串流。

此參考架構使用 AWS Glue Studio 建立擷取、轉換和載入 (ETL) 管道，將資料遷移至 MongoDB Atlas。與 MongoDB Atlas AWS Glue 編目程式 整合，以促進資料控管。資料可以使用 Amazon Kinesis Data Streams 批次移植或串流至 MongoDB Atlas。

**批次資料載入**

![\[以批次模式將資料遷移至 MongoDB Atlas。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/805a376f-35f4-44cc-b4b0-8bf4d95c1e5d/images/68d87202-95ba-4e2a-9b3b-27dd6db6165e.png)


如需批次資料遷移的詳細資訊，請參閱 AWS 部落格文章[使用 編寫 MongoDB Atlas 的 ETL 任務 AWS Glue](https://aws.amazon.com/blogs/big-data/compose-your-etl-jobs-for-mongodb-atlas-with-aws-glue/)。

**資料串流**

![\[在資料串流模式下將資料遷移至 MongoDB Atlas。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/805a376f-35f4-44cc-b4b0-8bf4d95c1e5d/images/b007a116-f463-418f-9721-647d80177e3b.png)


如需支援不同使用案例的 MongoDB Atlas 參考架構，請參閱 AWS Prescriptive Guidance 網站上的[遷移至 上的 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/architecture.html)。

## 工具
<a name="stream-data-from-ibm-db2-to-mongodb-atlas-tools"></a>

●  [AWS Glue](https://docs.aws.amazon.com/glue/latest/dg/what-is-glue.html) 是全受管 ETL 服務。它可協助您可靠地分類、清理、擴充和移動資料存放區和資料串流之間的資料。

●  [Amazon Kinesis Data Streams](https://aws.amazon.com/kinesis/data-streams/) 可協助您即時收集和處理大型資料記錄串流。

●  [MongoDB Atlas](https://www.mongodb.com/atlas) 是全受管資料庫即服務 (DbaaS)，用於在雲端中部署和管理 MongoDB 資料庫。

## 最佳實務
<a name="stream-data-from-ibm-db2-to-mongodb-atlas-best-practices"></a>

如需指導方針，請參閱 [ MongoDB GitHub 儲存庫中的 MongoDB 最佳實務指南](https://github.com/mongodb-partners/mongodb_atlas_as_aws_bedrock_knowledge_base/blob/main/data/MongoDB_Best_Practices_Guide.pdf)。 MongoDB GitHub 

## 史詩
<a name="stream-data-from-ibm-db2-to-mongodb-atlas-epics"></a>

### 探索和評估
<a name="discovery-and-assessment"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 決定叢集大小。 | 使用來自 的資訊估計工作集大小`db.stats()`，以取得總索引空間。假設經常存取您資料空間的百分比。或者，您可以根據您的假設預估記憶體需求。此任務大約需要一週的時間。如需此範例和其他案例的詳細資訊和範例，請參閱[相關資源](#stream-data-from-ibm-db2-to-mongodb-atlas-resources)區段中的連結。 | MongoDB DBA，應用程式架構師 | 
| 估計網路頻寬需求。 | 若要估算您的網路頻寬需求，請將平均文件大小乘以每秒提供的文件數量。請考慮叢集上任何節點所承擔的最大流量。若要計算從叢集到用戶端應用程式的下游資料傳輸率，請使用一段時間內傳回文件總數的總和。如果您的應用程式從次要節點讀取，請將總文件數除以可提供讀取操作的節點數。若要尋找資料庫的平均文件大小，請使用 `db.stats().avgObjSize`命令。此任務通常需要一天的時間。 | MongoDB DBA | 
| 選取 Atlas 層。 | 遵循 [MongoDB 文件](https://www.mongodb.com/docs/atlas/manage-clusters/)中的指示，選取正確的 Atlas 叢集層。  | MongoDB DBA | 
| 規劃切換。 | 規劃應用程式切換。 | MongoDB DBA，應用程式架構師 | 

### 在 AWS 上設定新的 MongoDB Atlas 環境
<a name="set-up-a-new-mongodb-atlas-environment-on-aws"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 上建立新的 MongoDB Atlas 叢集 AWS。 | 在 MongoDB Atlas 中，選擇**建置叢集**，然後選取 AWS 做為雲端供應商。 | MongoDB DBA | 
| 選取 AWS 區域 和 全域叢集組態。 | 從 AWS 區域 Atlas 叢集可用的 清單中選取 。視需要設定全域叢集。 | MongoDB DBA | 
| 選取叢集層。 | 選取您偏好的叢集層。您的方案選擇會決定記憶體、儲存體和 IOPS 規格等因素。 | MongoDB DBA | 
| 設定其他叢集設定。 | 設定其他叢集設定，例如 MongoDB 版本、備份和加密選項。如需這些選項的詳細資訊，請參閱[相關資源](#stream-data-from-ibm-db2-to-mongodb-atlas-resources)一節。 | MongoDB DBA | 

### 設定安全與合規
<a name="configure-security-and-compliance"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定存取清單。 | 若要連線至 Atlas 叢集，您必須將項目新增至[專案的存取清單](https://www.mongodb.com/docs/atlas/setup-cluster-security/#configure-security-features-for-clusters)。Atlas 使用 Transport Layer Security (TLS) / Secure Sockets Layer (SSL) 來加密資料庫虛擬私有雲端 (VPC) 的連線。若要設定專案的存取清單，以及有關此史詩中案例的詳細資訊，請參閱[相關資源](#stream-data-from-ibm-db2-to-mongodb-atlas-resources)區段中的連結。  | MongoDB DBA | 
| 驗證和授權使用者。 | 您必須建立和驗證將存取 MongoDB Atlas 叢集的資料庫使用者。若要存取專案中的叢集，使用者必須屬於該專案，而且可以屬於多個專案。 您也可以使用 AWS Identity and Access Management (IAM) 啟用授權。如需詳細資訊，請參閱 MongoDB 文件中的[使用 IAM 設定身分驗證](https://www.mongodb.com/docs/atlas/security/aws-iam-authentication/#set-up-authentication-with-aws-iam)。 | MongoDB DBA | 
| 建立自訂角色。 | （選用） 如果內建的 Atlas 資料庫使用者權限未涵蓋您所需的權限集，則 Atlas 支援建立[自訂角色](https://www.mongodb.com/docs/atlas/reference/custom-role-actions/)。 | MongoDB DBA | 
| 設定 VPC 對等互連。 | （選用） Atlas 支援 [VPC 與其他 AWS VPC 對等互連](https://www.mongodb.com/docs/atlas/security-vpc-peering/#set-up-a-network-peering-connection)。 VPCs | MongoDB DBA | 
| 設定 AWS PrivateLink 端點。 | （選用） 您可以使用 AWS 在 上設定私有端點[AWS PrivateLink](https://www.mongodb.com/docs/atlas/security-private-endpoint/)。 | MongoDB DBA | 
| 啟用雙重驗證。 | （選用） Atlas 支援雙重驗證 (2FA)，以協助使用者控制對其 Atlas 帳戶的存取。 | MongoDB DBA | 
| 使用 LDAP 設定使用者身分驗證和授權。 | （選用） Atlas 支援使用輕量型目錄存取通訊協定 (LDAP) 執行使用者身分驗證和授權。 | MongoDB DBA | 
| 設定統一 AWS 存取。 | （選用） 某些 Atlas 功能，包括使用客戶金鑰管理的 Atlas Data Lake 和靜態加密，請使用 IAM 角色進行身分驗證。 | MongoDB DBA | 
| 使用 設定靜態加密 AWS KMS。 | （選用） Atlas 支援使用 AWS Key Management Service (AWS KMS) 加密儲存引擎和雲端供應商備份。 | MongoDB DBA | 
| 設定 CSFLE。 | （選用） Atlas [支援用戶端欄位層級加密 (CSFLE)](https://www.mongodb.com/docs/upcoming/core/csfle/#client-side-field-level-encryption)，包括欄位的自動加密。  | MongoDB DBA | 

### 遷移資料
<a name="migrate-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 MongoDB Atlas 中啟動您的目標複本集。 | 在 MongoDB Atlas 中啟動您的目標複本集。在 Atlas Live Migration Service 中，選擇**我已準備好遷移**。 | MongoDB DBA | 
| 建立 AWS Glue 與 MongoDB Atlas 的連線。 | 使用 AWS Glue 編目程式 與 MongoDB Atlas （目標資料庫） AWS Glue 連線。此步驟有助於準備目標環境以進行遷移。如需詳細資訊，請參閱 [AWS Glue 文件](https://docs.aws.amazon.com/glue/latest/dg/console-connections.html)。 | MongoDB DBA | 
| 建立 AWS Glue 與來源資料庫或來源串流的連線。 | 這有助於準備目標環境以進行遷移。 | MongoDB DBA | 
| 設定資料轉換。 | 設定轉換邏輯，將資料從舊版結構化結構描述遷移至 MongoDB 的彈性結構描述。 | MongoDB DBA | 
| 遷移資料。 | 排程 中的遷移 AWS Glue Studio。 | MongoDB DBA | 

### 設定操作整合
<a name="configure-operational-integration"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 連線至叢集。 | 連線至 MongoDB Atlas 叢集。 | 應用程式開發人員 | 
| 與資料互動。 | 與叢集資料互動。 | 應用程式開發人員 | 
| 監控叢集。 | 監控您的 MongoDB Atlas 叢集。 | MongoDB DBA | 
| 備份和還原資料。 | 備份和還原叢集資料。 | MongoDB DBA | 

## 疑難排解
<a name="stream-data-from-ibm-db2-to-mongodb-atlas-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 如果您遇到問題 | 請參閱 MongoDB Atlas CloudFormation 資源儲存庫中的[故障診斷](https://github.com/mongodb/mongodbatlas-cloudformation-resources/tree/master#troubleshooting)。 | 

## 相關資源
<a name="stream-data-from-ibm-db2-to-mongodb-atlas-resources"></a>

除非另有說明，否則下列所有連結都會移至 MongoDB 文件中的網頁。

**遷移指南**
+ [在 上遷移至 MongoDB Atlas AWS](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-mongodb-atlas/) (AWS 方案指引）

**探索和評估**
+ [記憶體](https://docs.atlas.mongodb.com/sizing-tier-selection/#memory)
+ [使用 Atlas 範例資料集調整大小範例](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#example--the-service-sample-data-sets)
+ [行動應用程式的大小調整範例](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#example--mobile-app)
+ [網路流量](https://docs.atlas.mongodb.com/sizing-tier-selection/#network-traffic)
+ [叢集自動擴展](https://www.mongodb.com/docs/atlas/sizing-tier-selection/#cluster-auto-scaling)
+ [Atlas 大小調整範本](https://view.highspot.com/viewer/5f438f47a4dfa042e97130c5)

**設定安全與合規**
+ [設定 IP 存取清單項目](https://docs.atlas.mongodb.com/security/ip-access-list/)
+ [設定資料庫使用者](https://docs.atlas.mongodb.com/security-add-mongodb-users/)
+ [設定對 Atlas UI 的存取](https://docs.atlas.mongodb.com/organizations-projects/)
+ [設定自訂資料庫角色](https://docs.atlas.mongodb.com/security-add-mongodb-roles)
+ [設定資料庫使用者](https://docs.atlas.mongodb.com/security-add-mongodb-users/#atlas-user-privileges)
+ [設定網路對等連線](https://docs.atlas.mongodb.com/security-vpc-peering/)
+ [了解 Atlas 中的私有端點](https://docs.atlas.mongodb.com/security-private-endpoint/)
+ [管理您的多重要素驗證選項](https://docs.atlas.mongodb.com/security-two-factor-authentication/)
+ [使用 LDAP 設定使用者身分驗證和授權](https://docs.atlas.mongodb.com/security-ldaps/)
+ [Atlas Data Lake](https://docs.mongodb.com/datalake/)
+ [使用客戶金鑰管理進行靜態加密](https://docs.atlas.mongodb.com/security-kms-encryption/)
+ [擔任角色的方法 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html)(IAM 文件）
+ [用戶端欄位層級加密](https://docs.mongodb.com/manual/core/security-client-side-encryption)
+ [自動加密](https://docs.mongodb.com/manual/core/security-automatic-client-side-encryption) 
+ [MongoDB Atlas 安全控制](https://webassets.mongodb.com/_com_assets/cms/MongoDB_Atlas_Security_Controls-v7k3rbhi3p.pdf)
+ [MongoDB 信任中心](https://www.mongodb.com/cloud/trust)
+ [設定叢集的安全功能](https://docs.atlas.mongodb.com/setup-cluster-security/)

**在 上設定新的 MongoDB Atlas 環境 ****AWS**
+ [雲端供應商和區域](https://docs.atlas.mongodb.com/cloud-providers-regions/)
+ [管理全域叢集](https://docs.atlas.mongodb.com/global-clusters/)
+ [選取叢集層](https://www.mongodb.com/docs/atlas/manage-clusters/#select-cluster-tier)
+ [設定其他設定](https://docs.atlas.mongodb.com/cluster-additional-settings/)
+ [Atlas 入門](https://docs.atlas.mongodb.com/getting-started/)
+ [設定對 Atlas UI 的存取](https://docs.atlas.mongodb.com/organizations-projects/)

**遷移資料**
+ [遷移或匯入資料](https://www.mongodb.com/docs/atlas/import/)

**監控叢集**
+ [監控您的叢集](https://docs.atlas.mongodb.com/monitoring-alerts/)

**整合 操作**
+ [連線至叢集](https://docs.atlas.mongodb.com/connect-to-cluster/)
+ [與您的資料互動](https://docs.atlas.mongodb.com/data-explorer/)
+ [監控您的叢集](https://docs.atlas.mongodb.com/monitoring-alerts/)
+ [備份、還原和封存資料](https://docs.atlas.mongodb.com/backup-restore-cluster/)

**GitHub 儲存庫**
+ [使用 將資料串流至 MongoDB Atlas AWS Glue](https://github.com/mongodb-partners/Stream_Data_into_MongoDB_AWS_Glue?tab=readme-ov-file#troubleshooting)

# Amazon RDS Custom for Oracle 上 Oracle PeopleSoft 應用程式的轉換角色
<a name="transition-roles-for-an-oracle-peoplesoft-application-on-amazon-rds-custom-for-oracle"></a>

*sampath kathirvel，Amazon Web Services*

## 總結
<a name="transition-roles-for-an-oracle-peoplesoft-application-on-amazon-rds-custom-for-oracle-summary"></a>

若要在 Amazon Web Services (AWS) 上執行 [Oracle PeopleSoft](https://www.oracle.com/applications/peoplesoft/) 企業資源規劃 (ERP) 解決方案，您可以使用 [Amazon Relational Database Service (Amazon RDS)](https://aws.amazon.com/rds/) 或 [Amazon RDS Custom for Oracle](https://aws.amazon.com/rds/custom/)，以支援需要存取基礎作業系統 (OS) 和資料庫環境的舊版、自訂和封裝應用程式。如需規劃遷移時要考慮的關鍵因素，請參閱 AWS 方案指引中的 [Oracle 資料庫遷移策略](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-oracle-database/strategies.html)。

此模式著重於為在 Amazon RDS Custom 上執行的 PeopleSoft 應用程式資料庫執行 Oracle Data Guard 切換或角色轉換的步驟，做為具有僅供讀取複本資料庫的主要資料庫。模式包含設定[快速啟動容錯移轉 (FSFO) ](https://docs.oracle.com/en/database/oracle/oracle-database/19/dgbkr/using-data-guard-broker-to-manage-switchovers-failovers.html#GUID-D26D79F2-0093-4C0E-98CD-224A5C8CBFA4)的步驟。在此過程中，Oracle Data Guard 組態中的資料庫會繼續在其新角色中運作。Oracle Data Guard 轉換的典型使用案例包括災難復原 (DR) 演練、資料庫上的排程維護活動，以及[待命優先修補程式套用](https://docs.oracle.com/en/database/oracle/oracle-database/19/sbydb/upgrading-patching-downgrading-oracle-data-guard-configuration.html#GUID-A5226768-DB6B-4714-BB9A-0A3EF17A01C8)滾動修補程式。如需詳細資訊，請參閱部落格文章 [減少 Amazon RDS Custom 中的資料庫修補停機時間](https://aws.amazon.com/blogs/database/reduce-database-patching-downtime-in-amazon-rds-custom-for-oracle-using-oracle-data-guard-standby-first-patch-apply/)。

## 先決條件和限制
<a name="transition-roles-for-an-oracle-peoplesoft-application-on-amazon-rds-custom-for-oracle-prereqs"></a>

**先決條件 **
+ [使用僅供讀取複本模式完成在 Amazon RDS Custom 上將 HA 新增至 Oracle PeopleSoft](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica.html)。

**限制 **
+ [RDS Custom for Oracle](https://docs.amazonaws.cn/en_us/AmazonRDS/latest/UserGuide/custom-reqs-limits.html#custom-reqs-limits.limits) 的限制和不支援的組態
+ 與 [Amazon RDS Custom for Oracle 僅供讀取複本](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-rr.html#custom-rr.limitations)相關聯的限制

**產品版本**
+ 如需 Amazon RDS Custom 支援的 Oracle 資料庫版本，請參閱 [RDS Custom for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RDS_Fea_Regions_DB-eng.Feature.RDSCustom.html#Concepts.RDS_Fea_Regions_DB-eng.Feature.RDSCustom.ora)。
+ 如需 Amazon RDS Custom 支援的 Oracle 資料庫執行個體類別，請參閱 [RDS Custom for Oracle 的資料庫執行個體類別支援](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-reqs-limits.html#custom-reqs-limits.instances)。

## Architecture
<a name="transition-roles-for-an-oracle-peoplesoft-application-on-amazon-rds-custom-for-oracle-architecture"></a>

**技術堆疊**
+ Amazon RDS Custom for Oracle

**目標架構**

下圖顯示 Amazon RDS Custom 資料庫執行個體和 Amazon RDS Custom 僅供讀取複本。Oracle Data Guard 在 DR 的容錯移轉期間提供角色轉換。

![\[具有僅供讀取複本資料庫之主要 RDS Custom 資料庫執行個體的 Oracle Data Guard 切換。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/da3b011c-1668-4de4-9079-0982888a74b4/images/4e2a2f3b-b5bd-44b7-9b5a-13a663ee3be6.png)


如需在 AWS 上使用 Oracle PeopleSoft 的代表性架構，請參閱[在 AWS 上設定高度可用的 PeopleSoft 架構](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/set-up-a-highly-available-peoplesoft-architecture-on-aws.html)。

## 工具
<a name="transition-roles-for-an-oracle-peoplesoft-application-on-amazon-rds-custom-for-oracle-tools"></a>

**AWS 服務**
+ [Amazon RDS Custom for Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/working-with-custom-oracle.html) 是一種受管資料庫服務，適用於需要存取基礎作業系統和資料庫環境的舊版、自訂和封裝應用程式。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您使用以程式設計方式擷取秘密的 API 呼叫取代程式碼中的硬式編碼登入資料，包括密碼。在此模式中，您會從秘密名稱`RDS_DATAGUARD`為 的 Secrets Manager 擷取資料庫使用者密碼`do-not-delete-rds-custom-+<<RDS Resource ID>>+-dg`。

**其他服務**
+ [Oracle Data Guard](https://docs.oracle.com/en/database/oracle/oracle-database/21/sbydb/introduction-to-oracle-data-guard-concepts.html#GUID-5E73667D-4A56-445E-911F-1E99092DD8D7) 可協助您建立、維護、管理和監控待命資料庫。此模式使用 Oracle Data Guard 最高效能來轉換角色 ([Oracle Data Guard 切換](https://docs.oracle.com/database/121/DGBKR/sofo.htm#DGBKR330))。

## 最佳實務
<a name="transition-roles-for-an-oracle-peoplesoft-application-on-amazon-rds-custom-for-oracle-best-practices"></a>

對於您的生產部署，我們建議您在第三個可用區域中啟動觀察器執行個體，與主要節點和僅供讀取複本節點分開。

## 史詩
<a name="transition-roles-for-an-oracle-peoplesoft-application-on-amazon-rds-custom-for-oracle-epics"></a>

### 啟動角色轉換
<a name="initiate-role-transition"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 暫停主要和複本的資料庫自動化。 | 雖然 RDS Custom 自動化架構不會干擾角色轉換程序，但最好在 Oracle Data Guard 切換期間暫停自動化。若要暫停和繼續 RDS Custom 資料庫自動化，請遵循[暫停和繼續 RDS Custom 自動化](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/custom-managing.html#custom-managing.pausing)中的指示。 | 雲端管理員，DBA | 
| 檢查 Oracle Data Guard 狀態。 | 若要檢查 Oracle Data Guard 狀態，請登入主要資料庫。此模式包含使用多租戶容器資料庫 (CDB) 或非 CDB 執行個體的程式碼。**非 CDB**<pre>-bash-4.2$ dgmgrl RDS_DATAGUARD@RDS_CUSTOM_ORCL_A<br />DGMGRL for Linux: Release 19.0.0.0.0 - Production on Mon Nov 28 20:55:50 2022<br />Version 19.10.0.0.0<br />Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.<br />Welcome to DGMGRL, type "help" for information.<br />Password:<br />Connected to "ORCL_A"<br />Connected as SYSDG.<br />DGMGRL> show configuration<br />Configuration - rds_dg<br />Protection Mode: MaxAvailability<br />Members:<br />orcl_a - Primary database<br />orcl_d - Physical standby database <br />Fast-Start Failover: Disabled<br />Configuration Status:<br />SUCCESS (status updated 59 seconds ago)<br />DGMGRL></pre>**CDB**<pre>CDB-bash-4.2$ dgmgrl C##RDS_DATAGUARD@RDS_CUSTOM_RDSCDB_A<br />DGMGRL for Linux: Release 19.0.0.0.0 - Production on Wed Jan 18 06:13:07 2023<br />Version 19.16.0.0.0<br />Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.<br />Welcome to DGMGRL, type "help" for information.<br />Password:<br />Connected to "RDSCDB_A"<br />Connected as SYSDG.<br />DGMGRL> show configuration<br />Configuration - rds_dg<br />  Protection Mode: MaxAvailability<br />  Members:<br />  rdscdb_a - Primary database<br />    rdscdb_b - Physical standby database <br />Fast-Start Failover:  Disabled<br />Configuration Status:<br />SUCCESS   (status updated 52 seconds ago)<br />DGMGRL></pre> | DBA | 
| 驗證執行個體角色。 | 開啟 AWS 管理主控台，然後導覽至 Amazon RDS 主控台。在資料庫的**複寫**區段的**連線與安全**索引標籤上，驗證主要和複本的執行個體角色。主要角色應與 Oracle Data Guard 主要資料庫相符，而複本角色應與 Oracle Data Guard 實體待命資料庫相符。 | 雲端管理員，DBA | 
| 執行切換。 | 若要執行切換，`DGMGRL`請從主節點連線至 。**非 CDB**<pre>DGMGRL> switchover to orcl_d;<br />Performing switchover NOW, please wait...<br />Operation requires a connection to database "orcl_d"<br />Connecting ...<br />Connected to "ORCL_D"<br />Connected as SYSDG.<br />New primary database "orcl_d" is opening...<br />Operation requires start up of instance "ORCL" on database "orcl_a"<br />Starting instance "ORCL"...<br />Connected to an idle instance.<br />ORACLE instance started.<br />Connected to "ORCL_A"<br />Database mounted.<br />Database opened.<br />Connected to "ORCL_A"<br />Switchover succeeded, new primary is "orcl_d"<br />DGMGRL>  </pre>**CDB**<pre>DGMGRL> switchover to rdscdb_b<br />Performing switchover NOW, please wait...<br />New primary database "rdscdb_b" is opening...<br />Operation requires start up of instance "RDSCDB" on database "rdscdb_a"<br />Starting instance "RDSCDB"...<br />Connected to an idle instance.<br />ORACLE instance started.<br />Connected to "RDSCDB_A"<br />Database mounted.<br />Database opened.<br />Connected to "RDSCDB_A"<br />Switchover succeeded, new primary is "rdscdb_b"</pre> | DBA | 
| 驗證 Oracle Data Guard 連線。 | 切換後，驗證從主節點到 的 Oracle Data Guard 連線`DGMGRL`。**非 CDB**<pre>DGMGRL> show configuration;<br />Configuration - rds_dg<br />Protection Mode: MaxAvailability<br />Members:<br />orcl_d - Primary database<br />orcl_a - Physical standby database <br />Fast-Start Failover: Disabled<br />Configuration Status:<br />SUCCESS (status updated 60 seconds ago)<br />DGMGRL> <br /><br />DGMGRL> show configuration lag;<br />Configuration - rds_dg<br />Protection Mode: MaxAvailability<br />Members:<br />orcl_d - Primary database<br />orcl_a - Physical standby database <br />Transport Lag: 0 seconds (computed 0 seconds ago)<br />Apply Lag: 0 seconds (computed 0 seconds ago)<br />Fast-Start Failover: Disabled<br />Configuration Status:<br />SUCCESS (status updated 44 seconds ago)<br />DGMGRL> </pre>**CDB**<pre>DGMGRL> show configuration<br />DGMGRL> show configuration<br />Configuration - rds_dg<br />  Protection Mode: MaxAvailability<br />  Members:<br />  rdscdb_b - Primary database<br />    rdscdb_a - Physical standby database <br />Fast-Start Failover:  Disabled<br />Configuration Status:<br />SUCCESS   (status updated 52 seconds ago)<br />DGMGRL> <br /><br />DGMGRL> show configuration lag<br />Configuration - rds_dg<br />  Protection Mode: MaxAvailability<br />  Members:<br />  rdscdb_b - Primary database<br />    rdscdb_a - Physical standby database <br />               Transport Lag:      0 seconds (computed 0 seconds ago)<br />               Apply Lag:          0 seconds (computed 0 seconds ago)<br />Fast-Start Failover:  Disabled<br />Configuration Status:<br />SUCCESS   (status updated 53 seconds ago)<br />DGMGRL></pre> | DBA | 
| 在 Amazon RDS 主控台上驗證執行個體角色。 | 在您執行角色切換後，Amazon RDS 主控台會在**資料庫****連線與安全**索引標籤的**複寫**區段下顯示新角色。**複寫狀態**可能需要幾分鐘的時間才能從空白更新為**複寫**。 | DBA | 

### 設定 FSFO
<a name="configure-fsfo"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 重設切換。 | 將切換設回主節點。 | DBA | 
| 安裝並啟動觀察者。 | 觀察者程序是`DGMGRL`用戶端元件，通常在與主要和待命資料庫不同的機器中執行。觀察者的 ORACLE HOME 安裝可以是 Oracle Client Administrator 安裝，也可以安裝 Oracle Database Enterprise Edition 或 Personal Edition。如需資料庫版本的觀察程式安裝詳細資訊，請參閱[安裝和啟動觀察程式](https://docs.oracle.com/en/database/oracle/oracle-database/19/dgbkr/using-data-guard-broker-to-manage-switchovers-failovers.html#GUID-11EF3897-8FCA-4A54-B63B-E8C1668AE21B)。若要設定觀察者程序的高可用性，建議您執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/transition-roles-for-an-oracle-peoplesoft-application-on-amazon-rds-custom-for-oracle.html)對於 Oracle 12c 版本 2 和更新版本，您最多可以部署三個觀察者。一個觀察者是主要觀察者，其餘則是備份觀察者。當主要觀察者失敗時，其中一個備份觀察者會擔任主要角色。 | DBA | 
| 從觀察者主機連線至 DGMGRL。 | 觀察者主機設定了主要和待命資料庫連線`tnsnames.ora`的項目。只要資料遺失在 [FastStartFailoverLagLimit](https://docs.oracle.com/en/database/oracle/oracle-database/19/dgbkr/oracle-data-guard-broker-properties.html) 組態 （以秒為單位的值） 內，您就可以啟用具有最大效能保護模式的 FSFO。不過，您必須使用最大可用性保護模式才能達到零資料遺失 (RPO=0)。**非 CDB**<pre>DGMGRL> show configuration;<br />Configuration - rds_dg<br />Protection Mode: MaxAvailability<br />Members:<br />orcl_a - Primary database<br />orcl_d - Physical standby database <br />Fast-Start Failover: Disabled<br />Configuration Status:<br />SUCCESS (status updated 58 seconds ago)<br />DGMGRL> show configuration lag<br />Configuration - rds_dg<br />Protection Mode: MaxAvailability<br />Members:<br />orcl_a - Primary database<br />orcl_d - Physical standby database <br />Transport Lag: 0 seconds (computed 1 second ago)<br />Apply Lag: 0 seconds (computed 1 second ago)<br />Fast-Start Failover: Disabled<br />Configuration Status:<br />SUCCESS (status updated 5 seconds ago)<br />DGMGRL></pre>**CDB**<pre>-bash-4.2$ dgmgrl C##RDS_DATAGUARD@RDS_CUSTOM_RDSCDB_A<br />DGMGRL for Linux: Release 19.0.0.0.0 - Production on Wed Jan 18 06:55:09 2023<br />Version 19.16.0.0.0<br />Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.<br />Welcome to DGMGRL, type "help" for information.<br />Password:<br />Connected to "RDSCDB_A"<br />Connected as SYSDG.<br />DGMGRL> show configuration<br />Configuration - rds_dg<br />  Protection Mode: MaxAvailability<br />  Members:<br />  rdscdb_a - Primary database<br />    rdscdb_b - Physical standby database <br />Fast-Start Failover:  Disabled<br />Configuration Status:<br />SUCCESS   (status updated 18 seconds ago)<br />DGMGRL></pre> | DBA | 
| 將待命資料庫修改為容錯移轉目標。 | 從主節點或觀察者節點連線到一個待命資料庫。（雖然您的初始化可能具有 mulitiple 待命資料庫，但您目前只需要連線到一個。)**非 CDB**<pre>DGMGRL> edit database orcl_a set property FastStartFailoverTarget='orcl_d';<br />Property "faststartfailovertarget" updated<br />DGMGRL> edit database orcl_d set property FastStartFailoverTarget='orcl_a';<br />Property "faststartfailovertarget" updated<br />DGMGRL> show database orcl_a FastStartFailoverTarget;<br />FastStartFailoverTarget = 'orcl_d'<br />DGMGRL> show database orcl_d FastStartFailoverTarget;<br />FastStartFailoverTarget = 'orcl_a'<br />DGMGRL></pre>**CDB**<pre>DGMGRL> edit database orcl_a set property FastStartFailoverTarget='rdscdb_b';<br />Object "orcl_a" was not found<br />DGMGRL> edit database rdscdb_a set property FastStartFailoverTarget='rdscdb_b';<br />Property "faststartfailovertarget" updated<br />DGMGRL> edit database rdscdb_b set property FastStartFailoverTarget='rdscdb_a';<br />Property "faststartfailovertarget" updated<br />DGMGRL> show database rdscdb_a FastStartFailoverTarget;<br />  FastStartFailoverTarget = 'rdscdb_b'<br />DGMGRL> show database rdscdb_b FastStartFailoverTarget;<br />  FastStartFailoverTarget = 'rdscdb_a'<br />DGMGRL></pre> | DBA | 
| 為 DGMGRL 的連線設定 FastStartFailoverThreshold。 | 在 Oracle 19c 中，預設值為 30 秒，最小值為 6 秒。較低的值可能會縮短容錯移轉期間的復原時間目標 (RTO)。較高的值有助於降低主要資料庫發生不必要的容錯移轉暫時性錯誤的機率。RDS Custom for Oracle 自動化架構會監控資料庫運作狀態，並每隔幾秒執行修正動作。因此，我們建議將 FastStartFailoverThreshold 設定為高於 10 秒的值。下列範例會將閾值設定為 35 秒。**非 CBD 或 CDB**<pre>DGMGRL> edit configuration set property FastStartFailoverThreshold=35;<br />Property "faststartfailoverthreshold" updated<br />DGMGRL> show configuration FastStartFailoverThreshold;<br />FastStartFailoverThreshold = '35'<br />DGMGRL></pre> | DBA | 
| 從主要節點或觀察者節點連線至 DGMGRL 以啟用 FSFO。 | 如果資料庫未啟用 [Flashback 資料庫](https://docs.oracle.com/en/database/oracle/oracle-database/19/rcmrf/FLASHBACK-DATABASE.html#GUID-584AC79A-40C5-45CA-8C63-DED3BE3A4511)，則`ORA-16827`會顯示警告訊息。如果 [FastStartFailoverAutoReinstate](https://docs.oracle.com/en/database/oracle/oracle-database/19/dgbkr/oracle-data-guard-broker-properties.html#GUID-824E97C0-EEB0-4E1B-BD4A-F5AE282CEA28) 組態屬性設定為 `TRUE`（這是預設值），則選用的閃存資料庫有助於自動將失敗的主要資料庫恢復到容錯移轉之前的某個時間點。**非 CDB**<pre>DGMGRL> enable fast_start failover;<br />Warning: ORA-16827: Flashback Database is disabled<br />Enabled in Zero Data Loss Mode.<br />DGMGRL> <br />DGMGRL> show configuration<br />Configuration - rds_dg<br />Protection Mode: MaxAvailability<br />Members:<br />orcl_a - Primary database<br />Warning: ORA-16819: fast-start failover observer not started<br />orcl_d - (*) Physical standby database <br />Warning: ORA-16819: fast-start failover observer not started<br />Fast-Start Failover: Enabled in Zero Data Loss Mode<br />Configuration Status:<br />WARNING (status updated 29 seconds ago)<br />DGMGRL></pre>**CDB**<pre>DGMGRL> enable fast_start failover;<br />Warning: ORA-16827: Flashback Database is disabled<br />Enabled in Zero Data Loss Mode.<br />DGMGRL> show configuration;<br />Configuration - rds_dg<br />  Protection Mode: MaxAvailability<br />  Members:<br />  rdscdb_a - Primary database<br />    Warning: ORA-16819: fast-start failover observer not started<br />    rdscdb_b - (*) Physical standby database <br />Fast-Start Failover: Enabled in Zero Data Loss Mode<br />Configuration Status:<br />WARNING   (status updated 11 seconds ago)<br />DGMGRL></pre> | DBA | 
| 啟動觀察者以進行 FSFO 監控，並驗證狀態。 | 您可以在啟用 FSFO 之前或之後啟動觀察者。如果已啟用 FSFO，觀察者會立即開始監控主要和目標待命資料庫的狀態和連線。如果未啟用 FSFO，在啟用 FSFO 之前，觀察者不會開始監控。當您啟動觀察者時，主要資料庫組態會顯示為沒有任何錯誤訊息，如上一個`show configuration`命令所證明。**非 CDB**<pre>DGMGRL> start observer;<br />[W000 2022-12-01T06:16:51.271+00:00] FSFO target standby is orcl_d<br />Observer 'ip-10-0-1-89' started<br />[W000 2022-12-01T06:16:51.352+00:00] Observer trace level is set to USER<br /><br />DGMGRL> show configuration<br />Configuration - rds_dg<br />Protection Mode: MaxAvailability<br />Members:<br />orcl_a - Primary database<br />orcl_d - (*) Physical standby database <br />Fast-Start Failover: Enabled in Zero Data Loss Mode<br />Configuration Status:<br />SUCCESS (status updated 56 seconds ago)<br />DGMGRL> <br /><br />DGMGRL> show observer<br />Configuration - rds_dg<br />Primary: orcl_a<br />Active Target: orcl_d<br />Observer "ip-10-0-1-89" - Master<br />Host Name: ip-10-0-1-89<br />Last Ping to Primary: 1 second ago<br />Last Ping to Target: 1 second ago<br />DGMGRL></pre>**CDB**<pre>DGMGRL> start observer;<br />Succeeded in opening the observer file "/home/oracle/fsfo_ip-10-0-1-56.dat".<br />[W000 2023-01-18T07:31:32.589+00:00] FSFO target standby is rdscdb_b<br />Observer 'ip-10-0-1-56' started<br />The observer log file is '/home/oracle/observer_ip-10-0-1-56.log'.<br /><br />DGMGRL> show configuration<br />Configuration - rds_dg<br />  Protection Mode: MaxAvailability<br />  Members:<br />  rdscdb_a - Primary database<br />    rdscdb_b - (*) Physical standby database <br />Fast-Start Failover: Enabled in Zero Data Loss Mode<br />Configuration Status:<br />SUCCESS   (status updated 12 seconds ago)<br />DGMGRL> <br /><br />DGMGRL> show observer;<br />Configuration - rds_dg<br />  Primary:            rdscdb_a<br />  Active Target:      rdscdb_b<br />Observer "ip-10-0-1-56" - Master<br />  Host Name:                    ip-10-0-1-56<br />  Last Ping to Primary:         1 second ago<br />  Last Ping to Target:          2 seconds ago<br />DGMGRL></pre> | DBA | 
| 驗證容錯移轉。 | 在此案例中，可以透過手動停止主要 EC2 執行個體來執行容錯移轉測試。在停止 EC2 執行個體之前，請使用 `tail`命令，根據您的組態監控觀察者日誌檔案。使用 `DGMGRL`以`orcl_d`使用者 登入待命資料庫`RDS_DATAGUARD`，並檢查 Oracle Data Guard 狀態。它應該顯示 `orcl_d`是新的主要資料庫。在此容錯移轉測試案例中， `orcl_d`是非 CDB 資料庫。在容錯移轉之前，已在 上啟用快閃記憶體資料庫`orcl_a`。在前一個主要資料庫返回線上並開始處於 `MOUNT` 狀態後，觀察者會將其恢復為新的待命資料庫。恢復的資料庫可做為新主要資料庫的 FSFO 目標。您可以在觀察者日誌中驗證詳細資訊。<pre>DGMGRL> show configuration<br />Configuration - rds_dg<br />Protection Mode: MaxAvailability<br />Members:<br />orcl_d - Primary database<br />Warning: ORA-16824: multiple warnings, including fast-start failover-related warnings, detected for the database<br />orcl_a - (*) Physical standby database (disabled)<br />ORA-16661: the standby database needs to be reinstated<br />Fast-Start Failover: Enabled in Zero Data Loss Mode<br />Configuration Status:<br />WARNING (status updated 25 seconds ago)<br />DGMGRL></pre>以下顯示 中的範例輸出`observer.log`。<pre>$ tail -f /tmp/observer.log<br />Unable to connect to database using rds_custom_orcl_a<br />[W000 2023-01-18T07:50:32.589+00:00] Primary database cannot be reached.<br />[W000 2023-01-18T07:50:32.589+00:00] Fast-Start Failover threshold has expired.<br />[W000 2023-01-18T07:50:32.590+00:00] Try to connect to the standby.<br />[W000 2023-01-18T07:50:32.590+00:00] Making a last connection attempt to primary database before proceeding with Fast-Start Failover.<br />[W000 2023-01-18T07:50:32.591+00:00] Check if the standby is ready for failover.<br />[S002 2023-01-18T07:50:32.591+00:00] Fast-Start Failover started...<br />2023-01-18T07:50:32.591+00:00<br />Initiating Fast-Start Failover to database "orcl_d"...<br />[S002 2023-01-18T07:50:32.592+00:00] Initiating Fast-start Failover.<br />Performing failover NOW, please wait...<br />Failover succeeded, new primary is "orcl_d"<br />2023-01-18T07:55:32.101+00:00<br />[S002 2023-01-18T07:55:32.591+00:00] Fast-Start Failover finished...<br />[W000 2023-01-18T07:55:32.591+00:00] Failover succeeded. Restart pinging.<br />[W000 2023-01-18T07:55:32.603+00:00] Primary database has changed to orcl_d.<br />[W000 2023-01-18T07:55:33.618+00:00] Try to connect to the primary.<br />[W000 2023-01-18T07:55:33.622+00:00] Try to connect to the primary rds_custom_orcl_d.<br />[W000 2023-01-18T07:55:33.634+00:00] The standby orcl_a needs to be reinstated<br />[W000 2023-01-18T07:55:33.654+00:00] Try to connect to the new standby orcl_a.<br />[W000 2023-01-18T07:55:33.654+00:00] Connection to the primary restored!<br />[W000 2023-01-18T07:55:35.654+00:00] Disconnecting from database rds_custom_orcl_d.<br />[W000 2023-01-18T07:55:57.701+00:00] Try to connect to the new standby orcl_a.<br />ORA-12170: TNS:Connect timeout occurred</pre> | DBA | 

### 設定 Oracle Peoplesoft 應用程式與資料庫之間的連線
<a name="configure-connectivity-between-the-oracle-peoplesoft-application-and-the-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在主要資料庫中建立和啟動服務。 | 您可以使用同時包含組態中主要和待命資料庫端點的 TNS 項目，以避免角色轉換期間的應用程式組態變更。您可以定義兩個角色型資料庫服務，以支援讀取/寫入和唯讀工作負載。在下列範例中， `orcl_rw`是主要資料庫上作用中的讀取/寫入服務。 `orcl_ro`是唯讀服務，並且是已在唯讀模式中開啟的待命資料庫上作用中。<pre>SQL> select name,open_mode from v$database;<br />NAME OPEN_MODE<br />--------- --------------------<br />ORCL READ WRITE<br />SQL> exec dbms_service.create_service('orcl_rw','orcl_rw');<br />PL/SQL procedure successfully completed.<br />SQL> exec dbms_service.create_service('orcl_ro','orcl_ro');<br />PL/SQL procedure successfully completed.<br /><br />SQL> exec dbms_service.start_service('orcl_rw');<br />PL/SQL procedure successfully completed.<br />SQL></pre> | DBA | 
| 在待命資料庫中啟動服務。 | 若要在唯讀待命資料庫中啟動服務，請使用下列程式碼。<pre>SQL> select name,open_mode from v$database;<br />NAME OPEN_MODE<br />--------- --------------------<br />ORCL READ ONLY WITH APPLY<br />SQL> exec dbms_service.start_service('orcl_ro');<br />PL/SQL procedure successfully completed.<br />SQL></pre> | DBA | 
| 重新啟動主要資料庫時，自動啟動服務。 | 若要在重新啟動時在主要資料庫中自動啟動服務，請使用下列程式碼。<pre>SQL> CREATE OR REPLACE TRIGGER TrgDgServices after startup on database<br />DECLARE<br />db_role VARCHAR(30);<br />db_open_mode VARCHAR(30);<br />BEGIN<br />SELECT DATABASE_ROLE, OPEN_MODE INTO db_role, db_open_mode FROM V$DATABASE;<br />IF db_role = 'PRIMARY' THEN<br />DBMS_SERV 2 ICE.START_SERVICE('orcl_rw');<br />END IF;<br />IF db_role = 'PHYSICAL STANDBY' AND db_open_mode LIKE 'READ ONLY%' THEN<br />DBMS_SERVICE.START_SERVICE('orcl_ro');<br />END IF;<br />END;<br />/ <br />Trigger created.<br />SQL> </pre> | DBA | 
| 設定讀取/寫入和唯讀資料庫之間的連線。 | 您可以針對讀取/寫入和唯讀連線使用下列應用程式組態範例。<pre>ORCL_RW = (DESCRIPTION =<br />(CONNECT_TIMEOUT= 120)(RETRY_COUNT=20)(RETRY_DELAY=3)(TRANSPORT_CONNECT_TIMEOUT=3)<br />(ADDRESS_LIST =<br />(ADDRESS = (PROTOCOL = TCP)(HOST=devpsftdb.******.us-west-2.rds.amazonaws.com)(PORT=1521))<br />(ADDRESS = (PROTOCOL = TCP)(HOST=psftread.******.us-west-2.rds.amazonaws.com)(PORT=1521))<br />)<br />(CONNECT_DATA=(SERVICE_NAME = orcl_rw))<br />)<br />ORCL_RO = (DESCRIPTION =<br />(CONNECT_TIMEOUT= 120)(RETRY_COUNT=20)(RETRY_DELAY=3)(TRANSPORT_CONNECT_TIMEOUT=3)<br />(ADDRESS_LIST =<br />(ADDRESS = (PROTOCOL = TCP)(HOST=devpsftdb.******.us-west-2.rds.amazonaws.com)(PORT=1521))<br />(ADDRESS = (PROTOCOL = TCP)(HOST=psftread.******.us-west-2.rds.amazonaws.com)(PORT=1521))<br />)<br />(CONNECT_DATA=(SERVICE_NAME = orcl_ro))<br />)</pre> | DBA | 

## 相關資源
<a name="transition-roles-for-an-oracle-peoplesoft-application-on-amazon-rds-custom-for-oracle-resources"></a>
+ [使用 Amazon RDS Custom for Oracle 上的 Data Guard 啟用高可用性](https://d1.awsstatic.com/whitepapers/enabling-high-availability-with-data-guard-on-amazon-rds-custom-for-oracle.pdf) (AWS 技術指南）
+ [將 Amazon RDS 設定為 Oracle PeopleSoft 資料庫](https://d1.awsstatic.com/whitepapers/configuring-amazon-rds-as-peoplesoft-database.pdf) (AWS 白皮書）
+ [Oracle Data Guard Broker 指南 ](https://docs.oracle.com/en/database/oracle/oracle-database/19/dgbkr/index.html)(Oracle 參考文件）
+ [Data Guard 概念和管理 ](https://docs.oracle.com/en/database/oracle/oracle-database/19/sbydb/index.html)(Oracle 參考文件）
+ [Oracle Data Guard 特定 FAN 和 FCF 組態需求 ](https://docs.oracle.com/en/database/oracle/oracle-database/19/dgbkr/using-data-guard-broker-to-manage-switchovers-failovers.html#GUID-DFFDAA2B-A889-49AD-AB85-747D73FF0FF5)(Oracle 參考文件）

# 將資料從 Amazon Redshift 叢集跨帳戶卸載至 Amazon S3
<a name="unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3"></a>

*Andrew Kamel，Amazon Web Services*

## 總結
<a name="unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3-summary"></a>

當您測試應用程式時，在測試環境中擁有生產資料會很有幫助。使用生產資料可讓您更準確地評估正在開發的應用程式。

此模式會將生產環境中 Amazon Redshift 叢集的資料擷取到 Amazon Web Services () 上開發環境中的 Amazon Simple Storage Service (Amazon S3) 儲存貯體AWS。

模式會逐步完成 DEV 和 PROD 帳戶的設定，包括下列項目：
+ 必要的資源
+ AWS Identity and Access Management (IAM) 角色
+ 子網路、安全群組和虛擬私有雲端 (VPC) 的網路調整，以支援 Amazon Redshift 連線
+ 具有 Python 執行時間以測試架構的範例 AWS Lambda 函數

若要授予 Amazon Redshift 叢集的存取權，模式會使用 AWS Secrets Manager 來存放相關登入資料。優點是擁有直接連線至 Amazon Redshift 叢集所需的所有必要資訊，而不需要知道 Amazon Redshift 叢集所在的位置。此外，您可以[監控秘密的使用](https://docs.aws.amazon.com/secretsmanager/latest/userguide/monitoring.html)。

儲存在 Secrets Manager 中的秘密包括 Amazon Redshift 叢集的主機、資料庫名稱、連接埠和相關登入資料。

如需使用此模式時安全性考量的相關資訊，請參閱[最佳實務](#unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3-best-practices)一節。

## 先決條件和限制
<a name="unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3-prereqs"></a>

**先決條件**
+ 在 PROD 帳戶中[執行的 Amazon Redshift 叢集](https://docs.aws.amazon.com/redshift/latest/gsg/new-user.html) 
+ 在 DEV 帳戶中[建立的 S3 儲存貯](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html)體
+ DEV 和 PROD 帳戶之間的 [VPC 對等](https://docs.aws.amazon.com/vpc/latest/peering/create-vpc-peering-connection.html)互連，並相應[地調整路由表](https://docs.aws.amazon.com/vpc/latest/peering/vpc-peering-routing.html) 
+ 同時為對等 VPCs [啟用 DNS 主機名稱和 DNS 解析](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-dns.html) 

**限制**
+ 根據您要查詢的資料量，Lambda 函數可能會逾時。

  如果您的執行需要的時間超過 Lambda 逾時上限 (15 分鐘），請針對 Lambda 程式碼使用非同步方法。此模式的程式碼範例使用適用於 Python 的 [psycopg2](https://github.com/psycopg/psycopg2) 程式庫，目前不支援非同步處理。
+ 有些 AWS 服務 完全無法使用 AWS 區域。如需區域可用性，請參閱[AWS 服務 依區域](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/)。如需特定端點，請參閱[服務端點和配額](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)頁面，然後選擇服務的連結。

## Architecture
<a name="unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3-architecture"></a>

下圖顯示具有 DEV 和 PROD 帳戶的目標架構。

![\[DEV 帳戶中的 Lambda VPC 和 PROD 帳戶中的 Amazon Redshift VPC。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5c83c617-3a85-4aea-a7a7-930f406d1cef/images/fa4d01df-483d-4454-9711-b391ebbe4629.png)


該圖顯示以下工作流程：

1. DEV 帳戶中的 Lambda 函數會擔任存取 PROD 帳戶中 Secrets Manager 中的 Amazon Redshift 登入資料所需的 IAM 角色。

   Lambda 函數接著會擷取 Amazon Redshift 叢集秘密。

1. DEV 帳戶中的 Lambda 函數會使用資訊，透過對等 VPCs 連線至 PROD 帳戶中的 Amazon Redshift 叢集。

   然後，Lambda 函數會傳送卸載命令來查詢 PROD 帳戶中的 Amazon Redshift 叢集。

1. PROD 帳戶中的 Amazon Redshift 叢集會擔任相關的 IAM 角色，以存取 DEV 帳戶中的 S3 儲存貯體。

   Amazon Redshift 叢集會將查詢的資料卸載至 DEV 帳戶中的 S3 儲存貯體。

**從 Amazon Redshift 查詢資料**

下圖顯示用來擷取 Amazon Redshift 登入資料並連線至 Amazon Redshift 叢集的角色。工作流程是由 Lambda 函數啟動。

![\[跨帳戶擔任角色的三個步驟程序。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5c83c617-3a85-4aea-a7a7-930f406d1cef/images/ab25b72c-773c-4d58-9012-4a3755c181ff.png)


該圖顯示以下工作流程：

1. DEV 帳戶中`CrossAccount-SM-Read-Role`的 會擔任 PROD 帳戶中`SM-Read-Role`的 。

1. `SM-Read-Role` 角色使用附加的政策從 Secrets Manager 擷取秘密。

1. 登入資料用於存取 Amazon Redshift 叢集。

**將資料上傳至 Amazon S3**

下圖顯示擷取資料並將其上傳至 Amazon S3 的跨帳戶讀寫程序。工作流程是由 Lambda 函數啟動。模式[會鏈結 Amazon Redshift 中的 IAM 角色](https://docs.aws.amazon.com/redshift/latest/mgmt/authorizing-redshift-service.html#authorizing-redshift-service-chaining-roles)。來自 Amazon Redshift 叢集的卸載命令會擔任 `CrossAccount-S3-Write-Role`，然後擔任 `S3-Write-Role`。此角色鏈結可讓 Amazon Redshift 存取 Amazon S3。

![\[取得登入資料、存取 Amazon Redshift 並將資料上傳至 Amazon S3 的角色。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/5c83c617-3a85-4aea-a7a7-930f406d1cef/images/d2982fc6-1d12-4f9d-9493-a99ce691d693.png)


工作流程包含下列步驟：

1. DEV 帳戶中`CrossAccount-SM-Read-Role`的 會擔任 PROD 帳戶中`SM-Read-Role`的 。

1. 會從 Secrets Manager `SM-Read-Role`擷取 Amazon Redshift 登入資料。

1. Lambda 函數會連線至 Amazon Redshift 叢集並傳送查詢。

1. Amazon Redshift 叢集會擔任 `CrossAccount-S3-Write-Role`。

1. `CrossAccount-S3-Write-Role` 假設 DEV 帳戶中`S3-Write-Role`的 。

1. 查詢結果會卸載至 DEV 帳戶中的 S3 儲存貯體。

## 工具
<a name="unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3-tools"></a>

**AWS 服務**
+ [AWS Key Management Service (AWS KMS)](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) 可協助您建立和控制密碼編譯金鑰，以協助保護您的資料。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一項運算服務，可協助您執行程式碼，無需佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需支付使用的運算時間。
+ [Amazon Redshift](https://docs.aws.amazon.com/redshift/latest/gsg/getting-started.html) 是 AWS 雲端中的受管 PB 級資料倉儲服務。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 可協助您將程式碼中的硬式編碼憑證 (包括密碼) 取代為 Secrets Manager 的 API 呼叫，以便透過程式設計方法來擷取機密。
+ [Amazon Simple Storage Service (Amazon S3)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) 是一種雲端型物件儲存服務，可協助您儲存、保護和擷取任何數量的資料。

**程式碼儲存庫**

此模式的程式碼可在 GitHub [unload-redshift-to-s3-python](https://github.com/aws-samples/unload-redshift-to-s3-python/) 儲存庫中使用。

## 最佳實務
<a name="unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3-best-practices"></a>

**安全免責聲明**

實作此解決方案之前，請考慮下列重要的安全建議：
+ 請記住，連接開發和生產帳戶可以增加範圍並降低整體安全狀態。我們建議僅暫時部署此解決方案，擷取所需的資料部分，然後立即銷毀已部署的資源。若要銷毀資源，您應該刪除 Lambda 函數、移除為此解決方案建立的任何 IAM 角色和政策，以及撤銷帳戶之間授予的任何網路存取權。
+ 將任何資料從生產複製到開發環境之前，請先諮詢您的安全與合規團隊。通常不應以此方式複製個人身分識別資訊 (PII)、受保護醫療資訊 (PHI) 和其他機密或管制資料。僅複製公開可用的非機密資訊 （例如，來自商店前端的公有股票資料）。考慮權杖化或匿名化資料，或產生合成測試資料，而不是盡可能使用生產資料。其中一個[AWS 安全原則](https://docs.aws.amazon.com/en_us/wellarchitected/2022-03-31/framework/sec-design.html)是讓人員遠離資料。換句話說，開發人員不應該在生產帳戶中執行操作。
+ 限制對開發帳戶中 Lambda 函數的存取，因為它可以從生產環境中的 Amazon Redshift 叢集讀取資料。
+ 若要避免中斷生產環境，請實作下列建議：
  + 使用單獨的專用開發帳戶進行測試和開發活動。
  + 實作嚴格的網路存取控制，並將帳戶之間的流量限制為僅必要。
  + 監控和稽核對生產環境和資料來源的存取。
  + 為所有涉及的資源和服務實作最低權限的存取控制。
  + 定期檢閱和輪換登入資料，例如 AWS Secrets Manager 秘密和 IAM 角色存取金鑰。
+ 請參閱本文所用服務的下列安全文件：
  + [AWS Lambda 安全性](https://docs.aws.amazon.com/lambda/latest/dg/lambda-security.html)
  + [Amazon Redshift 安全性](https://docs.aws.amazon.com/redshift/latest/mgmt/iam-redshift-user-mgmt.html)
  + [Amazon S3 安全性](https://docs.aws.amazon.com/AmazonS3/latest/userguide/security.html)
  + [AWS Secrets Manager 安全性](https://docs.aws.amazon.com/secretsmanager/latest/userguide/security.html)
  + [IAM 安全最佳實務](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)

安全性是存取生產資料和資源時的首要考量。一律遵循最佳實務、實作最低權限的存取控制，並定期檢閱和更新您的安全措施。

## 史詩
<a name="unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3-epics"></a>

### 從 Amazon Redshift 查詢資料
<a name="query-data-from-amazon-redshift"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立 Amazon Redshift 叢集的秘密。 | 若要建立 Amazon Redshift 叢集的秘密，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 
| 建立 角色以存取 Secrets Manager。 | 若要建立角色，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 

### 將資料上傳至 Amazon S3
<a name="upload-data-to-s3"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立角色以存取 S3 儲存貯體。 | 若要建立存取 S3 儲存貯體的角色，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 
| 建立 Amazon Redshift 角色。 | 若要建立 Amazon Redshift 角色，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 

### 部署 Lambda 函數。
<a name="deploy-the-lam-function"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 部署 Lambda 函數。 | 若要在對等 VPC 中部署 Lambda 函數，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 

### 測試架構
<a name="test-the-architecture"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 匯入所需的資源。 | 若要匯入所需的資源，請執行下列命令：<pre>import ast<br />import boto3<br />import psycopg2<br />import base64<br />from botocore.exceptions import ClientError</pre> | 應用程式開發人員 | 
| 執行 Lambda 處理常式函數。 | Lambda 函數使用 AWS Security Token Service (AWS STS) 進行跨帳戶存取和臨時憑證管理。函數使用 AssumeRole API 操作暫時取得 IAM `sm_read_role` 角色的許可。若要執行 Lambda 函數，請使用下列範例程式碼：<pre>def lambda_handler(event, context):<br />    sts_client = boto3.client('sts')<br /><br />    # Secrets Manager Configurations<br />    secret_name = "redshift_creds"<br />    sm_region = "eu-west-1"<br />    sm_read_role = "arn:aws:iam::PROD_ACCOUNT_NUMBER:role/SM-Read-Role"<br /><br />    # S3 Bucket Configurations<br />    s3_bucket_path = "s3://mybucket/"<br />    s3_bucket_region = "eu-west-1"<br />    s3_write_role = "arn:aws:iam::DEV_ACCOUNT_NUMBER:role/S3-Write-Role"<br /><br />    # Redshift Configurations<br />    sql_query = "select * from category"<br />    redshift_db = "dev"<br />    redshift_s3_write_role = "arn:aws:iam::PROD_ACCOUNT_NUMBER:role/CrossAccount-S3-Write-Role"<br /><br />    chained_s3_write_role = "%s,%s" % (redshift_s3_write_role, s3_write_role)<br /><br />    assumed_role_object = sts_client.assume_role(<br />        RoleArn=sm_read_role,<br />        RoleSessionName="CrossAccountRoleAssumption",<br />        ExternalId="YOUR_EXTERNAL_ID",<br />    )<br />    credentials = assumed_role_object['Credentials']<br /><br />    secret_dict = ast.literal_eval(get_secret(credentials, secret_name, sm_region))<br />    execute_query(secret_dict, sql_query, s3_bucket_path, chained_s3_write_role, s3_bucket_region, redshift_db)<br /><br />    return {<br />        'statusCode': 200<br />    }</pre> | 應用程式開發人員 | 
| 取得秘密。 | 若要取得 Amazon Redshift 秘密，請使用下列範例程式碼：<pre>def get_secret(credentials, secret_name, sm_region):<br />    # Create a Secrets Manager client<br />    session = boto3.session.Session()<br />    sm_client = session.client(<br />        service_name='secretsmanager',<br />        aws_access_key_id=credentials['AccessKeyId'],<br />        aws_secret_access_key=credentials['SecretAccessKey'],<br />        aws_session_token=credentials['SessionToken'],<br />        region_name=sm_region<br />    )<br /><br />    try:<br />        get_secret_value_response = sm_client.get_secret_value(<br />            SecretId=secret_name<br />        )<br />    except ClientError as e:<br />        print(e)<br />        raise e<br />    else:<br />        if 'SecretString' in get_secret_value_response:<br />            return get_secret_value_response['SecretString']<br />        else:<br />            return base64.b64decode(get_secret_value_response['SecretBinary'])</pre> | 應用程式開發人員 | 
| 執行卸載命令。 | 若要將資料卸載至 S3 儲存貯體，請使用下列範例程式碼。<pre>def execute_query(secret_dict, sql_query, s3_bucket_path, chained_s3_write_role, s3_bucket_region, redshift_db):<br />    conn_string = "dbname='%s' port='%s' user='%s' password='%s' host='%s'" \<br />                  % (redshift_db,<br />                     secret_dict["port"],<br />                     secret_dict["username"],<br />                     secret_dict["password"],<br />                     secret_dict["host"])<br /><br />    con = psycopg2.connect(conn_string)<br /><br />    unload_command = "UNLOAD ('{}') TO '{}' IAM_ROLE '{}' DELIMITER '|' REGION '{}';" \<br />        .format(sql_query,<br />                s3_bucket_path + str(datetime.datetime.now()) + ".csv",<br />                chained_s3_write_role,<br />                s3_bucket_region)<br /><br />    # Opening a cursor and run query<br />    cur = con.cursor()<br />    cur.execute(unload_command)<br /><br />    print(cur.fetchone())<br />    cur.close()<br />    con.close()</pre> | 應用程式開發人員 | 

### 清除
<a name="clean-up"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 刪除 Lambda 函數。 | 為了避免產生意外成本，請移除資源以及 DEV 和 PROD 帳戶之間的連線。若要移除 Lambda 函數，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 
| 移除 IAM 角色和政策。 | 從 DEV 和 PROD 帳戶移除 IAM 角色和政策。在 DEV 帳戶中，執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html)在 PROD 帳戶中，執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 
| 在 Secrets Manager 中刪除秘密。 | 若要刪除秘密，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 
| 移除 VPC 對等互連和安全群組規則。 | 若要移除 VPC 對等互連和安全群組規則，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 
| 從 S3 儲存貯體移除資料。 | 若要從 Amazon S3 移除資料，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 
| 清除 AWS KMS 金鑰。 | 如果您已為加密建立任何自訂 AWS KMS 金鑰，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 
| 檢閱和刪除 Amazon CloudWatch logs。 | 若要刪除 CloudWatch 日誌，請執行下列動作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.html) | DevOps 工程師 | 

## 相關資源
<a name="unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3-resources"></a>
+ [Amazon CloudWatch 文件](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)
+ [IAM 文件](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)
+ [Lambda 文件](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)
+ [Amazon Redshift 文件](https://docs.aws.amazon.com/redshift/latest/gsg/new-user-serverless.html)
+ [Amazon S3 文件](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)
+ [AWS Secrets Manager 文件](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html)
+ [AWS 安全原則](https://docs.aws.amazon.com/en_us/wellarchitected/2022-03-31/framework/sec-design.html)

## 其他資訊
<a name="unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3-additional"></a>

將資料從 Amazon Redshift 卸載至 Amazon S3 之後，您可以使用 Amazon Athena 進行分析。

當您需要存取大量資料時，[Amazon Athena](https://docs.aws.amazon.com/athena/latest/ug/getting-started.html) 是一種大數據查詢服務非常有用。您可以使用 Athena，而無需佈建伺服器或資料庫。Athena 支援複雜的查詢，您可以在不同的物件上執行它。

與大多數一樣 AWS 服務，使用 Athena 的主要好處是它在執行查詢時提供了很大的靈活性，而不會增加複雜性。當您使用 Athena 時，您可以在 Amazon S3 中查詢不同的資料類型，例如 CSV 和 JSON，而無需變更資料類型。您可以從各種來源查詢資料，包括外部 AWS。Athena 可降低複雜性，因為您不必管理伺服器。Athena 會在您執行查詢之前直接從 Amazon S3 讀取資料，而不會載入或變更資料。

# 依工作負載的資料庫遷移模式
<a name="databases-database-migration-patterns-by-workload-pattern-list"></a>

**Topics**
+ [IBM](databases-database-migration-patterns-by-workload-ibm-pattern-list.md)
+ [Microsoft](databases-database-migration-patterns-by-workload-microsoft-pattern-list.md)
+ [N/A](databases-database-migration-patterns-by-workload-notapplicable-pattern-list.md)
+ [開放原始碼](databases-database-migration-patterns-by-workload-open-source-pattern-list.md)
+ [Oracle](databases-database-migration-patterns-by-workload-oracle-pattern-list.md)
+ [SAP](databases-database-migration-patterns-by-workload-sap-pattern-list.md)

# IBM
<a name="databases-database-migration-patterns-by-workload-ibm-pattern-list"></a>

**Topics**
+ [使用 AWS DMS 將 Db2 資料庫從 Amazon EC2 遷移至 Aurora MySQL 相容](migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.md)
+ [使用日誌運送將 LUW 的 Db2 遷移至 Amazon EC2，以減少中斷時間](migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time.md)
+ [將 LUW 的 Db2 遷移至具有高可用性災難復原的 Amazon EC2](migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery.md)
+ [使用 AWS DMS 和 AWS SCT 從 Amazon EC2 上的 IBM Db2 遷移至 Aurora PostgreSQL 相容 Amazon EC2](migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct.md)
+ [從 IBM WebSphere Application Server 遷移至 Amazon EC2 上的 Apache Tomcat](migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2.md)
+ [在 上將資料從 IBM Db2、SAP、Sybase 和其他資料庫串流至 MongoDB Atlas AWS](stream-data-from-ibm-db2-to-mongodb-atlas.md)

# Microsoft
<a name="databases-database-migration-patterns-by-workload-microsoft-pattern-list"></a>

**Topics**
+ [加速探索 Microsoft 工作負載並將其遷移至 AWS](accelerate-the-discovery-and-migration-of-microsoft-workloads-to-aws.md)
+ [使用連結的伺服器從 Amazon EC2 上的 Microsoft SQL Server 存取內部部署 Microsoft SQL Server 資料表](access-on-premises-microsoft-sql-server-tables-from-microsoft-sql-server-on-amazon-ec2-using-linked-servers.md)
+ [評估將 SQL Server 資料庫遷移至 AWS 上的 MongoDB Atlas 的查詢效能](assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws.md)
+ [使用 AWS Lambda 和 任務排程器，在 Amazon EC2 上執行的 SQL Server Express 版本中自動化資料庫任務](automate-database-tasks-in-sql-server-express-edition-running-on-amazon-ec2.md)
+ [變更 Python 和 Perl 應用程式，以支援從 Microsoft SQL Server 到 Amazon Aurora PostgreSQL 相容版本的資料庫遷移](change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.md)
+ [在 AWS 上 SQL Server 的 Always On 可用性群組中設定唯讀路由](configure-read-only-routing-in-an-always-on-availability-group-in-sql-server-on-aws.md)
+ [使用 設定 Amazon RDS for Microsoft SQL Server 的 Windows 身分驗證 AWS Managed Microsoft AD](configure-windows-authentication-for-amazon-rds-using-microsoft-ad.md)
+ [使用 Microsoft Excel 和 Python 為 AWS DMS 任務建立 AWS CloudFormation 範本](create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel-and-python.md)
+ [使用 Terraform 在 Amazon EC2 和 Amazon FSx 上部署 SQL Server 容錯移轉叢集執行個體](deploy-sql-server-failover-cluster-instances-on-amazon-ec2-and-amazon-fsx.md)
+ [使用 AWS DMS 將 Microsoft SQL Server 資料庫匯出至 Amazon S3](export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms.md)
+ [使用 AWS DMS 將 Amazon RDS for SQL Server 資料表匯出至 S3 儲存貯體](export-amazon-rds-for-sql-server-tables-to-an-s3-bucket-by-using-aws-dms.md)
+ [從 SQL Server 遷移至 PostgreSQL 時，實作 PII 資料的 SHA1 雜湊](implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.md)
+ [將 EC2 Windows 執行個體擷取並遷移至 AWS Managed Services 帳戶](ingest-and-migrate-ec2-windows-instances-into-an-aws-managed-services-account.md)
+ [使用 FSx for Windows File Server 在 Amazon EC2 上設定 Microsoft SQL Server 容錯移轉叢集](microsoft-sql-failover-cluster-on-amazon-ec2.md)
+ [將訊息佇列從 Microsoft Azure Service Bus 遷移至 Amazon SQS](migrate-a-messaging-queue-from-microsoft-azure-service-bus-to-amazon-sqs.md)
+ [使用 AWS DMS 將 Microsoft SQL Server 資料庫從 Amazon EC2 遷移至 Amazon DocumentDB](migrate-a-microsoft-sql-server-database-from-amazon-ec2-to-amazon-documentdb-by-using-aws-dms.md)
+ [使用 AWS DMS 和 AWS SCT 將 Microsoft SQL Server 資料庫遷移至 Aurora MySQL](migrate-a-microsoft-sql-server-database-to-aurora-mysql-by-using-aws-dms-and-aws-sct.md)
+ [將 .NET 應用程式從 Microsoft Azure App Service 遷移至 AWS Elastic Beanstalk](migrate-a-net-application-from-microsoft-azure-app-service-to-aws-elastic-beanstalk.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon EC2](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server.md)
+ [使用連結的伺服器將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-linked-servers.md)
+ [使用原生備份和還原方法，將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods.md)
+ [使用 AWS DMS 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Redshift](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-dms.md)
+ [使用 AWS SCT 資料擷取代理程式將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Redshift](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至執行 Linux 的 Amazon EC2 上的 Microsoft SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-microsoft-sql-server-on-amazon-ec2-running-linux.md)
+ [使用 Rclone 將資料從 Microsoft Azure Blob 遷移至 Amazon S3](migrate-data-from-microsoft-azure-blob-to-amazon-s3-by-using-rclone.md)
+ [使用 appcmd.exe 將 IIS 託管應用程式遷移至 Amazon EC2](migrate-iis-hosted-applications-to-amazon-ec2-by-using-appcmd.md)
+ [使用 遷移 Microsoft SQL Server Always On 可用性群組 AWS Application Migration Service](migrate-microsoft-sql-server-always-on-group-using-mgn.md)
+ [使用 Application Migration Service 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon EC2](migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn.md)
+ [在 上將關聯式資料庫遷移至 MongoDB Atlas AWS](migrate-relational-database-to-mongodb-atlas.md)
+ [使用分散式可用性群組將 SQL Server 遷移至 AWS](migrate-sql-server-to-aws-using-distributed-availability-groups.md)
+ [使用 ACM 將 Windows SSL 憑證遷移至 Application Load Balancer](migrate-windows-ssl-certificates-to-an-application-load-balancer-using-acm.md)
+ [在 AWS 雲端中重新託管內部部署工作負載：遷移檢查清單](rehost-on-premises-workloads-in-the-aws-cloud-migration-checklist.md)
+ [解決將 Microsoft SQL Server 遷移至 AWS 雲端後的連線錯誤](resolve-connection-errors-after-migrating-microsoft-sql-server-to-the-aws-cloud.md)
+ [使用內部部署 SMTP 伺服器和 Database Mail 傳送 Amazon RDS for SQL Server 資料庫執行個體的通知](send-notifications-for-an-amazon-rds-for-sql-server-database-instance-by-using-an-on-premises-smtp-server-and-database-mail.md)
+ [使用 Terraform 設定資料庫遷移的 CI/CD 管道](set-up-ci-cd-pipeline-for-db-migration-with-terraform.md)
+ [使用 Amazon FSx 設定 SQL Server Always On FCI 的異地同步備份基礎設施](set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.md)

# N/A
<a name="databases-database-migration-patterns-by-workload-notapplicable-pattern-list"></a>

**Topics**
+ [在重新託管遷移至 期間建立防火牆請求的核准程序 AWS](create-an-approval-process-for-firewall-requests-during-a-rehost-migration-to-aws.md)
+ [加密現有的 Amazon RDS for PostgreSQL 資料庫執行個體](encrypt-an-existing-amazon-rds-for-postgresql-db-instance.md)
+ [Amazon DynamoDB 資料表的預估儲存成本](estimate-storage-costs-for-an-amazon-dynamodb-table.md)
+ [使用 AWS DMS 和 Amazon Aurora 實作跨區域災難復原](implement-cross-region-disaster-recovery-with-aws-dms-and-amazon-aurora.md)

# 開放原始碼
<a name="databases-database-migration-patterns-by-workload-open-source-pattern-list"></a>

**Topics**
+ [使用 Python 應用程式自動產生 Amazon DynamoDB 的 PynamoDB 模型和 CRUD 函數 DynamoDB](automatically-generate-a-pynamodb-model-and-crud-functions-for-amazon-dynamodb-by-using-a-python-application.md)
+ [在 pgAdmin 中使用 SSH 通道進行連線](connect-by-using-an-ssh-tunnel-in-pgadmin.md)
+ [在 Aurora PostgreSQL 相容中建立應用程式使用者和角色](create-application-users-and-roles-in-aurora-postgresql-compatible.md)
+ [在 Amazon RDS 中啟用 PostgreSQL 資料庫執行個體的加密連線](enable-encrypted-connections-for-postgresql-db-instances-in-amazon-rds.md)
+ [使用 AWS SCT 和 AWS DMS 將 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL AWS CLI CloudFormation](migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation.md)
+ [使用原生工具將內部部署 MariaDB 資料庫遷移至 Amazon RDS for MariaDB](migrate-an-on-premises-mariadb-database-to-amazon-rds-for-mariadb-using-native-tools.md)
+ [將內部部署 MySQL 資料庫遷移至 Amazon EC2](migrate-an-on-premises-mysql-database-to-amazon-ec2.md)
+ [將內部部署 MySQL 資料庫遷移至 Amazon RDS for MySQL](migrate-an-on-premises-mysql-database-to-amazon-rds-for-mysql.md)
+ [將內部部署 MySQL 資料庫遷移至 Aurora MySQL](migrate-an-on-premises-mysql-database-to-aurora-mysql.md)
+ [將內部部署 PostgreSQL 資料庫遷移至 Aurora PostgreSQL](migrate-an-on-premises-postgresql-database-to-aurora-postgresql.md)
+ [將 Couchbase Server 資料庫遷移至 Amazon EC2](migrate-couchbase-server-ec2.md)
+ [使用 Auto Scaling 從 IBM WebSphere Application Server 遷移至 Amazon EC2 上的 Apache Tomcat](migrate-from-ibm-websphere-application-server-to-apache-tomcat-on-amazon-ec2-with-auto-scaling.md)
+ [使用 SharePlex 和 AWS DMS 從 Oracle 8i 或 9i 遷移至 Amazon RDS for Oracle](migrate-from-oracle-8i-or-9i-to-amazon-rds-for-oracle-using-shareplex-and-aws-dms.md)
+ [使用 pglogical 從 Amazon EC2 上的 PostgreSQL 遷移至 Amazon RDS for PostgreSQL Amazon EC2](migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical.md)
+ [使用 AWS App2Container 將內部部署 Java 應用程式遷移至 AWS](migrate-on-premises-java-applications-to-aws-using-aws-app2container.md)
+ [使用 Percona XtraBackup、Amazon EFS 和 Amazon S3 將內部部署 MySQL 資料庫遷移至 Aurora MySQL](migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3.md)
+ [將 Oracle 外部資料表遷移至 Amazon Aurora PostgreSQL 相容](migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible.md)
+ [將具有超過 100 個引數的 Oracle 函數和程序遷移至 PostgreSQL](migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql.md)
+ [將 Redis 工作負載遷移至 AWS 上的 Redis Enterprise Cloud](migrate-redis-workloads-to-redis-enterprise-cloud-on-aws.md)
+ [在沒有加密的情況下監控 Amazon Aurora 是否有執行個體](monitor-amazon-aurora-for-instances-without-encryption.md)
+ [重新啟動 RHEL 來源伺服器後，在不停用 SELinux 的情況下自動重新啟動 AWS 複寫代理程式](restart-the-aws-replication-agent-automatically-without-disabling-selinux-after-rebooting-a-rhel-source-server.md)
+ [使用 Lambda 和 Secrets Manager 來排程 Amazon RDS for PostgreSQL 和 Aurora PostgreSQL 的任務](schedule-jobs-for-amazon-rds-for-postgresql-and-aurora-postgresql-by-using-lambda-and-secrets-manager.md)
+ [使用 pg\$1transport 在兩個 Amazon RDS 資料庫執行個體之間傳輸 PostgreSQL 資料庫](transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport.md)
+ [將資料從 Amazon Redshift 叢集跨帳戶卸載至 Amazon S3](unload-data-from-amazon-redshift-cross-accounts-to-amazon-s3.md)

# Oracle
<a name="databases-database-migration-patterns-by-workload-oracle-pattern-list"></a>

**Topics**
+ [使用僅供讀取複本將 HA 新增至 Amazon RDS Custom 上的 Oracle PeopleSoft](add-ha-to-oracle-peoplesoft-on-amazon-rds-custom-by-using-a-read-replica.md)
+ [將 JSON Oracle 查詢轉換為 PostgreSQL 資料庫 SQL](convert-json-oracle-queries-into-postgresql-database-sql.md)
+ [將 Oracle 的 VARCHAR2(1) 資料類型轉換為 Amazon Aurora PostgreSQL 的布林資料類型](convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql.md)
+ [使用 PostgreSQL 相容 Aurora 全域資料庫模擬 Oracle DR](emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database.md)
+ [在 Amazon Aurora PostgreSQL 和 Amazon RDS for PostgreSQL 中模擬 Oracle PL/SQL 關聯陣列](emulate-oracle-plsql-associative-arrays-in-aurora-and-rds-postgresql.md)
+ [使用 AWR 報告估計 Oracle 資料庫的 Amazon RDS 引擎大小](estimate-the-amazon-rds-engine-size-for-an-oracle-database-by-using-awr-reports.md)
+ [在 Aurora PostgreSQL 中處理動態 SQL 陳述式中的匿名區塊](handle-anonymous-blocks-in-dynamic-sql-statements-in-aurora-postgresql.md)
+ [使用 Oracle SQL Developer 和 AWS SCT，逐步從 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL](incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct.md)
+ [在 Aurora PostgreSQL 相容中使用檔案編碼將 BLOB 檔案載入 TEXT](load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible.md)
+ [使用 AWS DMS，以 SSL 模式將 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL](migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.md)
+ [將 Amazon RDS for Oracle 資料庫遷移至另一個資料庫 AWS 帳戶 ， AWS 區域 並使用 AWS DMS 進行持續複寫](migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication.md)
+ [使用 Oracle Data Pump 將內部部署 Oracle 資料庫遷移至 Amazon EC2](migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump.md)
+ [使用 Logstash 將內部部署 Oracle 資料庫遷移至 Amazon OpenSearch Service](migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash.md)
+ [使用 AWS DMS 和 AWS SCT 將內部部署 Oracle 資料庫遷移至 Amazon RDS for MySQL](migrate-an-on-premises-oracle-database-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct.md)
+ [將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.md)
+ [透過資料庫連結使用直接 Oracle Data Pump Import，將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-by-using-direct-oracle-data-pump-import-over-a-database-link.md)
+ [使用 Oracle Data Pump 將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump.md)
+ [使用 Oracle 旁觀者和 AWS DMS 將內部部署 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL](migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms.md)
+ [將內部部署 Oracle 資料庫遷移至 Amazon EC2 上的 Oracle](migrate-an-on-premises-oracle-database-to-oracle-on-amazon-ec2.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫從 Amazon EC2 遷移至 Amazon RDS for MariaDB](migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct.md)
+ [使用 AWS DMS 將 Oracle 資料庫從 Amazon EC2 遷移至 Amazon RDS for Oracle](migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-oracle-using-aws-dms.md)
+ [使用 AWS DMS 將 Oracle 資料庫遷移至 Amazon DynamoDB](migrate-an-oracle-database-to-amazon-dynamodb-using-aws-dms.md)
+ [使用 Oracle GoldenGate 平面檔案轉接器，將 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫遷移至 Amazon Redshift](migrate-an-oracle-database-to-amazon-redshift-using-aws-dms-and-aws-sct.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫遷移至 Aurora PostgreSQL](migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct.md)
+ [使用 Oracle Data Pump 和 AWS DMS 將 Oracle JD Edwards EnterpriseOne 資料庫遷移至 AWS](migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms.md)
+ [使用 AWS DMS 將 Oracle 分割的資料表遷移至 PostgreSQL](migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms.md)
+ [使用 AWS DMS 將 Oracle PeopleSoft 資料庫遷移至 AWS](migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms.md)
+ [將資料從現場部署 Oracle 資料庫遷移至 Aurora PostgreSQL](migrate-data-from-an-on-premises-oracle-database-to-aurora-postgresql.md)
+ [從 Amazon RDS for Oracle 遷移至 Amazon RDS for MySQL](migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-mysql.md)
+ [使用具體化視觀表和 AWS DMS，從 Oracle 8i 或 9i 遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms.md)
+ [使用 SharePlex 和 AWS DMS 從 Oracle 8i 或 9i 遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-shareplex-and-aws-dms.md)
+ [使用 Oracle GoldenGate 從 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate.md)
+ [使用 AWS DMS 和 AWS SCT 從 Oracle on Amazon EC2 遷移至 Amazon RDS for MySQL](migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct.md)
+ [在 Amazon ECS 上從 Oracle WebLogic 遷移至 Apache Tomcat (TomEE)](migrate-from-oracle-weblogic-to-apache-tomcat-tomee-on-amazon-ecs.md)
+ [將函數型索引從 Oracle 遷移至 PostgreSQL](migrate-function-based-indexes-from-oracle-to-postgresql.md)
+ [將舊版應用程式從 Oracle Pro\$1C 遷移至 ECPG](migrate-legacy-applications-from-oracle-pro-c-to-ecpg.md)
+ [將 Oracle CLOB 值遷移至 AWS 上的 PostgreSQL 中的個別資料列](migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws.md)
+ [將 Oracle 資料庫錯誤代碼遷移至與 Amazon Aurora PostgreSQL 相容的資料庫](migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database.md)
+ [使用延伸模組將 Oracle 原生函數遷移至 PostgreSQL](migrate-oracle-native-functions-to-postgresql-using-extensions.md)
+ [將 Oracle PeopleSoft 遷移至 Amazon RDS Custom](migrate-oracle-peoplesoft-to-amazon-rds-custom.md)
+ [將 Oracle ROWID 功能遷移至 AWS 上的 PostgreSQL](migrate-oracle-rowid-functionality-to-postgresql-on-aws.md)
+ [將 Oracle SERIALLY\$1REUSABLE pragma 套件遷移至 PostgreSQL](migrate-oracle-serially-reusable-pragma-packages-into-postgresql.md)
+ [將虛擬產生的資料欄從 Oracle 遷移至 PostgreSQL](migrate-virtual-generated-columns-from-oracle-to-postgresql.md)
+ [使用 Amazon CloudWatch 監控 Oracle GoldenGate 日誌](monitor-oracle-goldengate-logs-by-using-amazon-cloudwatch.md)
+ [分析從 Oracle 到 PostgreSQL 的部分資料庫遷移的物件相依性](multilevel-object-analysis-for-database-migration-from-oracle-to-postgresql.md)
+ [在 Amazon RDS for Oracle 上將 Oracle Database Enterprise Edition 轉換為 Standard Edition 2](replatform-oracle-database-enterprise-edition-to-standard-edition-2-on-amazon-rds-for-oracle.md)
+ [使用作用中待命資料庫為 Amazon RDS Custom 上的 Oracle 電子商務套件設定 HA/DR 架構](set-up-an-ha-dr-architecture-for-oracle-e-business-suite-on-amazon-rds-custom-with-an-active-standby-database.md)
+ [在 Aurora PostgreSQL 相容上設定 Oracle UTL\$1FILE 功能](set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible.md)
+ [Amazon RDS Custom for Oracle 上 Oracle PeopleSoft 應用程式的轉換角色](transition-roles-for-an-oracle-peoplesoft-application-on-amazon-rds-custom-for-oracle.md)
+ [從 Oracle 遷移到 Amazon Aurora PostgreSQL 後驗證資料庫物件](validate-database-objects-after-migrating-from-oracle-to-amazon-aurora-postgresql.md)

# SAP
<a name="databases-database-migration-patterns-by-workload-sap-pattern-list"></a>

**Topics**
+ [使用 Systems Manager 和 EventBridge 自動備份 SAP HANA 資料庫](automatically-back-up-sap-hana-databases-using-systems-manager-and-eventbridge.md)
+ [使用 AWS DMS 從 SAP ASE 遷移至 Amazon RDS for SQL Server](migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms.md)
+ [使用 AWS SCT 和 AWS DMS 將 Amazon EC2 上的 SAP ASE 遷移至與 Amazon Aurora PostgreSQL 相容](migrate-sap-ase-on-amazon-ec2-to-amazon-aurora-postgresql-compatible-using-aws-sct-and-aws-dms.md)
+ [使用具有相同主機名稱的 SAP HSR 將 SAP HANA 遷移至 AWS](migrate-sap-hana-to-aws-using-sap-hsr-with-the-same-hostname.md)
+ [在 AWS 上設定 SAP on IBM Db2 的災難復原](set-up-disaster-recovery-for-sap-on-ibm-db2-on-aws.md)

# 更多模式
<a name="databases-more-patterns-pattern-list"></a>

**Topics**
+ [從 Amazon EKS 容器存取 Amazon Neptune 資料庫](access-amazon-neptune-database-from-amazon-eks-container.md)
+ [使用 Athena 存取、查詢和聯結 Amazon DynamoDB 資料表](access-query-and-join-amazon-dynamodb-tables-using-athena.md)
+ [允許 EC2 執行個體寫入存取 AMS 帳戶中的 S3 儲存貯體](allow-ec2-instances-write-access-to-s3-buckets-in-ams-accounts.md)
+ [使用 Amazon Athena 和 Amazon Quick Sight 分析並視覺化巢狀 JSON 資料](analyze-and-visualize-nested-json-data-with-amazon-athena-and-amazon-quicksight.md)
+ [使用 AWS Batch 自動化 Amazon RDS for PostgreSQL 資料庫執行個體的備份](automate-backups-for-amazon-rds-for-postgresql-db-instances-by-using-aws-batch.md)
+ [使用 DynamoDB TTL 自動將項目封存至 Amazon S3](automatically-archive-items-to-amazon-s3-using-dynamodb-ttl.md)
+ [自動修復未加密的 Amazon RDS 資料庫執行個體和叢集](automatically-remediate-unencrypted-amazon-rds-db-instances-and-clusters.md)
+ [使用 AWS Systems Manager 維護 Windows 自動停止和啟動 Amazon RDS 資料庫執行個體](automatically-stop-and-start-an-amazon-rds-db-instance-using-aws-systems-manager-maintenance-windows.md)
+ [建置包含 MongoDB Atlas 的 AWS 登陸區域](build-aws-landing-zone-that-includes-mongodb-atlas.md)
+ [使用 AWS Mainframe Modernization 和 建置 COBOL Db2 程式 AWS CodeBuild](build-cobol-db2-programs-mainframe-modernization-codebuild.md)
+ [使用 Amazon DataZone 建置企業資料網格 AWS CDK，以及 AWS CloudFormation](build-enterprise-data-mesh-amazon-data-zone.md)
+ [變更 Python 和 Perl 應用程式，以支援從 Microsoft SQL Server 到 Amazon Aurora PostgreSQL 相容版本的資料庫遷移](change-python-and-perl-applications-to-support-database-migration-from-microsoft-sql-server-to-amazon-aurora-postgresql-compatible-edition.md)
+ [使用 Python 將 EBCDIC 資料轉換為 AWS 上的 ASCII](convert-and-unpack-ebcdic-data-to-ascii-on-aws-by-using-python.md)
+ [將 Teradata NORMALIZE 暫時功能轉換為 Amazon Redshift SQL](convert-the-teradata-normalize-temporal-feature-to-amazon-redshift-sql.md)
+ [將 Teradata RESET WHEN 功能轉換為 Amazon Redshift SQL](convert-the-teradata-reset-when-feature-to-amazon-redshift-sql.md)
+ [將 Oracle 的 VARCHAR2(1) 資料類型轉換為 Amazon Aurora PostgreSQL 的布林資料類型](convert-varchar2-1-data-type-for-oracle-to-boolean-data-type-for-amazon-aurora-postgresql.md)
+ [在 Aurora PostgreSQL 相容中建立應用程式使用者和角色](create-application-users-and-roles-in-aurora-postgresql-compatible.md)
+ [使用 Microsoft Excel 和 Python 為 AWS DMS 任務建立 AWS CloudFormation 範本](create-aws-cloudformation-templates-for-aws-dms-tasks-using-microsoft-excel-and-python.md)
+ [使用 Kinesis Data Streams 和 Firehose 搭配 將 DynamoDB 記錄交付至 Amazon S3 AWS CDK](deliver-dynamodb-records-to-amazon-s3-using-kinesis-data-streams-and-amazon-data-firehose-with-aws-cdk.md)
+ [使用私有靜態 IPs 在 Amazon EC2 上部署 Cassandra 叢集，以避免重新平衡](deploy-a-cassandra-cluster-on-amazon-ec2-with-private-static-ips-to-avoid-rebalancing.md)
+ [使用 Terraform 在 Amazon EKS 中部署 CockroachDB 叢集](deploy-cockroachdb-on-eks-using-terraform.md)
+ [使用 RAG 和 ReAct 提示，開發進階生成式 AI 聊天式助理](develop-advanced-generative-ai-chat-based-assistants-by-using-rag-and-react-prompting.md)
+ [使用 PostgreSQL 相容 Aurora 全域資料庫模擬 Oracle DR](emulate-oracle-dr-by-using-a-postgresql-compatible-aurora-global-database.md)
+ [在 IBM Db2 資料庫中啟用直接封存至 Amazon S3 的 DB2 日誌 Amazon S3 Db2](enable-db2-logarchive-directly-to-amazon-s3-in-ibm-db2-database.md)
+ [在 Amazon RDS for SQL Server 中啟用透明資料加密](enable-transparent-data-encryption-in-amazon-rds-for-sql-server.md)
+ [使用 AWS DMS 將 Microsoft SQL Server 資料庫匯出至 Amazon S3](export-a-microsoft-sql-server-database-to-amazon-s3-by-using-aws-dms.md)
+ [從 SQL Server 遷移至 PostgreSQL 時，實作 PII 資料的 SHA1 雜湊](implement-sha1-hashing-for-pii-data-when-migrating-from-sql-server-to-postgresql.md)
+ [使用 Oracle SQL Developer 和 AWS SCT，逐步從 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL](incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct.md)
+ [在 Aurora PostgreSQL 相容中使用檔案編碼將 BLOB 檔案載入 TEXT](load-blob-files-into-text-by-using-file-encoding-in-aurora-postgresql-compatible.md)
+ [使用 AWS Secrets Manager 管理登入資料](manage-credentials-using-aws-secrets-manager.md)
+ [使用 AWS DMS 將 Db2 資料庫從 Amazon EC2 遷移至 Aurora MySQL 相容](migrate-a-db2-database-from-amazon-ec2-to-aurora-mysql-compatible-by-using-aws-dms.md)
+ [使用 AWS DMS 將 Microsoft SQL Server 資料庫從 Amazon EC2 遷移至 Amazon DocumentDB](migrate-a-microsoft-sql-server-database-from-amazon-ec2-to-amazon-documentdb-by-using-aws-dms.md)
+ [使用 AWS DMS 和 AWS SCT 將 Microsoft SQL Server 資料庫遷移至 Aurora MySQL](migrate-a-microsoft-sql-server-database-to-aurora-mysql-by-using-aws-dms-and-aws-sct.md)
+ [使用 AWS DMS，以 SSL 模式將 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL](migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-in-ssl-mode-by-using-aws-dms.md)
+ [使用 AWS SCT 和 AWS DMS 將 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL AWS CLI CloudFormation](migrate-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-with-aws-sct-and-aws-dms-using-aws-cli-and-aws-cloudformation.md)
+ [將 Amazon RDS 資料庫執行個體遷移至另一個 VPC 或帳戶](migrate-an-amazon-rds-db-instance-to-another-vpc-or-account.md)
+ [將 Amazon RDS for Oracle 資料庫遷移至另一個資料庫 AWS 帳戶 ， AWS 區域 並使用 AWS DMS 進行持續複寫](migrate-an-amazon-rds-for-oracle-database-to-another-aws-account-and-aws-region-using-aws-dms-for-ongoing-replication.md)
+ [將 Amazon Redshift 叢集遷移至中國的 AWS 區域](migrate-an-amazon-redshift-cluster-to-an-aws-region-in-china.md)
+ [使用原生工具將內部部署 MariaDB 資料庫遷移至 Amazon RDS for MariaDB](migrate-an-on-premises-mariadb-database-to-amazon-rds-for-mariadb-using-native-tools.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon EC2](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-ec2.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server.md)
+ [使用連結的伺服器將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-linked-servers.md)
+ [使用原生備份和還原方法，將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon RDS for SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-rds-for-sql-server-using-native-backup-and-restore-methods.md)
+ [使用 AWS DMS 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Redshift](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-dms.md)
+ [使用 AWS SCT 資料擷取代理程式將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon Redshift](migrate-an-on-premises-microsoft-sql-server-database-to-amazon-redshift-using-aws-sct-data-extraction-agents.md)
+ [將內部部署 Microsoft SQL Server 資料庫遷移至執行 Linux 的 Amazon EC2 上的 Microsoft SQL Server](migrate-an-on-premises-microsoft-sql-server-database-to-microsoft-sql-server-on-amazon-ec2-running-linux.md)
+ [將內部部署 MySQL 資料庫遷移至 Amazon RDS for MySQL](migrate-an-on-premises-mysql-database-to-amazon-rds-for-mysql.md)
+ [將內部部署 MySQL 資料庫遷移至 Aurora MySQL](migrate-an-on-premises-mysql-database-to-aurora-mysql.md)
+ [使用 Oracle Data Pump 將內部部署 Oracle 資料庫遷移至 Amazon EC2](migrate-an-on-premises-oracle-database-to-amazon-ec2-by-using-oracle-data-pump.md)
+ [使用 Logstash 將內部部署 Oracle 資料庫遷移至 Amazon OpenSearch Service](migrate-an-on-premises-oracle-database-to-amazon-opensearch-service-using-logstash.md)
+ [使用 AWS DMS 和 AWS SCT 將內部部署 Oracle 資料庫遷移至 Amazon RDS for MySQL](migrate-an-on-premises-oracle-database-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct.md)
+ [將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle.md)
+ [透過資料庫連結使用直接 Oracle Data Pump Import，將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-by-using-direct-oracle-data-pump-import-over-a-database-link.md)
+ [使用 Oracle Data Pump 將內部部署 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-on-premises-oracle-database-to-amazon-rds-for-oracle-using-oracle-data-pump.md)
+ [使用 Oracle 旁觀者和 AWS DMS 將內部部署 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL](migrate-an-on-premises-oracle-database-to-amazon-rds-for-postgresql-by-using-an-oracle-bystander-and-aws-dms.md)
+ [將內部部署 Oracle 資料庫遷移至 Amazon EC2 上的 Oracle](migrate-an-on-premises-oracle-database-to-oracle-on-amazon-ec2.md)
+ [將內部部署 PostgreSQL 資料庫遷移至 Aurora PostgreSQL](migrate-an-on-premises-postgresql-database-to-aurora-postgresql.md)
+ [將內部部署 ThoughtSpot Falcon 資料庫遷移至 Amazon Redshift](migrate-an-on-premises-thoughtspot-falcon-database-to-amazon-redshift.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫從 Amazon EC2 遷移至 Amazon RDS for MariaDB](migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-mariadb-using-aws-dms-and-aws-sct.md)
+ [使用 AWS DMS 將 Oracle 資料庫從 Amazon EC2 遷移至 Amazon RDS for Oracle](migrate-an-oracle-database-from-amazon-ec2-to-amazon-rds-for-oracle-using-aws-dms.md)
+ [使用 Oracle GoldenGate 平面檔案轉接器，將 Oracle 資料庫遷移至 Amazon RDS for Oracle](migrate-an-oracle-database-to-amazon-rds-for-oracle-by-using-oracle-goldengate-flat-file-adapters.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫遷移至 Amazon Redshift](migrate-an-oracle-database-to-amazon-redshift-using-aws-dms-and-aws-sct.md)
+ [使用 AWS DMS 和 AWS SCT 將 Oracle 資料庫遷移至 Aurora PostgreSQL](migrate-an-oracle-database-to-aurora-postgresql-using-aws-dms-and-aws-sct.md)
+ [使用 Oracle Data Pump 和 AWS DMS 將 Oracle JD Edwards EnterpriseOne 資料庫遷移至 AWS](migrate-an-oracle-jd-edwards-enterpriseone-database-to-aws-by-using-oracle-data-pump-and-aws-dms.md)
+ [使用 AWS DMS 將 Oracle 分割的資料表遷移至 PostgreSQL](migrate-an-oracle-partitioned-table-to-postgresql-by-using-aws-dms.md)
+ [使用 AWS DMS 將 Oracle PeopleSoft 資料庫遷移至 AWS](migrate-an-oracle-peoplesoft-database-to-aws-by-using-aws-dms.md)
+ [將 Couchbase Server 資料庫遷移至 Amazon EC2](migrate-couchbase-server-ec2.md)
+ [將資料從現場部署 Oracle 資料庫遷移至 Aurora PostgreSQL](migrate-data-from-an-on-premises-oracle-database-to-aurora-postgresql.md)
+ [AWS 雲端 使用 Starburst 將資料遷移至](migrate-data-to-the-aws-cloud-by-using-starburst.md)
+ [使用日誌運送將 LUW 的 Db2 遷移至 Amazon EC2，以減少中斷時間](migrate-db2-for-luw-to-amazon-ec2-by-using-log-shipping-to-reduce-outage-time.md)
+ [將 LUW 的 Db2 遷移至具有高可用性災難復原的 Amazon EC2](migrate-db2-for-luw-to-amazon-ec2-with-high-availability-disaster-recovery.md)
+ [從 Amazon RDS for Oracle 遷移至 Amazon RDS for MySQL](migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-mysql.md)
+ [從 Couchbase Server 遷移至 AWS 上的 Couchbase Capella](migrate-from-couchbase-server-to-couchbase-capella-on-aws.md)
+ [使用 AWS DMS 和 AWS SCT 從 Amazon EC2 上的 IBM Db2 遷移至 Aurora PostgreSQL 相容 Amazon EC2](migrate-from-ibm-db2-on-amazon-ec2-to-aurora-postgresql-compatible-using-aws-dms-and-aws-sct.md)
+ [使用具體化視觀表和 AWS DMS，從 Oracle 8i 或 9i 遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-materialized-views-and-aws-dms.md)
+ [使用 SharePlex 和 AWS DMS 從 Oracle 8i 或 9i 遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-8i-or-9i-to-amazon-rds-for-postgresql-using-shareplex-and-aws-dms.md)
+ [使用 Oracle GoldenGate 從 Oracle 資料庫遷移至 Amazon RDS for PostgreSQL](migrate-from-oracle-database-to-amazon-rds-for-postgresql-by-using-oracle-goldengate.md)
+ [使用 AWS DMS 和 AWS SCT 從 Oracle on Amazon EC2 遷移至 Amazon RDS for MySQL](migrate-from-oracle-on-amazon-ec2-to-amazon-rds-for-mysql-using-aws-dms-and-aws-sct.md)
+ [使用 pglogical 從 Amazon EC2 上的 PostgreSQL 遷移至 Amazon RDS for PostgreSQL Amazon EC2](migrate-from-postgresql-on-amazon-ec2-to-amazon-rds-for-postgresql-using-pglogical.md)
+ [使用 AWS DMS 從 SAP ASE 遷移至 Amazon RDS for SQL Server](migrate-from-sap-ase-to-amazon-rds-for-sql-server-using-aws-dms.md)
+ [將函數型索引從 Oracle 遷移至 PostgreSQL](migrate-function-based-indexes-from-oracle-to-postgresql.md)
+ [將舊版應用程式從 Oracle Pro\$1C 遷移至 ECPG](migrate-legacy-applications-from-oracle-pro-c-to-ecpg.md)
+ [使用 Application Migration Service 將內部部署 Microsoft SQL Server 資料庫遷移至 Amazon EC2](migrate-microsoft-sql-server-to-amazon-ec2-using-aws-mgn.md)
+ [將內部部署 Cloudera 工作負載遷移至 AWS 上的 Cloudera 資料平台](migrate-on-premises-cloudera-workloads-to-cloudera-data-platform-on-aws.md)
+ [使用 Percona XtraBackup、Amazon EFS 和 Amazon S3 將內部部署 MySQL 資料庫遷移至 Aurora MySQL](migrate-on-premises-mysql-databases-to-aurora-mysql-using-percona-xtrabackup-amazon-efs-and-amazon-s3.md)
+ [從內部部署伺服器將 Oracle Business Intelligence 12c 遷移至 AWS 雲端](migrate-oracle-business-intelligence-12c-to-the-aws-cloud-from-on-premises-servers.md)
+ [將 Oracle CLOB 值遷移至 AWS 上的 PostgreSQL 中的個別資料列](migrate-oracle-clob-values-to-individual-rows-in-postgresql-on-aws.md)
+ [將 Oracle 資料庫錯誤代碼遷移至與 Amazon Aurora PostgreSQL 相容的資料庫](migrate-oracle-database-error-codes-to-an-amazon-aurora-postgresql-compatible-database.md)
+ [將 Oracle 外部資料表遷移至 Amazon Aurora PostgreSQL 相容](migrate-oracle-external-tables-to-amazon-aurora-postgresql-compatible.md)
+ [使用延伸模組將 Oracle 原生函數遷移至 PostgreSQL](migrate-oracle-native-functions-to-postgresql-using-extensions.md)
+ [將 Oracle PeopleSoft 遷移至 Amazon RDS Custom](migrate-oracle-peoplesoft-to-amazon-rds-custom.md)
+ [將 Oracle ROWID 功能遷移至 AWS 上的 PostgreSQL](migrate-oracle-rowid-functionality-to-postgresql-on-aws.md)
+ [將 Oracle SERIALLY\$1REUSABLE pragma 套件遷移至 PostgreSQL](migrate-oracle-serially-reusable-pragma-packages-into-postgresql.md)
+ [使用 AWS SCT 和 AWS DMS 將 Amazon EC2 上的 SAP ASE 遷移至與 Amazon Aurora PostgreSQL 相容](migrate-sap-ase-on-amazon-ec2-to-amazon-aurora-postgresql-compatible-using-aws-sct-and-aws-dms.md)
+ [將虛擬產生的資料欄從 Oracle 遷移至 PostgreSQL](migrate-virtual-generated-columns-from-oracle-to-postgresql.md)
+ [設定最低可行的資料空間以在組織之間共用資料](minimum-viable-data-space-share-data-organizations.md)
+ [監控 Amazon ElastiCache 叢集的靜態加密](monitor-amazon-elasticache-clusters-for-at-rest-encryption.md)
+ [使用 Amazon Athena 查詢具有 SQL 的 Amazon DynamoDB 資料表](query-amazon-dynamodb-tables-sql-amazon-athena.md)
+ [使用信任的內容來保護和簡化 AWS 上 Db2 聯合資料庫中的使用者存取](secure-and-streamline-user-access-in-a-db2-federation-database-on-aws-by-using-trusted-contexts.md)
+ [在 AWS 上設定高度可用的 PeopleSoft 架構](set-up-a-highly-available-peoplesoft-architecture-on-aws.md)
+ [在 Aurora PostgreSQL 相容上設定 Oracle UTL\$1FILE 功能](set-up-oracle-utl_file-functionality-on-aurora-postgresql-compatible.md)
+ [使用 PGO 在 Amazon EKS 上簡化 PostgreSQL 部署](streamline-postgresql-deployments-amazon-eks-pgo.md)
+ [以 CSV 檔案將大規模 Db2 z/OS 資料傳輸至 Amazon S3](transfer-large-scale-db2-z-os-data-to-amazon-s3-in-csv-files.md)
+ [使用 pg\$1transport 在兩個 Amazon RDS 資料庫執行個體之間傳輸 PostgreSQL 資料庫](transport-postgresql-databases-between-two-amazon-rds-db-instances-using-pg-transport.md)
+ [從 Oracle 遷移到 Amazon Aurora PostgreSQL 後驗證資料庫物件](validate-database-objects-after-migrating-from-oracle-to-amazon-aurora-postgresql.md)