您好,登錄后才能下訂單哦!
前面我們有講到Oracle 11G DataGuard的搭建,10G的搭建也是大同小異.不過(guò)Oracle 10G不支持Standby open
環(huán)境:
角色 | 主機(jī)名 | IP | 數(shù)據(jù)庫(kù)版本 | 操作系統(tǒng)版本 |
Primary | fdb1 | 192.168.10.8 | 10.2.0.1 | CentOS 5.11 x86_64 |
Standby | fdb2 | 192.168.10.9 | 10.2.0.1 | CentOS 5.11 x86_64 |
在fdb1的/etc/hosts中加入(fdb1)
127.0.0.1 fdb1 192.168.10.9 fdb2
在fdb2的/etc/hosts中加入(fdb2)
127.0.0.1 fdb2 192.168.10.8 fdb1
創(chuàng)建必要的目錄(fdb1,fdb2)
mkdir -p /opt/oracle/flash_recovery_area mkdir -p /opt/oracle/admin/fengdb/{a,b,c,u}dump mkdir /opt/oracle/oradata/fengdb -p mkdir -p /opt/oracle/dbackup mkdir -p /opt/oracle/flash_recovery_area/fengdb/archivelog
查看當(dāng)前的redo組(fdb1)
select group#,member from v$logfile; //增加standby日志組 alter database add standby logfile ('/opt/oracle/oradata/fengdb/standby04.log') size 50m; alter database add standby logfile ('/opt/oracle/oradata/fengdb/standby05.log') size 50m; alter database add standby logfile ('/opt/oracle/oradata/fengdb/standby06.log') size 50m; alter database add standby logfile ('/opt/oracle/oradata/fengdb/standby07.log') size 50m;
創(chuàng)建原始參數(shù)文件用于備份(fdb1)
create pfile='/tmp/fengdb.pfile.ori' from spfile;
修改相關(guān)參數(shù)用于DataGuard環(huán)境,注意此處與Oracle 11G不同(fdb1)
alter system set db_unique_name=fdb1 scope=spfile; alter system set log_archive_config='dg_config=(fdb1,fdb2)' scope=spfile; alter system set log_archive_dest_1= 'location=/opt/oracle/flash_recovery_area/fengdb/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=fdb1' scope=spfile; alter system set log_archive_dest_2= 'service=fdb2 async valid_for=(online_logfiles,primary_role) db_unique_name=fdb2' scope=spfile; alter system set log_archive_dest='' scope=spfile; alter system set log_archive_dest_state_1=enable scope=spfile; alter system set log_archive_dest_state_2=enable scope=spfile; alter system set standby_file_management=auto scope=spfile; alter system set fal_server=fdb2 scope=spfile; alter system set fal_client=fdb1 scope=spfile; alter system set db_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area' scope=spfile; alter system set log_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area' scope=spfile;
注意:與Oracle 11G不同的地方有: alter system set log_archive_dest='' scope=spfile; 否則可能出現(xiàn)ORA-16019: cannot use LOG_ARCHIVE_DEST_1 with LOG_ARCHIVE_DEST or LOG_ARCHIVE_DUPLEX_DEST 以及上面都是直接修改spfile的,不修改當(dāng)前運(yùn)行中的參數(shù) scope=spfile |
執(zhí)行上面的語(yǔ)句其實(shí)就是改了下面的一些參數(shù)
*.db_unique_name='fdb1' *.log_archive_config='dg_config=(fdb1,fdb2)' *.log_archive_dest_1='location=/opt/oracle/flash_recovery_area/fengdb/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=fdb1' *.log_archive_dest_2='service=fdb2 async valid_for=(online_logfiles,primary_role) db_unique_name=fdb2' *.log_archive_dest_state_1='ENABLE' *.log_archive_dest_state_2='ENABLE' *.standby_file_management='AUTO' *.fal_client='fdb1' *.fal_server='fdb2' *.db_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area' *.log_file_name_convert='/opt/oracle/flash_recovery_area','/opt/oracle/flash_recovery_area' *.log_archive_dest='' |
重啟數(shù)據(jù)庫(kù)以使數(shù)據(jù)庫(kù)生效(fdb1)
shutdown immediate startup
修改監(jiān)聽(fdb1)
vim $ORACLE_HOME/network/admin/tnsnames.ora
fdb1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = fdb1)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = fdb1) ) ) fdb2 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = fdb2)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = fdb2) ) )
RMAN備份(fdb1)
rman target / run{ allocate channel c1 type disk; backup format '/opt/oracle/dbackup/fengdb_%T_%s_%p' database; sql 'alter system archive log current'; backup format '/opt/oracle/dbackup/archive_log_%T_%s_%p' archivelog all; backup spfile format '/opt/oracle/dbackup/spfile_%u_%T.bak'; release channel c1; } copy current controlfile for standby to '/opt/oracle/dbackup/standby.ctl';
將備份及監(jiān)聽文件和密碼文件全部復(fù)制到fdb2上(fdb1)
scp -r /opt/oracle/dbackup/* fdb2:/opt/oracle/dbackup
scp -r $ORACLE_HOME/network/admin/* fdb2:$ORACLE_HOME/network/admin/
scp -r $ORACLE_HOME/dbs/* fdb2:$ORACLE_HOME/dbs/
在fdb2上執(zhí)行如下對(duì)數(shù)據(jù)庫(kù)進(jìn)行恢復(fù)(fdb2)
RMAN> startup nomount;
RMAN> restore spfile to pfile '/tmp/fengdb.pfile' from '/opt/oracle/dbackup/spfile_rmrioont_20161019.bak';
RMAN> shutdown immediate;
然后修改/etc/fengdb.pfile成如下的紅色部分
*.db_unique_name='fdb2'
*.fal_client='fdb2'
*.fal_server='fdb1'
*.log_archive_config='dg_config=(fdb2,fdb1)'
*.log_archive_dest_1='location=/opt/oracle/flash_recovery_area/fengdb/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=fdb2'
*.log_archive_dest_2='service=fdb1 async valid_for=(online_logfiles,primary_role) db_unique_name=fdb1'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
備庫(kù)復(fù)制控制文件(fdb2)
cp /opt/oracle/dbackup/standby.ctl /opt/oracle/oradata/fengdb/control01.ctl
cp /opt/oracle/dbackup/standby.ctl /opt/oracle/oradata/fengdb/control02.ctl
cp /opt/oracle/dbackup/standby.ctl /opt/oracle/oradata/fengdb/control03.ctl
啟動(dòng)至mount狀態(tài)進(jìn)行數(shù)據(jù)的恢復(fù)
RMAN> startup mount; RMAN> restore database;
啟動(dòng)備庫(kù)應(yīng)用日志
SQL> alter database recover managed standby database using current logfile disconnect from session;
創(chuàng)建參數(shù)文件
SQL> create spfile from pfile='/tmp/fengdb.pfile';
注意:Oracle 10G與11G的區(qū)別: 10G備庫(kù)只能啟動(dòng)到mount狀態(tài),而11G可以啟動(dòng)到open read only. |
檢查日志是否同步(fdb1,fdb2)
select sequence#,applied from v$archived_log;
也可以試著切換下日志
//切換日志 alter system switch logfile; select sequence#,applied from v$archived_log;
在主庫(kù):(fdb1)
select dest_name,status,error from v$archive_dest; alter system set log_archive_dest_state_2= enable;
查詢角色(fdb1,fdb2)
select open_mode,database_role from v$database;
如果在備庫(kù)上
SQL> select sequence#,applied from v$archived_log;
no rows selected
而且監(jiān)聽都是正常的,則有可能就是密碼沒(méi)復(fù)制過(guò)來(lái)
保持主庫(kù)密碼和備庫(kù)密碼一致
復(fù)制密碼文件(fdb1)
scp $ORACLE_HOME/dbs/orapw$ORACLE_SID fdb2:$ORACLE_HOME/dbs/orapw$ORACLE_SID
Oracle 10G主備切換
db1---primary/db2---standby ===》db2--primary/db1--standby
[oracle@fdb1 ~]$ lsnrctl stop
(fdb1)SQL> alter database commit to switchover to physical standby with session shutdown;
(fdb1)SQL> shutdown immediate;
(fdb1)SQL> startup mount;
(fdb1)SQL> alter database recover managed standby database using current logfile disconnect from session;
//在執(zhí)行這條的時(shí)候,如果出現(xiàn)
ERROR at line 1:
ORA-01665: control file is not a standby control file
則是沒(méi)有執(zhí)行alter database commit to switchover to physical standby with session shutdown;
若出現(xiàn)ORA-38500: USING CURRENT LOGFILE option not available without stand
這種情況出現(xiàn)在主備切換之后,備再切換回主的情況下出現(xiàn)
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/opt/oracle/oradata/fengdb/redo03.log
/opt/oracle/oradata/fengdbredo02.log
/opt/oracle/oradata/fengdb/redo01.log
增加standby flog即可
alter database add standby logfile ('/opt/oracle/oradata/fengdb/standby04.log') size 50m;
alter database add standby logfile ('/opt/oracle/oradata/fengdb/standby05.log') size 50m;
alter database add standby logfile ('/opt/oracle/oradata/fengdb/standby06.log') size 50m;
alter database add standby logfile ('/opt/oracle/oradata/fengdb/standby07.log') size 50m;
[oracle@fdb1 ~]$ lsnrctl start
(fdb2)SQL> alter database commit to switchover to primary;
注意: 若出現(xiàn)ORA-16139: media recovery required,執(zhí)行如下語(yǔ)句: SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION; SQL> alter database commit to switchover to primary; 如果出現(xiàn),則可能是已打開了會(huì)話,加上with session shutdown強(qiáng)制關(guān)閉繪畫 ERROR at line 1: ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected SQL> alter database commit to switchover to primary WITH SESSION SHUTDOWN; |
(fdb2)SQL> shutdown immediate;
(fdb2)SQL> startup;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。