使用 OCI GoldenGate 以最短停機時間從內部部署佈建 OCI 資料庫與 PostgreSQL 並進行移轉
簡介
Oracle Cloud Infrastructure Database with PostgreSQL (OCI Database with PostgreSQL) 是完全託管的 PostgreSQL 相容服務,透過資料庫最佳化儲存提高 3 倍效能,與 Amazon Web Service (AWS) 相比,成本降低一半,提供自動化備份、高可用性、排定維護、動態儲存規模、垂直擴展等功能。
範例:業務連續性
具備 PostgreSQL 服務的 OCI 資料庫提供 99.99% 正常運作時間服務層次協議 (SLA)、多節點資料庫系統的復原時間目標 (RTO) 少於 2 分鐘,以及 0 的復原點目標 (RPO),而不會遺失資料。對於單一可用性網域 (AD) 區域中的單一節點資料庫系統,此服務提供 99.9% 的正常運作時間 SLA、不到 20 分鐘的 RTO,以及 0 的 RPO。
OCI Database with PostgreSQL 利用 OCI Block Volumes 儲存使用者資料。因此,相同的持久性、安全性和效能保證也適用。如需詳細資訊,請參閱 OCI 資料庫概要 (含 PostgreSQL) 和第一原則:最佳化雲端的 PostgreSQL 。
本教學課程著重於使用 OCI GoldenGate 從內部部署 PostgreSQL 資料庫移轉至使用 PostgreSQL 的 OCI 資料庫 (最短停機時間)。
環境詳細資訊:
- OCI GoldenGate 主控台使用者名稱:
oggadmin
。 - OCI GoldenGate 版本:
23ai
。 - OCI 資料庫,管理名稱為 PostgreSQL:
admin
。
來源內部部署 | 目標 OCI | |
---|---|---|
DB 名稱 | product_inventory | 目標資料庫 |
User | 訂單管理器 | admin |
綱要 | data_analyze | data_analyze |
資料庫版本 | 15.12 | 15.6 |
目標
-
使用 PostgreSQL 資料庫系統建立 OCI 資料庫。
-
佈建 OCI GoldenGate 部署。
-
在部署時建立內部部署資料庫和 OCI 資料庫連線,然後指定連線。
-
準備來源資料庫伺服器與資料庫。
-
建立初始載入 Extract。
-
使用
pg_dump
公用程式備份來源資料庫描述資料。 -
使用 PostgreSQL 將中繼資料匯入 OCI 資料庫。
-
使用歷程檔建立起始載入 Replicat。
-
建立線上或變更資料擷取 (CDC) 擷取,將其更改為開始用於擷取的日誌序號 (LSN)。
-
建立提供 CDC Extract 歷程檔的線上 Replicat。
工作 1:使用 PostgreSQL 資料庫系統佈建 OCI 資料庫
此作業說明如何建立資料庫系統,以及佈建之前需要下列原則。如需詳細資訊,請參閱管理資料庫系統。
-
新增下列 Oracle Cloud Infrastructure Identity and Access Management (IAM) 原則。
Allow group <postgresql-admin-group> to read compartments in tenancy Allow group <postgresql-admin-group> to manage postgres-db-systems in [ tenancy | compartment <compartment_name> | compartment id <compartment_OCID> ] Allow group <postgresql-admin-group> to manage postgres-backups in [ tenancy | compartment <compartment_name> | compartment id <compartment_OCID> ] Allow group <postgresql-admin-group> to read postgres-work-requests in [ tenancy | compartment <compartment_name> | compartment id <compartment_OCID> ] Allow group <postgresql-admin-group> to manage postgres-configuration in [ tenancy | compartment <compartment_name> | compartment id <compartment_OCID> ] Allow group <postgresql-admin-group> to manage virtual-network-family in [ tenancy | compartment <compartment_name> | compartment id <compartment_OCID> ] Allow group <postgresql-admin-group> to read secret-family in [ tenancy | compartment <compartment_name> | compartment id <compartment_OCID> ] Allow group <postgresql-admin-group> to read vaults in [ tenancy | compartment <compartment_name> | compartment id <compartment_OCID> ] Allow group <postgresql-admin-group> to read metrics in [ tenancy | compartment <compartment_name> | compartment id <compartment_OCID> ] Allow group <postgresql-admin-group> to use tag-namespaces in tenancy
-
建立或選取資料庫管理員密碼的保存庫。如需更多資訊,請參閱 Managing Vaults 。
-
建立資料庫密碼的金鑰。如需更多資訊,請參閱 Managing Keys 。
-
建立資料庫密碼的加密密碼。如需詳細資訊,請參閱管理保存庫加密密碼。
-
登入 OCI 主控台,瀏覽至資料庫、PostgreSQL 、資料庫系統、建立新資料庫系統,然後按下一步。
-
選取硬體組態。
-
選取虛擬雲端網路和子網路,然後輸入資料庫系統管理員證明資料。在此範例中, Username 會成為 admin 。
建立完成後,資料庫系統就會顯示作用中狀態。
-
請執行下列命令,以驗證從運算節點使用 PostgreSQL 連線至 OCI 資料庫。
-bash-4.2$ psql "sslmode=verify-full sslrootcert=c.pub host=<OCI DB server ip address> user=admin dbname=postgres" Password for user admin: psql (15.12, server 15.6) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, compression: off) Type "help" for help. postgres=>
工作 2:建立用於移轉的 OCI GoldenGate 部署
-
前往 OCI 主控台,瀏覽至 Oracle Database 、GoldenGate 、部署,然後按一下建立部署。
-
輸入下列影像中指定的必要資訊,並選取 PostgreSQL 作為選取技術。
-
在設定您的部署中,使用
oggadmin
作為使用者名稱,以管理員身分登入 OCI GoldenGate 主控台。 -
按一下建立,即可開始建立和部署。順利完成之後,會顯示作用中狀態。
工作 3:建立內部部署資料庫連線、部署中的 OCI 資料庫連線以及指定連線
OCI GoldenGate 需要來源、目標資料庫連線,並將這兩個連線指派給部署。
-
建立來源資料庫連線。
-
按一下部署名稱 (
PG_Mig_deployment
),選取連線,然後按一下建立連線。如下列影像所示,輸入所需的資訊。 -
選取類型作為 PostgreSQL 伺服器,選取安全協定作為純文字,然後按一下建立。
-
-
建立目標資料庫連線。
-
按一下部署名稱,選取連線,然後按一下建立連線。如下列影像所示,輸入所需的資訊。
-
選取類型作為 OCI PostgreSQL 。
-
選取安全協定 (Security Protocol) 作為 TLS ,選取 SSL 模式作為要求 (Require) 。
-
-
指定資料庫連線到建置。
-
前往部署,按一下部署名稱 (
PG_Mig_deployment
),選取指派連線,然後按一下指派連線。 -
如下列影像所示,輸入所需的資訊。
指定連線完成後,您將會見到作用中狀態。
-
作業 4:準備來源資料庫伺服器與資料庫
-
安裝
postgresql15-contrib
套裝軟體。OCI GoldenGate 需要來源資料庫伺服器上的
postgresql14-contrib
套件,才能從 PostgreSQL 伺服器資料庫中擷取。套裝軟體可以使用sudo yum install postgresql15-contrib
指令來安裝 (來源資料庫版本是 15)。注意:建議從屬端程式庫的版本必須與 PostgreSQL 資料庫版本相符。不支援低於 10 的用戶端版本。
-
準備在來源資料庫和必要權限上建立資料庫使用者。
product_inventory=# create user ggreplication with password 'abc1234'; ERROR: role "ggreplication" already exists product_inventory=# product_inventory=# select current_database(); current_database ------------------- product_inventory (1 row) product_inventory=# GRANT CONNECT ON DATABASE product_inventory TO ggreplication; GRANT product_inventory=# ALTER USER ggreplication WITH REPLICATION; ALTER ROLE product_inventory=# ALTER USER ggreplication WITH SUPERUSER; ALTER ROLE product_inventory=# GRANT USAGE ON SCHEMA ordermanager TO ggreplication; GRANT product_inventory=# GRANT USAGE ON SCHEMA data_analyze TO ggreplication; GRANT product_inventory=# GRANT SELECT ON ALL TABLES IN SCHEMA ordermanager TO ggreplication; GRANT product_inventory=# GRANT SELECT ON ALL TABLES IN SCHEMA data_analyze TO ggreplication; GRANT product_inventory=# GRANT CREATE ON DATABASE product_inventory TO ggreplication; GRANT product_inventory=# GRANT CREATE, USAGE ON SCHEMA ordermanager TO ggreplication; GRANT product_inventory=# GRANT CREATE, USAGE ON SCHEMA data_analyze TO ggreplication; GRANT product_inventory=# GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA ordermanager TO ggreplication; GRANT product_inventory=# GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA data_analyze TO ggreplication; GRANT product_inventory=# GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA ordermanager TO ggreplication; GRANT product_inventory=# GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA data_analyze TO ggreplication; GRANT product_inventory=#
如需有關每個權限之特定用途的詳細資訊,請參閱準備 PostgreSQL 的資料庫使用者和權限。
-
以下為 PostgreSQL 資料庫組態檔中的參數。組態檔的位置是
$PGDATA/postgresql.conf
。wal_level = logical **# set to logical for Capture** max_replication_slots = 1 **# max number of replication and one slot for Extract/Client** max_wal_senders = 1 **# one sender per max repl slot** track_commit_timestamp = on **# optional, correlates tx commit time** with begin tx log record (useful for # timestamp- based positioning)
注意:
- 在進行上述任何變更之後,請重新啟動資料庫。
- OCI GoldenGate 複製支援的 PostgreSQL 資料類型和受支援資料類型的限制,可從文件驗證受支援的物件和作業。如需詳細資訊,請參閱準備資料庫。
任務 5:建立初始載入擷取
我們需要建立初始載入 Extract,這將會提供 OCI GoldenGate Extract 報表區段上的 LSN。
-
前往 OCI 主控台,瀏覽至資料庫、GoldenGate 、部署,然後按一下在任務 2 中建立的部署名稱。
-
按一下啟動主控台,然後輸入登入證明資料。
-
移至資料庫連線,這應該顯示具有 PostgreSQL 資料庫連線的指派來源和 OCI 資料庫,並確認連線檢查。
成功的連線可以在此階段開始初始載入。
-
前往 OCI GoldenGate 主控台,瀏覽至擷取,然後按一下 + 。
初始載入 Extract 停止之後,請驗證 OCI GoldenGate 報表檔案並記下 LSN 詳細資訊,並妥善用於 Task 9。
工作 6:使用 pg_dump
命令備份來源資料庫描述資料
pg_dump
命令僅用於傾印來源資料庫 product_inventory
描述資料。
pg_dump -h localhost -U ggreplication -d product_inventory -F c -v -s --file=/tmp/exp_source_db.dump
工作 7:使用 PostgreSQL 將描述資料匯入 OCI 資料庫
使用 pg_restore 二進位檔以 PostgreSQL 匯入目標 OCI 資料庫,此處的 OCI 資料庫名稱為 targetdb
。
從 OCI Compute 節點執行回復命令,我們已順利在作業 1.8 中執行連線命令。
pg_restore -h <OCI IP address> -U admin -d targetdb -v exp_source_db.dump
postgres=> \c targetdb
psql (15.12, server 15.6)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, compression: off)
You are now connected to database "targetdb" as user "admin".
targetdb=> \dn
List of schemas
Name | Owner
--------------+-------------------
data_analyze | admin
ordermanager | admin
public | pg_database_owner
(3 rows)
注意:使用
select table_name,table_schema from information_schema.tables where table_type='BASE TABLE' and table_schema in ('data_analyze','ordermanager') order by table_schema,table_name;
查詢在目標上匯入描述資料之後,驗證表格名稱。
作業 8:使用歷程檔建立起始載入 Replicat
-
前往 OCI GoldenGate 主控台,瀏覽至 Replicats 並按一下 + 以建立 Replicat。
-
按一下建立並執行以開始初始載入「複製」(Replicate) 完成後,請檢查表格資料列計數。
-
前往報表並確認初始載入「複製」報表。驗證兩個資料庫的少數表格資料列計數。
任務 9:建立 CDC 擷取變更以開始擷取的 LSN
「CDC 擷取」是線上擷取,用於擷取現有資料庫的持續變更,而「CDC 擷取」會從收集的 LSN 編號開始擷取。
-
前往 OCI GoldenGate 主控台,瀏覽至擷取,按一下 + 並輸入所需的資訊,如下圖所示。
-
註冊並建立 CDC 後,按一下以選項開始以指示從任務 5 中收集的特定 LSN 讀取。
我們可以在一段時間後看到 CDC Extract 的零秒延遲。
作業 10:建立提供 CDC 擷取歷程檔的線上複寫
-
前往 OCI GoldenGate 主控台,瀏覽至 Replicats ,按一下 + ,然後輸入所需的資訊,如下圖所示。
-
修改
MAP
命令後,按一下建立並執行。我們可以在一段時間後看到線上 Replicat 的零秒延遲。
驗證
執行下列查詢以插入來源表格 data_analyze.table3
複製至目標資料庫 data_analyze.table3
表格。
目標端驗證表格個數和資料。
相關連結
-
使用 OCI GoldenGate,使用 PostgreSQL 將內部部署 PostgreSQL 資料庫順暢地移轉至 OCI 資料庫
-
使用 OCI GoldenGate 將內部部署 PostgreSQL 資料庫移轉至含有 PostgreSQL 的 OCI 資料庫
認可
- 作者 - Sivakrishna Burle (Oracle 北美雲端服務資深雲端工程師 - NACIE)
其他學習資源
在 docs.oracle.com/learn 上探索其他實驗室,或在 Oracle Learning YouTube 頻道上存取更多免費學習內容。此外,請造訪 education.oracle.com/learning-explorer 以成為 Oracle Learning Explorer。
如需產品文件,請造訪 Oracle Help Center 。
Provision OCI Database with PostgreSQL and Migrate from On-Premises with Minimum Downtime using OCI GoldenGate
G39917-02
Copyright ©2025, Oracle and/or its affiliates.