您好,登錄后才能下訂單哦!
前面我們有講到Oracle 11G DataGuard的搭建,10G的搭建也是大同小異.不過Oracle 10G不支持Standby open
環境:
角色 | 主機名 | IP | 數據庫版本 | 操作系統版本 |
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
創建必要的目錄(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
查看當前的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;
創建原始參數文件用于備份(fdb1)
create pfile='/tmp/fengdb.pfile.ori' from spfile;
修改相關參數用于DataGuard環境,注意此處與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; 否則可能出現ORA-16019: cannot use LOG_ARCHIVE_DEST_1 with LOG_ARCHIVE_DEST or LOG_ARCHIVE_DUPLEX_DEST 以及上面都是直接修改spfile的,不修改當前運行中的參數 scope=spfile |
執行上面的語句其實就是改了下面的一些參數
*.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='' |
重啟數據庫以使數據庫生效(fdb1)
shutdown immediate startup
修改監聽(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';
將備份及監聽文件和密碼文件全部復制到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上執行如下對數據庫進行恢復(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'
備庫復制控制文件(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
啟動至mount狀態進行數據的恢復
RMAN> startup mount; RMAN> restore database;
啟動備庫應用日志
SQL> alter database recover managed standby database using current logfile disconnect from session;
創建參數文件
SQL> create spfile from pfile='/tmp/fengdb.pfile';
注意:Oracle 10G與11G的區別: 10G備庫只能啟動到mount狀態,而11G可以啟動到open read only. |
檢查日志是否同步(fdb1,fdb2)
select sequence#,applied from v$archived_log;
也可以試著切換下日志
//切換日志 alter system switch logfile; select sequence#,applied from v$archived_log;
在主庫:(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;
如果在備庫上
SQL> select sequence#,applied from v$archived_log;
no rows selected
而且監聽都是正常的,則有可能就是密碼沒復制過來
保持主庫密碼和備庫密碼一致
復制密碼文件(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;
//在執行這條的時候,如果出現
ERROR at line 1:
ORA-01665: control file is not a standby control file
則是沒有執行alter database commit to switchover to physical standby with session shutdown;
若出現ORA-38500: USING CURRENT LOGFILE option not available without stand
這種情況出現在主備切換之后,備再切換回主的情況下出現
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;
注意: 若出現ORA-16139: media recovery required,執行如下語句: SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION; SQL> alter database commit to switchover to primary; 如果出現,則可能是已打開了會話,加上with session shutdown強制關閉繪畫 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;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。