客戶一套核心系統由一台Oracle Database 11.2.0.3.4單機和一台Active Data Guard組成,分別運行在兩台PC服務器上,Oracle Linux 5.8 x86_64bit操作系統,兩台服務器都未接存儲設備;由於原有設備老舊等原因,現在要將這套Oracle數據庫系統(主庫和ADG庫)遷移到新采購的兩台服務器上,不跨版本,也不跨平台。為了最小化停機時間,我們先用目前最新的RMAN 0級備份在兩台新服務器上restore database,之後將到目前為止的所有1級備份和歸檔日志restore和recover到兩個數據庫上,在主數據庫正常停機之後把剩余的歸檔和在線Redo日志文件應用到兩個新數據庫,使他們的數據到最新,且是一致的,最後打開主數據庫,恢復ADG的同步,整個過程從凌晨0點開始停機,一直持續到了4:20才遷移成功,之間遇到了不少小的問題,再次進行記錄:
1.RMAN報錯。
RMAN在應用部分歸檔日志之後收到如下報錯:
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 11/13/2014 00:03:03
ORA-00283: recovery session canceled due to errors
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/oradata/bak/archivelog/2014_11_12/o1_mf_1_62193_b65oryl5_.arc'
ORA-00283: recovery session canceled due to errors
ORA-19755: could not open change tracking file
ORA-19750: change tracking file: '/u01/app/oracle/block_change_file'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
執行下面的SQL禁用block change tracking,數據庫即可繼續正常的應用archivelog:
SQL > alter database disable block change tracking;
Database altered.
參考文章:http://gavinsoorma.com/2009/07/rman-recovery-interrupted-due-to-block-change-tracking-file/
2.resetlogs之後檢查主庫和備庫的日志同步情況。
通常在主庫執行以下的SQL語句可以用於檢查主庫和備庫日志同步情況:
SQL> select dest_id,thread#,max(sequence#) from v$archived_log where resetlogs_change#=936497858 group by dest_id,thread#;
DEST_ID THREAD# MAX(SEQUENCE#)
---------- ---------- --------------
2 1 9
1 1 9
由於主數據庫在打開的時候執行了alter database open resetlogs,所以查詢v$archived_log要跟上resetlogs_change#,確保查看的是現在數據庫的歸檔情況,resetlogs_change#可以通過v$database.resetlogs_change#獲得,另外,由於resetlogs打開了數據庫,所以sequence#重新開始計數。
3.對活動的Standby LogFile的處理。
停止主數據庫之後,我們是想將原來的所有Online Redo Logfile和Standby Logfile都拷貝到新服務器,通過alter databae rename file ... to ...的方式進行重命名,沒想到的是Active的Standby Logfile無法進行重命名(收到報錯:ORA-01511: error in renaming log/data files),但又必須將Standby Logfile文件放在指定的目錄下,下面是查詢v$logfile的狀態:
SQL> select group#,member from v$logfile;
GROUP#
----------
MEMBER
--------------------------------------------------------------------------------
3
/oradata/orcl/REDO03.LOG
2
/oradata/orcl/REDO02.LOG
1
/oradata/orcl/REDO01.LOG
GROUP#
----------
MEMBER
--------------------------------------------------------------------------------
4
/u01/app/oracle/oradata/orcl/sredo01.log
5
/oradata/orcl/sredo02.log
6
/oradata/orcl/sredo03.log
GROUP#
----------
MEMBER
--------------------------------------------------------------------------------
7
/oradata/orcl/sredo04.log
7 rows selected.
group# 4是主數據庫之前的Active Standby Logfile,無法對其進行alter database rename file操作。
SQL> alter database drop logfile group 4;
alter database drop logfile group 4
*
ERROR at line 1:
ORA-00315: log 4 of thread 1, wrong thread # 0 in header
ORA-00312: online log 4 thread 1: '/u01/app/oracle/oradata/orcl/sredo01.log'
嘗試DROP GROUP組失敗。
SQL> alter database add logfile member '/oradata/orcl/sredo01.log' to group 4;
alter database add logfile member '/oradata/orcl/sredo01.log' to group 4
*
ERROR at line 1:
ORA-16161: Cannot mix standby and online redo log file members for group 4
嘗試添加成員失敗。
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 4;
ALTER DATABASE CLEAR LOGFILE GROUP 4
*
ERROR at line 1:
ORA-00350: log 4 of instance orcl (thread 1) needs to be archived
ORA-00312: online log 4 thread 1: '/u01/app/oracle/oradata/orcl/sredo01.log'
由於未歸檔所以直接CLEAR失敗。
SQL> ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP 4;
Database altered.
CLEAR UNARCHIVED成功。
對Standby Logfile的處理辦法和對Online Redo Logfile的處理辦法一致。
SQL> select group#,thread#,status from v$standby_log;
GROUP# THREAD# STATUS
---------- ---------- ----------
4 1 UNASSIGNED
5 1 UNASSIGNED
6 1 UNASSIGNED
7 1 UNASSIGNED
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/oradata/orcl/REDO03.LOG
/oradata/orcl/REDO02.LOG
/oradata/orcl/REDO01.LOG
/u01/app/oracle/oradata/orcl/sredo01.log
/oradata/orcl/sredo02.log
/oradata/orcl/sredo03.log
/oradata/orcl/sredo04.log
7 rows selected.
SQL> alter database drop logfile group 4;
Database altered.
成功DROP該日志組。
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/oradata/orcl/REDO03.LOG
/oradata/orcl/REDO02.LOG
/oradata/orcl/REDO01.LOG
/oradata/orcl/sredo02.log
/oradata/orcl/sredo03.log
/oradata/orcl/sredo04.log
6 rows selected.
SQL> select group#,thread#,bytes/1024/1024 mb from v$standby_log;
GROUP# THREAD# MB
---------- ---------- ----------
5 1 50
6 1 50
7 1 50
SQL> ALTER DATABASE ADD STANDBY LOGFILE group 4 ('/oradata/orcl/sredo01.log') SIZE 50M;
Database altered.
添加GROUP 4新的位置。
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/oradata/orcl/REDO03.LOG
/oradata/orcl/REDO02.LOG
/oradata/orcl/REDO01.LOG
/oradata/orcl/sredo01.log
/oradata/orcl/sredo02.log
/oradata/orcl/sredo03.log
/oradata/orcl/sredo04.log
7 rows selected.
注意:以上的操作可能在備庫上無法完成,解決方法是,在主庫完成Standby Logfile遷移之後,主庫在MOUNT狀態下創建新的for Standby Controlfile(alter database create standby controlfile as '/tmp/controlf.ctl'; ),將新的Standby Controlfile和Standby Logfile傳遞到相同的位置,恢復備庫到一致狀態,打開備庫,開始應用日志即可。可以參考文章《Oracle Active Data Guard調整案例[2]》:http://blog.itpub.net/23135684/viewspace-1262326/
Data Guard備庫一定要是一致的狀態才能open read only打開,否者執行alter database recover managed standby database應用日志,恢復到一致性的狀態,再open read only。
4.主庫和備用庫無法實時同步。
原有的主數據庫和備用數據庫配置的時最高性能模式下的實時同步,完成遷移後無法進行實時同步,但歸檔切換後的同步正常。
首先主數據庫的LOG_ARCHIVE_DEST_2配置好了LGWR AFFIRM SYNC參數,備庫執行了如下應用命令:
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
且主庫和備用庫的日志傳輸服務正常工作。
在主數據庫和備用數據庫執行如下SQL語句:
SQL> select group#,thread#,status,bytes/1024/1024 mb from v$standby_log;
GROUP# THREAD# STATUS MB
---------- ---------- ---------- ----------
4 0 UNASSIGNED 100
5 0 UNASSIGNED 100
6 0 UNASSIGNED 100
7 0 UNASSIGNED 100
正常情況下,備用數據庫Standby Logfile Group至少有一個GROUP是Active的狀態,這裡沒有,所以不能實時同步數據,仔細觀察可以發現,這裡的Thread等於0,這或許就是備用數據庫找不到Standby Logfile進行實時同步的原因。
將備用數據庫啟動到MOUNT狀態,執行如下的SQL,指定Standby Logfile的Thread號:
SQL> startup mount
ORACLE instance started.
Total System Global Area 1.3683E+11 bytes
Fixed Size 2245480 bytes
Variable Size 8858373272 bytes
Database Buffers 1.2778E+11 bytes
Redo Buffers 189480960 bytes
Database mounted.
SQL> ALTER DATABASE ADD STANDBY LOGFILE thread 1 ('/oradata/orcl/sredo05.log') SIZE 100M reuse;
Database altered.
SQL> select group#,thread#,status,bytes/1024/1024 mb from v$standby_log;
GROUP# THREAD# STATUS MB
---------- ---------- ---------- ----------
4 0 UNASSIGNED 100
5 0 UNASSIGNED 100
6 0 UNASSIGNED 100
7 0 UNASSIGNED 100
8 1 UNASSIGNED 100
SQL> alter database drop logfile group 4;
Database altered.
SQL> alter database drop logfile group 5;
Database altered.
SQL> alter database drop logfile group 6;
Database altered.
SQL> alter database drop logfile group 7;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE thread 1 group 4 ('/oradata/orcl/sredo01.log') SIZE 100M reuse;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE thread 1 group 5 ('/oradata/orcl/sredo02.log') SIZE 100M reuse;
Database altered.
SQL> ALTER DATABASE ADD STANDBY LOGFILE thread 1 group 6 ('/oradata/orcl/sredo03.log') SIZE 100M reuse;
ALTER DATABASE ADD STANDBY LOGFILE thread 1 group 7 ('/oradata/orcl/sredo04.log') SIZE 100M reuse;
Database altered.
SQL> select group#,thread#,status,bytes/1024/1024 mb from v$standby_log;
GROUP# THREAD# STATUS MB
---------- ---------- ---------- ----------
4 1 UNASSIGNED 100
5 1 UNASSIGNED 100
6 1 UNASSIGNED 100
7 1 UNASSIGNED 100
8 1 ACTIVE 100
之後數據同步即恢復了正常工作,通常的操作還需要在主數據庫上完成,主庫和備庫實時同步期間會不斷的在兩個或多個Standby Logfile之間切換。
--end--