您好,登錄后才能下訂單哦!
需求:在同一個環境下新建Standby RAC庫,即和Primary RAC在相同的磁盤組。
說明:生產環境一般不建議這樣配置DG,因為存儲層面是相同磁盤組,災備的實際意義不大。我這里是用作讀寫分離。
基本信息:
db_name: jyzhao
Primary RAC db_unique_name:jyzhao
Standby RAC db_unique_name:jyzhaodg
Standby RAC instance_name: jyzhaodg1, jyzhaodg2
版本:GI 11.2.0.4 + DB 11.2.0.4
確認RAC Standby存儲是在和RAC Primary相同的ASM磁盤組內(PS:災備效果不明顯),創建RAC Standby存儲目錄(根據db_unique_name)
mkdir +DATA/JYZHAODG mkdir +FRA/JYZHAODG
cd $ORACLE_HOME/network/admin/
cat tnsnames.ora
添加主庫備庫的連接信息(所有節點):
JYZHAO = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oradb-scan)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = jyzhao) ) ) jyzhaodg = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oradb-scan)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = jyzhaodg) ) )
節點1:
export ORACLE_SID=jyzhaodg1 密碼文件; cd $ORACLE_HOME/dbs orapwd file=orapwjyzhaodg1 password=oracle entries=5 或者直接copy之前的密碼文件,然后mv重命名: cp orapwjyzhao1 orapwjyzhaodg1
節點2:
export ORACLE_SID=jyzhaodg2 密碼文件; cd $ORACLE_HOME/dbs orapwd file=orapwjyzhaodg2 password=oracle entries=5 或者直接copy之前的密碼文件,然后mv重命名: cp orapwjyzhao2 orapwjyzhaodg2
最后測試相互連接可用
sqlplus sys/oracle@jyzhao as sysdba sqlplus sys/oracle@jyzhaodg as sysdba
vi backup.sh
備份腳本如下:
rman target / <<EOF run { allocate channel c1 device type disk; allocate channel c2 device type disk; backup as compressed backupset database filesperset 1 format '/u01/orabak/salehrdb_%d_%T_%s.bak'; backup current controlfile format '/u01/orabak/control.bak'; release channel c1; release channel c2; } EOF
后臺執行備份任務:
nohup sh backup.sh &
注意:如果使用backup as copy database format方案,就不用再備份到磁盤后再恢復了,可以節省時間。
backup as copy 方案備份腳本 backupcp.sh內容如下:
rman target / <<EOF run { allocate channel c1 device type disk; allocate channel c2 device type disk; backup as copy database format '+DATA/JYZHAODG/DATAFILE/%u.dbf'; release channel c1; release channel c2; } EOF
注意:這種方式,路徑包含的目錄需手動創建。
mkdir +DATA/JYZHAODG/DATAFILE
確認當前環境ORACLE_SID:
echo $ORACLE_SID export ORACLE_SID=jyzhao1
根據spfile文件創建pfile:
create pfile='/tmp/pfile.ora' from spfile;
Primary RAC 添加參數
--為不停止primary RAC,所以盡可能動態修改參數: show parameter log_archive_config show parameter db_file_name_convert show parameter log_file_name_convert show parameter fal_client show parameter fal_server show parameter log_archive_dest_3 alter system set log_archive_config='dg_config=(jyzhao,jyzhaodg)'; alter system set db_file_name_convert='+DATA/jyzhaodg','+DATA/jyzhao' scope=spfile; alter system set log_file_name_convert='+DATA/jyzhaodg','+DATA/jyzhao' scope=spfile; alter system set fal_client='jyzhao'; alter system set fal_server='jyzhaodg'; alter system set log_archive_dest_3='service=jyzhaodg valid_for=(online_logfiles,primary_role) db_unique_name=jyzhaodg'; --暫時defer傳輸鏈路,防止此時主庫告警生成相關錯誤 SQL> alter system set log_archive_dest_state_3=defer;
根據主庫之前導出的參數文件修改備庫的參數文件:
cp /tmp/pfile.ora /tmp/pfile_std.ora
vi /tmp/pfile_std.ora
*._high_priority_processes='LMS*' *.audit_file_dest='/u01/app/oracle/admin/jyzhaodg/adump' *.audit_trail='db' *.cluster_database=true *.compatible='11.2.0.4.0' *.control_files='+DATA/jyzhaodg/controlfile/current.260.931878631','+FRA/jyzhaodg/controlfile/current.256.931878631' *.db_block_size=8192 *.db_create_file_dest='+DATA' *.db_domain='' *.db_name='jyzhao' *.db_recovery_file_dest='+FRA' *.db_recovery_file_dest_size=4621074432 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=jyzhaoXDB)' jyzhaodg2.instance_number=2 jyzhaodg1.instance_number=1 *.log_archive_format='%t_%s_%r.dbf' *.memory_target=313286272 *.open_cursors=300 *.processes=150 *.remote_listener='oradb-scan:1521' *.remote_login_passwordfile='exclusive' jyzhaodg2.thread=2 jyzhaodg1.thread=1 jyzhaodg2.undo_tablespace='UNDOTBS2' jyzhaodg1.undo_tablespace='UNDOTBS1' #add db_unique_name='jyzhaodg' log_archive_config='dg_config=(jyzhao,jyzhaodg)'#db_unique_name db_file_name_convert='+DATA/jyzhao','+DATA/jyzhaodg' log_file_name_convert='+DATA/jyzhao','+DATA/jyzhaodg' standby_file_management=auto fal_client='jyzhaodg'#tnsnames.ora fal_server='jyzhao'#salehrdb log_archive_dest_3='service=jyzhao valid_for=(online_logfiles,primary_role) db_unique_name=jyzhao'
主要是注意后面#add之后的內容。
在ASM中創建standby的spfile,并確定各節點的參數文件內容指向磁盤中的spfile。
節點1:
echo $ORACLE_SID export ORACLE_SID=jyzhaodg1 create spfile='+DATA/jyzhaodg/spfilejyzhaodg.ora' from pfile='/tmp/pfile_std.ora'; -- cat initjyzhaodg1.ora SPFILE='+DATA/jyzhaodg/spfilejyzhaodg.ora'
節點2:
echo $ORACLE_SID export ORACLE_SID=jyzhaodg2 cat initjyzhaodg2.ora SPFILE='+DATA/jyzhaodg/spfilejyzhaodg.ora'
創建adump目錄(所有節點)
mkdir -p /u01/app/oracle/admin/jyzhaodg/adump
節點1:
echo $ORACLE_SID export ORACLE_SID=jyzhaodg1 startup nomount
節點2:
echo $ORACLE_SID export ORACLE_SID=jyzhaodg2 startup nomount
在Primary RAC上創建備庫使用的控制文件:
echo $ORACLE_SID export ORACLE_SID=jyzhao1 SQL> alter database create standby controlfile as '/tmp/control01.ctlbak';
在Standby RAC的節點1上恢復控制文件并啟動到mount:
echo $ORACLE_SID export ORACLE_SID=jyzhaodg1 restore controlfile from '/tmp/control01.ctlbak'; alter database mount; crosscheck backupset; --如果是之前copy到磁盤組的備份沒加載到控制文件中,可以手動catalog catalog start with '+data/jyzhaodg/DATAFILE'; --同樣,如果是之前的備份集沒加載到控制文件中,一樣手動catalog catalog start with '/u01/orabak/';
查看此時standby記錄的各文件路徑是否符合預期:
SQL> select name from v$datafile; NAME -------------------------------------------------------------------------------- +DATA/jyzhaodg/datafile/system.256.931878537 +DATA/jyzhaodg/datafile/sysaux.257.931878537 +DATA/jyzhaodg/datafile/undotbs1.258.931878537 +DATA/jyzhaodg/datafile/users.259.931878537 +DATA/jyzhaodg/datafile/undotbs2.264.931878827 +DATA/jyzhaodg/datafile/dbs_d_jingyu.268.937515173 6 rows selected. SQL> select member from v$logfile; MEMBER -------------------------------------------------------------------------------- +DATA/jyzhaodg/onlinelog/group_2.262.931878637 +FRA/jyzhao/onlinelog/group_2.258.931878639 +DATA/jyzhaodg/onlinelog/group_1.261.931878635 +FRA/jyzhao/onlinelog/group_1.257.931878637 +DATA/jyzhaodg/onlinelog/group_3.265.931879021 +FRA/jyzhao/onlinelog/group_3.259.931879023 +DATA/jyzhaodg/onlinelog/group_4.266.931879027 +FRA/jyzhao/onlinelog/group_4.260.931879029 8 rows selected. SQL> select name from v$tempfile; NAME -------------------------------------------------------------------------------- +DATA/jyzhaodg/tempfile/temp.263.931878661 SQL> select name from v$controlfile; NAME -------------------------------------------------------------------------------- +DATA/jyzhaodg/controlfile/current.288.937645851 +FRA/jyzhaodg/controlfile/current.275.937645851
發現日志文件有不符合預期的路徑,進行修正:
SQL> show parameter convert NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_file_name_convert string +DATA/jyzhao, +DATA/jyzhaodg log_file_name_convert string +DATA/jyzhao, +DATA/jyzhaodg SQL> alter system set log_file_name_convert='+DATA/jyzhao','+DATA/jyzhaodg','+FRA/jyzhao','+FRA/jyzhaodg' scope=spfile; SQL> shutdown immediate; ORA-01109: database not open Database dismounted. ORACLE instance shut down. SQL> startup mount; ORACLE instance started. Total System Global Area 313159680 bytes Fixed Size 2252824 bytes Variable Size 222302184 bytes Database Buffers 83886080 bytes Redo Buffers 4718592 bytes Database mounted. SQL> select member from v$logfile; MEMBER -------------------------------------------------------------------------------- +DATA/jyzhaodg/onlinelog/group_2.262.931878637 +FRA/jyzhaodg/onlinelog/group_2.258.931878639 +DATA/jyzhaodg/onlinelog/group_1.261.931878635 +FRA/jyzhaodg/onlinelog/group_1.257.931878637 +DATA/jyzhaodg/onlinelog/group_3.265.931879021 +FRA/jyzhaodg/onlinelog/group_3.259.931879023 +DATA/jyzhaodg/onlinelog/group_4.266.931879027 +FRA/jyzhaodg/onlinelog/group_4.260.931879029 8 rows selected.
Standby RAC節點1:
確定ORACLE_SID變量:
echo $ORACLE_SID export ORACLE_SID=jyzhaodg1
a. 如果是使用從備份集恢復的方式
vi restore.sh
rman target / <<EOF! > db_restore.log run { allocate channel d1 type disk; allocate channel d2 type disk; restore database; release channel d1; release channel d2; } exit; EOF!
nohup sh restore.sh &
b. 如果是直接使用copy到磁盤組的
直接switch database to copy即可。
RMAN> switch database to copy; using target database control file instead of recovery catalog datafile 1 switched to datafile copy "+DATA/jyzhaodg/datafile/0eru6m4s.dbf" datafile 2 switched to datafile copy "+DATA/jyzhaodg/datafile/0fru6m4s.dbf" datafile 3 switched to datafile copy "+DATA/jyzhaodg/datafile/0hru6meo.dbf" datafile 4 switched to datafile copy "+DATA/jyzhaodg/datafile/0iru6mg5.dbf" datafile 5 switched to datafile copy "+DATA/jyzhaodg/datafile/0jru6mg6.dbf" datafile 6 switched to datafile copy "+DATA/jyzhaodg/datafile/0gru6men.dbf"
確認Primary RAC的日志傳輸鏈路打開:
echo $ORACLE_SID export ORACLE_SID=jyzhao1 SQL> alter system set log_archive_dest_state_3=enable;
Standby RAC節點1在mount狀態下開啟日志應用:
echo $ORACLE_SID export ORACLE_SID=jyzhaodg1 SQL> alter database recover managed standby database disconnect from session;
停止備庫應用:
SQL> alter database recover managed standby database cancel;
查看日志信息:
SQL> select * from v$Log; GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME ---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------ ------------ ------------ 1 1 69 52428800 512 2 YES CURRENT 2450934 03-MAR-17 2.8147E+14 2 1 0 52428800 512 2 YES UNUSED 2440706 03-MAR-17 2450934 03-MAR-17 3 2 0 52428800 512 2 YES UNUSED 2440817 03-MAR-17 2450939 03-MAR-17 4 2 36 52428800 512 2 YES CURRENT 2450939 03-MAR-17 2.8147E+14 SQL> col member for a70 SQL> select group#, type, member from v$logfile; GROUP# TYPE MEMBER ---------- ------- ---------------------------------------------------------------------- 2 ONLINE +DATA/jyzhaodg/onlinelog/group_2.298.937648563 2 ONLINE +FRA/jyzhaodg/onlinelog/group_2.278.937648565 1 ONLINE +DATA/jyzhaodg/onlinelog/group_1.297.937648559 1 ONLINE +FRA/jyzhaodg/onlinelog/group_1.279.937648561 3 ONLINE +DATA/jyzhaodg/onlinelog/group_3.299.937648567 3 ONLINE +FRA/jyzhaodg/onlinelog/group_3.389.937648569 4 ONLINE +DATA/jyzhaodg/onlinelog/group_4.300.937648573 4 ONLINE +FRA/jyzhaodg/onlinelog/group_4.390.937648573 8 rows selected.
根據檢查結果,合理為數據庫添加standby logfile:
alter database add standby logfile thread 1 group 11 ('+DATA','+FRA') size 52428800; alter database add standby logfile thread 1 group 12 ('+DATA','+FRA') size 52428800; alter database add standby logfile thread 1 group 13 ('+DATA','+FRA') size 52428800; alter database add standby logfile thread 2 group 21 ('+DATA','+FRA') size 52428800; alter database add standby logfile thread 2 group 22 ('+DATA','+FRA') size 52428800; alter database add standby logfile thread 2 group 23 ('+DATA','+FRA') size 52428800;
添加完再次查看:
SQL> select group#, type, member from v$logfile; GROUP# TYPE MEMBER ---------- ------- ---------------------------------------------------------------------- 2 ONLINE +DATA/jyzhaodg/onlinelog/group_2.298.937648563 2 ONLINE +FRA/jyzhaodg/onlinelog/group_2.278.937648565 1 ONLINE +DATA/jyzhaodg/onlinelog/group_1.297.937648559 1 ONLINE +FRA/jyzhaodg/onlinelog/group_1.279.937648561 3 ONLINE +DATA/jyzhaodg/onlinelog/group_3.299.937648567 3 ONLINE +FRA/jyzhaodg/onlinelog/group_3.389.937648569 4 ONLINE +DATA/jyzhaodg/onlinelog/group_4.300.937648573 4 ONLINE +FRA/jyzhaodg/onlinelog/group_4.390.937648573 11 STANDBY +DATA/jyzhaodg/onlinelog/group_11.301.937648773 11 STANDBY +FRA/jyzhaodg/onlinelog/group_11.391.937648775 12 STANDBY +DATA/jyzhaodg/onlinelog/group_12.302.937648777 GROUP# TYPE MEMBER ---------- ------- ---------------------------------------------------------------------- 12 STANDBY +FRA/jyzhaodg/onlinelog/group_12.392.937648779 13 STANDBY +DATA/jyzhaodg/onlinelog/group_13.303.937648779 13 STANDBY +FRA/jyzhaodg/onlinelog/group_13.393.937648781 21 STANDBY +DATA/jyzhaodg/onlinelog/group_21.304.937648783 21 STANDBY +FRA/jyzhaodg/onlinelog/group_21.394.937648783 22 STANDBY +DATA/jyzhaodg/onlinelog/group_22.305.937648785 22 STANDBY +FRA/jyzhaodg/onlinelog/group_22.395.937648787 23 STANDBY +DATA/jyzhaodg/onlinelog/group_23.306.937648787 23 STANDBY +FRA/jyzhaodg/onlinelog/group_23.396.937648789 20 rows selected.
繼續開啟備庫應用,確定恢復完成日志沒報錯信息后取消日志應用,打開數據庫,開啟ADG:
alter database recover managed standby database disconnect from session; alter database recover managed standby database cancel; alter database open; alter database recover managed standby database using current logfile disconnect from session;
查看DG同步狀態:
SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS, FORCE_LOGGING, DATAGUARD_BROKER, GUARD_STATUS FROM V$DATABASE; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS FOR DATAGUAR GUARD_S -------------------- ---------------- -------------------- --- -------- ------- READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED NO DISABLED NONE SQL> set lines 1000 SQL> select * from v$dataguard_stats; NAME VALUE UNIT TIME_COMPUTED DATUM_TIME -------------------------------- ---------------------------------------------------------------- ------------------------------ ------------------------------ ------------------------------ transport lag +00 00:09:37 day(2) to second(0) interval 03/03/2017 10:03:20 03/03/2017 10:03:13 apply lag +00 00:09:38 day(2) to second(0) interval 03/03/2017 10:03:20 03/03/2017 10:03:13 apply finish time day(2) to second(3) interval 03/03/2017 10:03:20 estimated startup time 40 second 03/03/2017 10:03:20 --可以在Primary RAC上歸檔當前日志模擬業務切換歸檔: SQL> SELECT OPEN_MODE, DATABASE_ROLE, SWITCHOVER_STATUS, FORCE_LOGGING, DATAGUARD_BROKER, GUARD_STATUS FROM V$DATABASE; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS FOR DATAGUAR GUARD_S -------------------- ---------------- -------------------- --- -------- ------- READ WRITE PRIMARY TO STANDBY NO DISABLED NONE SQL> alter system archive log current; System altered. --再次在Standby RAC上查看DG同步狀態: SQL> r 1* select * from v$dataguard_stats NAME VALUE UNIT TIME_COMPUTED DATUM_TIME -------------------------------- ---------------------------------------------------------------- ------------------------------ ------------------------------ ------------------------------ transport lag +00 00:00:00 day(2) to second(0) interval 03/03/2017 10:04:45 03/03/2017 10:04:44 apply lag +00 00:00:00 day(2) to second(0) interval 03/03/2017 10:04:45 03/03/2017 10:04:44 apply finish time day(2) to second(3) interval 03/03/2017 10:04:45 estimated startup time 40 second 03/03/2017 10:04:45
至此,已完成RAC Standby庫在同環境下的創建。
我們可以將RAC Standby也加入到crs資源中:
[oracle@oradb23 ~]$ srvctl add database -d jyzhaodg -o $ORACLE_HOME -i jyzhaodg1 -n jyzhao [oracle@oradb23 ~]$ srvctl add instance -d jyzhaodg -i jyzhaodg1 -n oradb23 [oracle@oradb23 ~]$ srvctl add instance -d jyzhaodg -i jyzhaodg2 -n oradb24 --啟動數據庫 [oracle@oradb23 ~]$ srvctl start database -d salehrdg --查看資源狀態: [grid@oradb23 ~]$ crsctl stat res -t
總結:同環境下搭建Standby RAC,最重要的注意事項就是一定要細心,操作前確保自己操作的是正確的ORACLE_SID,備庫的路徑也要反復確認無誤再操作。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。