RAC環境下的歸檔模式切換與單一實例稍有不同,主要是共用儲存所產生的差異。在這種情況下,我們可以將RAC資料庫切換到非叢集狀態下,僅僅在一個執行個體上來實施歸檔模式切換即可完成RAC資料庫的歸檔模式轉換問題。本文主要描述了由非歸檔模式切換到歸檔模式,而由非歸檔切換的歸檔步驟相同,不再贅述。
1、主要步驟:
備份spfile,以防止參數修改失敗導致資料庫無法啟動
修改叢集參數cluster_database為false
啟動單一實例到mount狀態
將資料庫置于歸檔模式(alter database archivelog/noarchivelog)
修改叢集參數cluster_database為true
關閉單一實例
啟動叢集資料庫
2、環境
oracle@bo2dbp:~> cat /etc/issue
Welcome to SUSE Linux Enterprise Server 10 SP3 (x86_64) - Kernel \r (\l).
oracle@bo2dbp:~> sqlplus -v
SQL*Plus: Release 10.2.0.3.0 - Production
使用asm儲存方式存放歸檔日誌
3、修改叢集資料庫到歸檔模式
oracle@bo2dbp:~> export ORACLE_SID=ora10g1
oracle@bo2dbp:~> sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Mon Dec 24 16:53:18 2012
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
With the Real Application Clusters option
SQL> archive log list; -->查看當前資料庫的歸檔模式
Database log mode No Archive Mode -->非歸檔模式
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 59
Current log sequence 60
SQL> select instance_name,host_name,status from gv$instance;
INSTANCE_NAME HOST_NAME STATUS
---------------- -------------------- ------------
ora10g1 bo2dbp OPEN
ora10g2 bo2dbs OPEN
SQL> show parameter cluster -->查看叢集的參數,cluster_database為true表示為叢集資料庫,否則,非叢集資料庫
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cluster_database boolean TRUE
cluster_database_instances integer 2
cluster_interconnects string
SQL> create pfile='/u01/oracle/db/dbs/ora10g_robin.ora' from spfile; -->先備份spfile
File created.
SQL> alter system set cluster_database=false scope=spfile sid='*'; -->修改為非叢集資料庫,該參數為靜態參數,需要使用scope=spfile
System altered.
oracle@bo2dbp:~> srvctl stop database -d ora10g -->關閉資料庫
oracle@bo2dbp:~> srvctl start instance -d ora10g -i ora10g1 -o mount -->啟動單個執行個體到mount狀態
oracle@bo2dbp:~> sqlplus / as sysdba
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
ora10g1 MOUNTED
SQL> alter database archivelog; -->改變資料庫到歸檔模式
Database altered.
SQL> alter system set cluster_database=true scope=spfile sid='*'; -->在將資料庫改為叢集模式
System altered.
SQL> ho srvctl stop instance -d ora10g -i ora10g1 -->關閉當前執行個體
SQL> ho srvctl start database -d ora10g -->啟動叢集資料庫
SQL> archive log list;
ORA-03135: connection lost contact
SQL> conn / as sysdba
Connected.
SQL> archive log list; -->查看歸檔模式
Database log mode Archive Mode -->已經處于歸檔模式
Automatic archival Enabled -->自動歸檔
Archive destination USE_DB_RECOVERY_FILE_DEST -->歸檔位置為參數DB_RECOVERY_FILE_DEST的值
Oldest online log sequence 60 -->下面是sequence相關資訊
Next log sequence to archive 61
Current log sequence 61
SQL> show parameter db_recovery_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string +REV
db_recovery_file_dest_size big integer 2G
4、歸檔驗證
SQL> select inst_id,name,thread#,sequence#,status from gv$archived_log; -->當前無任何歸檔日誌
no rows selected
SQL> alter system switch logfile; -->在執行個體1上進行歸檔
System altered.
SQL> col name format a65
SQL> select inst_id,name,thread#,sequence#,status from gv$archived_log; -->查看到sequence為61的日誌已經歸檔
INST_ID NAME THREAD# SEQUENCE# S
---------- ----------------------------------------------------------------- ---------- ---------- -
1 +REV/ora10g/archivelog/2012_12_24/thread_1_seq_61.459.802892953 1 61
SQL> select name,thread#,sequence#,status from v$archived_log; -->下面是從執行個體層級的視圖來查看
NAME THREAD# SEQUENCE# S
----------------------------------------------------------------- ---------- ---------- -
+REV/ora10g/archivelog/2012_12_24/thread_1_seq_61.459.802892953 1 61 A
SQL> conn system/oracle@ora10g2 -->串連到執行個體2
Connected.
SQL> show parameter instance_name;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
instance_name string ora10g2
SQL> alter system switch logfile; -->在執行個體2上進行歸檔
System altered.
SQL> select inst_id,name,thread#,sequence#,status from gv$archived_log;
-->可以看到sequence為43的日誌已經歸檔
-->注意這個視圖查詢時同一個歸檔日誌除了出現在自身執行個體中外,對另外的執行個體也是可見的
INST_ID NAME THREAD# SEQUENCE# S
---------- ----------------------------------------------------------------- ---------- ---------- -
1 +REV/ora10g/archivelog/2012_12_24/thread_1_seq_61.459.802892953 1 61 A
1 +REV/ora10g/archivelog/2012_12_24/thread_2_seq_43.458.802893283 2 43 A
2 +REV/ora10g/archivelog/2012_12_24/thread_1_seq_61.459.802892953 1 61 A
2 +REV/ora10g/archivelog/2012_12_24/thread_2_seq_43.458.802893283 2 43 A
-->查看日誌的狀態
-->注意這個v$log視圖將兩個執行個體上的組及狀態都顯示出來了
-->在這裡用thread#來區分,thread#為1表示執行個體1上的日誌組有1,2,且1處於current狀態.thread#2類似.
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 62 52428800 2 NO CURRENT 4314741 24-DEC-12
2 1 61 52428800 2 YES ACTIVE 4312116 24-DEC-12
3 2 43 52428800 2 YES ACTIVE 4312300 24-DEC-12
4 2 44 52428800 2 NO CURRENT 4315097 24-DEC-12
-->Author: Robinson
-->歸檔當前日誌,注意該命令在單一實例下等同於alter system switch logfile
-->在rac環境下則不同,那就是所有執行個體上的current日誌都將會被歸檔
SQL> alter system archive log current;
System altered.
-->下面的查詢正好驗證了上面的描述
-->日誌62與44正是剛剛上面的命令同時產生的歸檔日誌
SQL> select inst_id,name,thread#,sequence#,status from gv$archived_log;
INST_ID NAME THREAD# SEQUENCE# S
---------- ----------------------------------------------------------------- ---------- ---------- -
2 +REV/ora10g/archivelog/2012_12_24/thread_1_seq_61.459.802892953 1 61 A
2 +REV/ora10g/archivelog/2012_12_24/thread_2_seq_43.458.802893283 2 43 A
2 +REV/ora10g/archivelog/2012_12_24/thread_2_seq_44.456.802894343 2 44 A
2 +REV/ora10g/archivelog/2012_12_24/thread_1_seq_62.457.802894341 1 62 A
1 +REV/ora10g/archivelog/2012_12_24/thread_1_seq_61.459.802892953 1 61 A
1 +REV/ora10g/archivelog/2012_12_24/thread_2_seq_43.458.802893283 2 43 A
1 +REV/ora10g/archivelog/2012_12_24/thread_2_seq_44.456.802894343 2 44 A
1 +REV/ora10g/archivelog/2012_12_24/thread_1_seq_62.457.802894341 1 62 A
8 rows selected.
oracle視頻教程請關注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html