

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

# 使用 Oracle SQL Developer 和 AWS SCT，逐步從 Amazon RDS for Oracle 遷移至 Amazon RDS for PostgreSQL
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct"></a>

*Pinesh Singal，Amazon Web Services*

## 總結
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-summary"></a>

許多遷移策略和方法會分多個階段執行，持續數週到數個月。在此期間，您可能會因為要遷移至 PostgreSQL 資料庫執行個體的來源 Oracle 資料庫執行個體中的修補或升級而遇到延遲。為了避免這種情況，建議您將剩餘的 Oracle 資料庫程式碼逐步遷移至 PostgreSQL 資料庫程式碼。

此模式為在初始遷移後執行大量交易且必須遷移至 PostgreSQL 資料庫的多 TB Oracle 資料庫執行個體提供無停機時間的增量遷移策略。您可以使用此模式的step-by-step方法，將 Amazon Relational Database Service (Amazon RDS) for Oracle 資料庫執行個體逐步遷移至 Amazon RDS for PostgreSQL 資料庫執行個體，而無需登入 Amazon Web Services (AWS) 管理主控台。

模式使用 [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) 尋找來源 Oracle 資料庫中兩個結構描述之間的差異。然後，您可以使用 AWS Schema Conversion Tool (AWS SCT) 將 Amazon RDS for Oracle 資料庫結構描述物件轉換為 Amazon RDS for PostgreSQL 資料庫結構描述物件。然後，您可以在 Windows 命令提示字元中執行 Python 指令碼，為來源資料庫物件的增量變更建立 AWS SCT 物件。

**注意**  
遷移生產工作負載之前，建議您在測試或非生產環境中，針對此模式的方法執行概念驗證 (PoC)。

