Oracle DataGuard是一种数据库级别的HA方案最主要功能是冗灾数据保护故障恢复等
在生产数据库的事务一致性时使用生产库的物理全备份(或物理COPY)创建备库备库会通过生产库传输过来的归档日志(或重做条目)自动维护备用数据库将重做数据应用到备用库本文介绍使用RMAN备份创建备库(dataguard)
一:Oracle DataGuard环境概述
软件环境
操作系统Red Linux Enterprise as
数据库版本Oracle g release
primary databae
IP:
ORACLE_SID=db
db_unique_name=db
standby database
IP:
ORACLE_SID=standby
db_unique_name=standby
二主数据库(db)做准备
设置主数据库为Force logging
SQL>alterdatabaseforcelogging;
创建密码文件
cd$ORACLE_HOME/dbs/
orapwdfile=orapwdbpassword=force=y
修改主库的初始化参数
altersystemsetlog_archive_config=dg_config=(dbstandby)scope=both;
altersystemsetlog_archive_dest_=location=/u/db/archscope=both;
altersystemsetdb_unique_name=dbscope=both;
生成数据库备份
RMAN>connecttargetsys/
RMAN>backupdatabaseformat=/oracle/rmanback/%d_%sdbfplusarchivelog;
[oracle@oraclermanback]$ls
DB_dbfDB_dbf
生成备库的control file
SQL>alterdatabasecreatestandbycontrolfileas/oracle/rmanback/ctontrl
配置listenerora 和tnsnamesora文件
启动lintenerora
[oracle@oracledbs]$lsnrctlstatus
LSNRCTLforLinux:VersionProductiononJUN::
Servicedbhasinstance(s)
InstancedbstatusREADYhashandler(s)forthisservice
Servicedb_XPThasinstance(s)
InstancedbstatusREADYhashandler(s)forthisservice
Thecommandcompletedsuccessfully
配置rnsnamesora
vi $ORACLE_HOME/network/admin/tnsnamesora
db =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = ))
)
(CONNECT_DATA =
(SERVICE_NAME = db)
standby =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = ))
)
(CONNECT_DATA =
(SERVICE_NAME = standby)
)
)
三创建standby database
设置环境变量并安装oracle软件
#环境变量设成与主库一样
#只安装软件不安装库
/runInstaller–silent–responseFile/tmp/installoraclersp
建立相关的目录
cd$ORACLE_HOME/dbs/
orapwdfile=orapwSIDpassword=force=y
#注要密码要与主库的一样否则会归档失败
建立密码文件
cd$ORACLE_HOME/dbs/
orapwdfile=orapwSIDpassword=force=y
#注要密码要与主库的一样否则会归档失败
建立参数文件(pfile)
db_name = standby
shared_pool_size = M
undo_management = AUTO
undo_tablespace = undotbs
sga_max_size = M
sga_target = M
db_k_cache_size = M
standby_file_management=AUTO
fal_server=db
fal_client=standby
log_archive_dest_=location=/u/app/oracle/product//dbs/arch
log_archive_dest_=SERVICE=db REOPEN=
log_archive_dest_state_=ENABLE
log_archive_dest_state_=ENABLE
CP主数据库RMAN备份及控制文件到备库
注意:备份存放位置要与primary database RMAN备份文件的位置相同 控制文件存放位置要与生成standby database controlfile的位置相同
scp/oracle/rmanback/*dbfroot@:/oracle/rmanback/
scp/oracle/rmanback/*ctlroot@:/oracle/oracle/oradata/standby
利用备用的控制文件把备用数据库启到mount
SQL>connect / as sysdba
connnpcted to an idle instance.
SQL>startup nomount pfile=$ORACLE_HOME/dbs/initstandbyora
SQL>alter database mount standby database
配置listenerora 和tnsnamesora文件
与主库相同启动listenertnsnamesora也与主库配置的一样
当主备库的监听都启动后进行测试以例下面能顺利进行
tnsping db
tnsping standby
SQL> sqlplus sys/@db
SQL> sqlplus sys/@standby
转储数据库
RMAN>connect target /
connected to target databaseTEST(DBID=)
RMAN> restore database
恢复数据库
SQL>recovermanagedstandbydatabasedisconnectfromsession
#如果有需要应用的日志并想手工应用可以运行如下命令
SQL>recoverautomaticstandbydatabase
检查standby database是否创建成功
a在primary database 上切换日志
SQL>altersystemswitchlogfile
b在primary database上运行下面的语句
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
c 在standby database上运行下面的语句
SQL> select sequence# applied from v$archived_log order by sequence#;
SEQUENCE# APP
YES
YES
YES
若在上步中的max sequence#在的的app状态为YES说明standby database 成功创建
以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数据备份的操作流程