Oracle Standby
Database
Chao_Ping@
Oracle数据库保护-standby技术
1. Standby 技术该览,实现机制
2. Standby 实现需要注意的问题
3. Oracle Standby和其他技术的比较
4. Standby 切换
* 假设大家对Oracle Standby数据库有一定理解
Oracle Standby 概念
什么是Standby数据库?
–Standby Database产生于Oracle 7.3,在9版本里面重命名为Data Guard
–主要作用是Oracle数据库的灾难恢复
–Oracle的特有的灾难恢复方法
为什么需要Standby数据库
–优秀的Oracle数据库灾备方法
–Oracle数据库高可用解决方案之一
实现机制
核心机制:
–Standby Controlfile +
–一份初始的数据库备份+
–持续不断的Archivelog Recover过程
Standby:系统框架
PrimaryDatabase
Physical Standby
Standby创建
一份最近数据库物理备份
–冷备份
–Rman备份
–OS 热备份(begin backup,cp, end backup)
一份Standby Controlfile
SQL>alter database create standby controlfile as ‘$PATH/$FILENAME’;
一份同版本的$ORACLE_HOME,一套initsid.ora 约束:
–相同平台,相同Oracle 版本
Standby创建
Standby InitSID.ora的关键参数:
db_file_name_convert
log_file_name_convert
standby_archive_dest
fal_client (9i)
fal_server (9i)
standby_file_management (9i)
Remote_login_passwordfile(For monitor)
Standby 同步
归档日志同步
–Cron调用脚本,rcp/ftp拷贝归档日志
成熟,稳定,Standby问题不会对Primary造成任何影响
自己编写同步脚本,通过Cron控制同步时间间隔
–Log_archive_dest_n=‘service=standby optional…’;优点:
简单。8i开始支持。Oracle 推荐方式。趋势。
其他的no data lost等新的DataGuard Feature必须采用这种模式可能有问题产生
8.1.6: standby down, possible primary down
Standby os hangs, primary arch process can hangs…
Standby数据库同步
Lgwr 同步
–Async
alter system set log_archive_dest_2
='service=miscguard reopen=200 lgwr async';–Sync
alter system set log_archive_dest_2
='service=miscguard reopen=200 lgwr async';
Standby 数据库同步
LGWR同步
–需要先在standby数据库添加standby logfile.
–Standby Logfile数目需要足够充裕,以免Production数据库挂起
Standby数据库同步
Async和Sync之间的选择
保护模式
最大化保护Redo的传输LWGR/SYNC/S
RL特点不会丢失任何一个提交的事务SQL>ALTER DATABASE SET STANDBY TO
MAXIMIZE PROTECTION;
必须至少有一个Standby工作,不然Production
停机!
不会丢失任何一个提交的事务
SQL>ALTER DATABASE SET STANDBY TO
MAXIMIZE AVALIABILITY;
同最大化保护模式。
当Standby由于网络问题时,Production仍然可
以继续运行
可能丢失几秒钟到一个Logfile的事务
SQL>ALTER DATABASE SET STANDBY TO
MAXIMIZE PERFORMANCE;
对Prod影响最小最大可用性LGWR/SYNC最大化性能LGWR/ASYNC或者ARCH
Standby 数据库维护:归档日志
归档日志源源不断的产生,必须及时删除,才能维护系统的正常运行
只能删除已经成功Recover的归档日志。 删除依据:
–1)alert_$ORACLE_SID.log文件,关键词:ORA-279(oracle 8i/9i, Manual Recovery)
–2)v$archived_log.applied(Oracle 9i)
Standby 数据库维护:
影响Standby数据库的操作
影响Standby的Primary数据库操作:
添加tablespace/Datafile
Resetlogs 操作:
–recreate controlfile resetlogs
–Incomplete Recover
Nologging操作
–9i: Forcelogging(v$database.force_logging)–8i: Recreate affected datafile
Clear unarchived logfile
7-8i Standby自动添加datafile
set term off echo off head off feedback off
connect / as sysdba
set autorecovery on
spool /home/oracle/admin/catalog/nohup.out
recover standby database;
exit
EOF
sql=`grep ORA-01110 /home/oracle/admin/catalog/nohup.out |awk '{print $5}'`
echo $sql
wrong=`grep ORA-01157 /home/oracle/admin/catalog/nohup.out |wc -l`
echo $wrong
if [ $wrong -gt 0 ]
then
sqlplus /nolog <<EOF
connect / as sysdba
alter database create datafile $sql;
exit
EOF
else
echo OK
fi;
输出示例
ALTER DATABASE RECOVER CONTINUE DEFAULT
Media Recovery Log /home/oracle/admin/catalog/arch/arch_1_17758.arc
Fri Aug 29 14:00:11 2003
Errors in file /home/oracle/admin/catalog/bdump/dbw0_16742.trc:
ORA-01157: cannot identify/lock data file 21 -see DBWR trace file
ORA-01110: data file 21: '/oradata/catalog/table17.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Media Recovery failed with error 1670
ORA-283 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Fri Aug 29 14:00:14 2003
ALTER DATABASE RECOVER CANCEL
ORA-1112 signalled during: ALTER DATABASE RECOVER CANCEL ...
Fri Aug 29 14:00:14 2003
alter database create datafile '/oradata/catalog/table17.dbf'
Fri Aug 29 14:01:10 2003
Completed: alter database create datafile '/oradata/catalog/t
9i Standby 添加Datafile自动维护
关键: standby_file_management=auto
例子:
Media Recovery Log
/home/oracle/9.2.0/dbs/archarch1_792.dbf
Mon Dec 22 16:32:51 2003
Recovery created file /oradata/misc/filter02.dbf
Successfully added datafile 5 to media recoveryDatafile #5: '/oradata/misc/filter02.dbf'
Media Recovery Waiting for thread 1 seq# 793
Nologging操作(8i)
1。DBA管理规范:一般情况下,不允许进行Nologging操作
2。事后补救:
Media Recovery Log /archivelog/biddbstandby/biddb_arch_1_36640.arc
Recovery is repairing media corrupt block 11 of file 17
Recovery is repairing media corrupt block 12 of file 17
Recovery is repairing media corrupt block 13 of file 17
Recovery is repairing media corrupt block 14 of file 17
Recovery is repairing media corrupt block 15 of file 17
SQL>SELECT NAME, UNRECOVERABLE_CHANGE# FROM V$DATAFILE order by 2 asc比较Production和Standby的结果。
把受影响的Datafile从Production重新备份,恢复到Standby
Nologging操作(9i)
SQL> select force_logging from v$database;
FORCE_LOGGING
---
NO
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FORCE_LOGGING
---
YES
Standby + RAC
Prod:RAC 多节点Standby:可以是RAC单节点或者多节点这个是Oracle推荐的RAC 高可用性解决方案RAC—解决节点失败,OS失败等问题DataGuard—解决存储失败,Site失败等问题。