天天看點

Oracle 資料庫跨版本更新遷移實踐

實施背景

今年春節加班期間,将某客戶的核心資料庫從 Oracle 10.2.0.4 RAC 遷移更新至 12.2 RAC。原庫是使用的 Raw,而且版本較低,無法直接更新到 12.2 版本,是以整個更新過程相對麻煩。

實施思路

我們在新環境部署了10g、11.2、12.2 的 Database 軟體(其中 10g,11.2 均為單機,12.2 為已經安裝好的 Oracle RAC 環境);

然後配置好主庫到新環境的 DataGuard 資料同步,在正式割接之前确認主備同步正常。由于需要将資料庫從 10gR2 遷移到新環境并且更新到 12.2,且需要使用 CDB 模式,是以整個過程相對繁瑣。

如下是大緻步驟: 

1. 停止 Job(将 job_queue_processes 參數提前置為0,并 kill 相關程序);

2. 檢查分布式事務,并進行相關處理(實際上我們檢查确實發現了部分分布式事務需要手工介入);

select ' exec DBMS_TRANSACTION.PURGE_LOST_DB_ENTRY('||chr(39)||LOCAL_TRAN_ID||chr(39)||');'||chr(10)||'commit;'  from dba_2pc_pending;

3. 在确認主備資料同步之後,進行 switchover,如下是主備切換簡約步驟:

--主庫 alter database commit to switchover to physical standby WITH SESSION SHUTDOWN; startup mount; alter database open read only; --備庫 alter database commit to switchover to primary; startup force

4. 新主庫更新到 11.2 之前需要先建立還原點,防止有問題可以回退;

alter database flashback on;
 alter database open; alter system switch logfile; create restore point restore_point_10g guarantee flashback database;


5. 執行更新腳本,将資料庫更新到 11.2;

6. 确認更新成功之後,drop 還原點并建立新的還原點,準備将資料庫更新到 12.2;

drop restore point restore_point_10g; create restore point restore_point_11g guarantee flashback database;


這裡需要注意的是,在更新到 12.2 之前需要将執行個體參數 compatible 設定為11.2.0.4,否則在更新過程中可能會遭遇 ORA-00600 錯誤。

7. 執行更新腳本将資料庫更新到 12.2;

@/home/oracle/shell/log/preupgrade_fixups.sql $ORACLE_HOME/perl/bin/perl -I $ORACLE_HOME/perl/lib $ORACLE_HOME/rdbms/admin/catctl.pl -n 8 $ORACLE_HOME/rdbms/admin/catupgrd.sql @/home/oracle/shell/log/postupgrade_fixups.sql

8. 确認更新後資料庫元件正常且無相關報錯之後,drop 還原點;

select comp_name,VERSION,STATUS from dba_registry; drop restore point restore_point_11g;

9. 資料庫更新到 12.2 之後,需要将 DB 從 NO-CDB 模式轉換成 CDB 模式,将資料庫作為 PDB 插入到 12.2 RAC 叢集中;

如下是轉 CDB 模式是相關簡單步驟:

1)啟動執行個體到隻讀模式

startup mount exclusive
; alter database open read only;

2)建立 xml 中繼資料檔案

EXEC DBMS_PDB.DESCRIBE( pdb_descr_file => '/tmp/XXXDB.xml');

3)檢查相容性

DECLARE compatible CONSTANT VARCHAR2(3) :=  CASE  DBMS_PDB.CHECK_PLUG_COMPATIBILITY(pdb_descr_file => '/tmp/XXDB.xml',pdb_name => 'xxdb') WHEN TRUE THEN 'YES' ELSE 'NO' END; BEGIN DBMS_OUTPUT.PUT_LINE(compatible); /

4)進行 nocopy 操作

CREATE PLUGGABLE DATABASE pdbcdrs USING '/tmp/XXDB.xml' NOCOPY;

5) 啟動 PDB 進行并進行轉換 

alter session set container= pdbcdrs;
 alter pluggable database pdbcdrs open; shutdown immediate
; @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql

10. 建立 Redo、Undo 以及修改相應參數,将資料庫轉成 RAC 執行個體。

問題讨論

Oracle 資料庫跨版本更新遷移實踐

在整個更新過程中,我們遇到了幾個小問題,分别如下:

1. DataGuard 的檔案 convert 參數沒有加入 tempfile,導緻 DG 切換之後,主庫 open 有問題,需要先 drop tempfile 之後才行;

2. 在更新到 12.2 的過程中,遇到 ORA-01722 錯誤,如下所示:

Oracle 資料庫跨版本更新遷移實踐

根據 Oracle Mos 文檔 Upgrade to 12.2 Fails with Error:”ORA-01722: Invalid number : NONUPGRADED_TABLEDATA” (文檔 ID 2279497.1) 的描述,可以通過如下的方式來解決:

set serveroutput on @?/rdbms/admin/catuptabdata.sql @?/rdbms/admin/utluptabdata.sql execute dbms_preup.run_fixup_and_report('INVALID_SYS_TABLEDATA'); execute dbms_preup.run_fixup_and_report('INVALID_USR_TABLEDATA'); set serveroutput off

3. 将資料庫作為 PDB 插入到 CDB 之後,打開 PDB 時提示為受限模式。

該問題經查是由于我們在執行的過程中漏掉了一個步驟(exec dbms_pdb.sync_pdb();),導緻 PDB 的資訊與 CDB 的資訊不一緻,本質上元件資訊不一緻。

實際上從 Oracle 官方的解釋來看,隻要 PDB 的元件屬于 CDB 的子集就行,我們當時查詢結果卻是顯示正常的,但是 PDB 的元件狀态顯示異常,是以讓 Oracle 認為 PDB 的元件與 CDB 有巨大差異,将 PDB 置于受限模式“OPTION WARNING Database option mismatch: PDB installed version NULL” in PDB_PLUG_IN_VIOLATIONS(文檔 ID 2020172.1)。

該文檔中有詳細的描述,認為這是 12.2 的一個加強。

Some warnings in PDB_PLUG_IN_VIOLATIONS prevent you from actually opening the PDB in READ WRITE mode; this is not one of them.  You can ignore these messages.   It is okay for a PDB to have a subset (fewer) options installed than the CDB into which it is plugged.   (The reverse is NOT true, however -- the CDB must always have the same or more options as its PDBs).   Unpublished Bug 16192980 : NO SIMPLE WAY TO CLEAN ROWS FROM PDB_PLUG_IN_VIOLATIONS AFTER DBMS_PDB CALL has been filed to request a way to clear out no-impact warnings from PDB_PLUG_IN_VIOLATIONS.  This enhancement is implemented in versions > 12.2.0.1.

我們嘗試過将元件 Reinstall 然後再 Install 是可以的,但是元件較多,大約8個元件,尤其是 Java 或 xdb 相關元件比較麻煩,是以我們将 PDB 删除然後重新建立了 PDB 進行加載,最終解決了該問題。

總的來接,整個過程遇到了幾個小問題,但是還算順利!

參考文檔:

PDB Opens up in Restricted mode after migrating from Non-CDB To CDB environment (Doc ID 2202516.1)

PDB does not come out of Restricted Mode due to ORA-959 in PDB_PLUG_IN_VIOLATIONS (Doc ID 2167662.1)

PDB Is Always In Restricted Mode (Doc ID 1933110.1)

PDB in Restrict Mode Causes Issues (Doc ID 1949188.1)

Pluggable Databases Opened in Restricted Mode After PSU Patching (Doc ID 2225006.1)