## 先決條件和限制
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 現有的 Amazon RDS for Oracle 資料庫執行個體。 
+ 現有的 Amazon RDS for PostgreSQL 資料庫執行個體。
+ AWS SCT，安裝並設定適用於 Oracle 和 PostgreSQL 資料庫引擎的 JDBC 驅動程式。如需詳細資訊，請參閱 [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Installing.html#CHAP_Installing.Procedure) 文件中的安裝 AWS SCT 和[安裝所需的資料庫驅動程式](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Installing.html#CHAP_Installing.JDBCDrivers)。 
+ Oracle SQL Developer，已安裝並設定。如需詳細資訊，請參閱 [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) 文件。 
+ `incremental-migration-sct-sql.zip` 檔案 （已連接），下載到您的本機電腦。

**限制**
+ 來源 Amazon RDS for Oracle 資料庫執行個體的最低需求為：
  + Oracle 10.2 版和更新版本 （適用於 10.x 版）、11g 版 (11.2.0.3.v1 版和更新版本） 和最高 12.2 版，以及 Enterprise、Standard、Standard One 和 Standard Two 版 18c 版
+ 您目標 Amazon RDS for PostgreSQL 資料庫執行個體的最低需求為： 
  + PostgreSQL 9.4 版和更新版本 （適用於 9.x 版）、10.x 版和 11.x 版
+ 此模式使用 Oracle SQL Developer。如果您使用其他工具來尋找和匯出結構描述差異，結果可能會有所不同。
+ Oracle SQL Developer [產生的 SQL 指令碼](https://docs.oracle.com/database/121/AEUTL/sql_rep.htm#AEUTL191)可能會引發轉換錯誤，這表示您需要執行手動遷移。
+ 如果 AWS SCT 來源和目標測試連線失敗，請確定您已設定虛擬私有雲端 (VPC) 安全群組的 JDBC 驅動程式版本和傳入規則，以接受傳入流量。

**產品版本**
+ Amazon RDS for Oracle 資料庫執行個體 12.1.0.2 版 (10.2 版及更新版本）
+ Amazon RDS for PostgreSQL 資料庫執行個體 11.5 版 (9.4 版及更新版本）
+ Oracle SQL Developer 19.1 版及更新版本
+ AWS SCT 1.0.632 版及更新版本

## Architecture
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-architecture"></a>

**來源技術堆疊**
+ Amazon RDS for Oracle 資料庫執行個體

**目標技術堆疊**
+ Amazon RDS for PostgreSQL 資料庫執行個體

**來源和目標架構**

下圖顯示 Amazon RDS for Oracle 資料庫執行個體遷移至 Amazon RDS for PostgreSQL 資料庫執行個體。

![\[從 Amazon RDS for Oracle 到 Amazon RDS for PostgreSQL 的遷移工作流程。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/c7eed517-e496-4e8e-a520-c1e43397419e/images/bfbbed5e-db13-4a22-99aa-1a17f00f5faf.png)


圖表顯示下列遷移工作流程：

1. 開啟 Oracle SQL Developer 並連線至來源和目標資料庫。

1. 產生[差異報告](https://docs.oracle.com/cd/E93130_01/rules_palette/Content/Diff%20Reports/Detailed_Diff_Reports.htm)，然後產生結構描述差異物件的 SQL 指令碼檔案。如需 diff 報告的詳細資訊，請參閱 Oracle 文件中的[詳細 diff 報告](https://docs.oracle.com/cd/E93130_01/rules_palette/Content/Diff%20Reports/Detailed_Diff_Reports.htm)。

1. 設定 AWS SCT 並執行 Python 程式碼。

1. SQL 指令碼檔案會從 Oracle 轉換為 PostgreSQL。

1. 在目標 PostgreSQL 資料庫執行個體上執行 SQL 指令碼檔案。 

**自動化和擴展**

您可以將單一程式中多個功能的其他參數和安全相關變更新增至 Python 指令碼，以自動化此遷移。

## 工具
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-tools"></a>
+ [AWS SCT](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Welcome.html) – AWS Schema Conversion Tool (AWS SCT) 會將您現有的資料庫結構描述從一個資料庫引擎轉換為另一個資料庫引擎。
+ [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) – Oracle SQL Developer 是一種整合的開發環境 (IDE)，可簡化傳統和雲端部署中 Oracle 資料庫的開發和管理。

**Code**

`incremental-migration-sct-sql.zip` 檔案 （已連接） 包含此模式的完整原始碼。

## 史詩
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-epics"></a>

### 建立來源資料庫結構描述差異的 SQL 指令碼檔案
<a name="create-the-sql-scripts-file-for-the-source-database-schema-differences"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Oracle SQL Developer 中執行資料庫差異。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct.html) | DBA | 
| 產生 SQL 指令碼檔案。 | 選擇**產生指令碼**以產生 SQL 檔案中的差異。 這會產生 SQL 指令碼檔案，供 AWS SCT 用來將資料庫從 Oracle 轉換為 PostgreSQL。 | DBA | 

### 使用 Python 指令碼在 AWS SCT 中建立目標資料庫物件
<a name="use-the-python-script-to-create-the-target-db-objects-in-aws-sct"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 使用 Windows 命令提示字元設定 AWS SCT。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct.html)<pre>#source_vendor,source_hostname,source_dbname,source_user,source_pwd,source_schema,source_port,source_sid,target_vendor,target_hostname,target_user,target_pwd,target_dbname,target_port<br /><br />ORACLE,myoracledb.cokmvis0v46q.us-east-1.rds.amazonaws.com,ORCL,orcl,orcl1234,orcl,1521,ORCL,POSTGRESQL,mypgdbinstance.cokmvis0v46q.us-east-1.rds.amazonaws.com,pguser,pgpassword,pgdb,5432</pre>4. 根據您的需求修改 AWS SCT 組態參數，然後將 SQL 指令碼檔案複製到`input`子目錄中的工作目錄。 | DBA | 
| 執行 Python 指令碼。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct.html) | DBA | 
|  在 Amazon RDS for PostgreSQL 中建立物件 | 執行 SQL 檔案，並在 Amazon RDS for PostgreSQL 資料庫執行個體中建立物件。 | DBA | 

## 相關資源
<a name="incrementally-migrate-from-amazon-rds-for-oracle-to-amazon-rds-for-postgresql-using-oracle-sql-developer-and-aws-sct-resources"></a>
+ [Amazon RDS 上的 Oracle](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html) 
+ [Amazon RDS 上的 PostgreSQL ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html)
+ [使用 AWS SCT 使用者介面](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_UserInterface.html)
+ [使用 Oracle 做為 AWS SCT 的來源](https://docs.aws.amazon.com/SchemaConversionTool/latest/userguide/CHAP_Source.Oracle.html)

## 附件
<a name="attachments-c7eed517-e496-4e8e-a520-c1e43397419e"></a>

若要存取與本文件相關聯的其他內容，請解壓縮下列檔案： [attachment.zip](samples/p-attach/c7eed517-e496-4e8e-a520-c1e43397419e/attachments/attachment.zip)