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/
- 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 root@192.168.18.2:/oracle/rmanback/
- scp /oracle/rmanback/*.ctl root@192.168.18.2:/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数据备份的操作流程。