Oracle DataGuard是一種數據庫級別的HA方案,最主要功能是冗災、數據保護、故障恢復等。
在生產數據庫的"事務一致性"時,使用生產庫的物理全備份(或物理COPY)創建備庫,備庫會通過生產庫傳輸過來的歸檔日志(或重做條目)自動維護備用數據庫。將重做數據應用到備用庫。本文介紹使用RMAN備份創建備庫(dataguard).
一:Oracle DataGuard環境概述
1.軟件環境
操作系統Red Linux Enterprise as 5
數據庫版本Oracle 10g release 2
2.primary databae
IP:192.168.18.1
Oracle_SID=db1
db_unique_name=db1
3.standby database
IP:192.168.18.2
Oracle_SID=standby
db_unique_name=standby
二,主數據庫(db1)做准備
1.設置主數據庫為Force logging
- SQL> alter database force logging;
2.創建密碼文件
- cd $Oracle_HOME/dbs/
- orapwdfile=orapwdb1 passWord=123456 force=y
3.修改主庫的初始化參數
- alter system set log_archive_config='dg_config=(db1,standby)' scope=both;
- alter system set log_archive_dest_1='location=/u01/db1/arch' scope=both;
- alter system set db_unique_name='db1' scope=both;
4.生成數據庫備份
- RMAN> connect target sys/123456
- RMAN> backup database format='/Oracle/rmanback/%d_%s.dbf' plus archivelog;
- [oracle@Oracle rmanback]$ ls
- DB1_1.dbfDB1_2.dbf
5.生成備庫的control file
- SQL>alter database create standby controlfile as '/Oracle/rmanback/ctontrl01.ctl
6.配置listener.ora 和tnsnames.ora文件
啟動lintener.ora,
- [oracle@Oracle dbs]$ lsnrctl status
- LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 14-JUN-2009 02:54:29
- Service "db1" has 1 instance(s).
- Instance "db1", status READY, has 1 handler(s) for this service...
- Service "db1_XPT" has 1 instance(s).
- Instance "db1", status READY, has 1 handler(s) for this service...
- The command completed successfully
配置rnsnames.ora
- vi $Oracle_HOME/network/admin/tnsnames.ora
- db1 =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.18.1)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = db1)
- standby =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.18.2)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SERVICE_NAME = standby)
- )
- )
三.創建standby database
1.設置環境變量並安裝Oracle軟件
- #環境變量設成與主庫一樣
- #只安裝軟件不安裝庫
- ./runInstaller –silent –responseFile /tmp/installOracle.rsp
2.建立相關的目錄
- cd $Oracle_HOME/dbs/
- orapwdfile=orapwSID passWord=123456 force=y
- #注要密碼要與主庫的一樣, 否則會歸檔失敗
3.建立密碼文件
- cd $Oracle_HOME/dbs/
- orapwd file=orapwSID passWord=123456 force=y
- #注要密碼要與主庫的一樣, 否則會歸檔失敗
3.建立參數文件(pfile)
- db_name = standby
- shared_pool_size = 120M
- undo_management = AUTO
- undo_tablespace = undotbs
- sga_max_size = 200M
- sga_target = 160M
- db_2k_cache_size = 4M
- standby_file_management=AUTO
- fal_server='db1'
- fal_clIEnt='standby'
- log_archive_dest_1='location=/u01/app/Oracle/product/10.2.0/dbs/arch'
- log_archive_dest_2='SERVICE=db1 REOPEN=300'
- log_archive_dest_state_1='ENABLE'
- log_archive_dest_state_2='ENABLE'
4.CP主數據庫RMAN備份及控制文件到備庫
注意:備份存放位置要與primary database RMAN備份文件的位置相同. 控制文件存放位置要與生成standby database controlfile的位置相同
- scp /oracle/rmanback/*.dbf [email protected]:/Oracle/rmanback/
- scp /oracle/rmanback/*.ctl [email protected]:/oracle/Oracle/oradata/standby/
5.利用備用的控制文件,把備用數據庫啟到mount
- SQL>connect / as sysdba
- connnpcted to an idle instance.
- SQL>startup nomount pfile=$Oracle_HOME/dbs/initstandby.ora
- SQL>alter database mount standby database
6. 配置listener.ora 和tnsnames.ora文件.
與主庫相同啟動listener,tnsnames.ora也與主庫配置的一樣,
當主備庫的監聽都啟動後,進行測試,以例下面能順利進行
- tnsping db1
- tnsping standby
- SQL> sqlplus sys/123456@db1
- SQL> sqlplus sys/123456@standby
7.轉儲數據庫
- RMAN>connect target /
- connected to target database:TEST(DBID=788075692)
- RMAN> restore database
8.恢復數據庫。
- SQL>recover managed standby database disconnect from session;
- #如果有需要應用的日志並想手工應用,可以運行如下命令
- SQL>recover automatic standby database;
9.檢查standby database是否創建成功
a.在primary database 上切換日志
- SQL> alter system switch logfile
b.在primary database上運行下面的語句
- SQL> select max(sequence#) from v$archived_log;
- MAX(SEQUENCE#)
- --------------
- 17
c. 在standby database上運行下面的語句
- SQL> select sequence# ,applIEd from v$archived_log order by sequence#;
- SEQUENCE# APP
- --------------------- ---
- 15YES
- 16YES
- 17YES
若在上步中的max sequence#在的的app狀態為YES說明standby database 成功創建.
10. 以spfile啟動並設為只讀
- SQL> create spfile from pfile;
- SQL> shutdown immedaite
- SQL> startup mount
- SQL> alter database recover managed standby database disconnect from session;
- SQL> alter database open read only;
以上就是Oracle DataGuard數據備份的操作流程。本文出自 “追求” 博客。