Oracle DataGuard;简称DG。是由一个Primary Database(主库)和一个或者多个Standby Database(备库)组成。对Oracle来说;本身不能提高性能。通过数据冗余来保护数据。由Primary Database对外提供服务;用户操作在Primary Database上操作;其操作的数据库Redo Log或者Archive log通过网络传输到Standby Database。Standby Database在重做这些日志。从而实现Primary Database和Standby Database数据同步。
架构图如下:
Oracle DataGuard中的Standby库有两种:物理Standby和逻辑Standby。
- 逻辑Standby接收后将其转换成sql语句,在Standby数据库上执行sql语句实现同步,这种方式叫sql Apply。
- 物理Standby接收完Primary数据库生成的REDO数据后,以介质恢复的方式实现同步,这种方式也叫Redo Apply。
2|0二. Oracle DataGuard搭建
安装规划:
IP | ROLE |
192.168.1.235 | Primary |
192.168.1.221 | Standby |
2|12.1. 主库设置归档模式
alter database archivelog;2|22.2. 主库设置Force Logging模式
alter database force logging;2|32.3. 备库创建相应的dump文件夹
# 在主库查询对应的dump目录 select name, value from v$parameter where name in ('audit_file_dest', 'background_dump_dest', 'control_files', 'core_dump_dest', 'user_dump_dest', 'db_recovery_file_dest' ) ORDER BY name ASC; # 备库用oracle用户执行创建目录 mkdir -p $value2|42.4. 配置Standby Redologs
对于模式中最大保护和最高可用性;采用是 LGWR 模式传送 Redo 日志;需要为 Standby库配置 Standby Redologs。Standby Redologs 和 ONline Redologs 文件大小是相同的。比 ONline Redologs 个数要 +1 。
# 查看redologs日志信息 sql> select group#,type,member from v$logfile; GROUP# TYPE MEMBER ------ ---------- -------------------------------------------------- 1 ONLINE /u01/app/oradata/ora235/redo01.log 2 ONLINE /u01/app/oradata/ora235/redo02.log 3 ONLINE /u01/app/oradata/ora235/redo03.log sql> select group#,bytes from v$log; GROUP# BYTES ------ ---------- 1 52428800 2 52428800 3 52428800 # 添加Standby Redologs;添加如下: ALTER DATABASE ADD STANDBY LOGFILE GROUP 4('/u01/app/oradata/ora235/stdred001.log') SIZE 50 M; ALTER DATABASE ADD STANDBY LOGFILE GROUP 5('/u01/app/oradata/ora235/stdred002.log') SIZE 50 M; ALTER DATABASE ADD STANDBY LOGFILE GROUP 6('/u01/app/oradata/ora235/stdred003.log') SIZE 50 M; ALTER DATABASE ADD STANDBY LOGFILE GROUP 7('/u01/app/oradata/ora235/stdred004.log') SIZE 50 M;2|52.5. 创建实例密钥文件
orapwd FILE=/u01/app/oracle/dbs/orapwora235 password=li0924 entries=5;- 将密钥文件传输到备库
2|62.6. 创建参数文件
本文采用 Primary 库和 Standby 库采用相同路径;所以仅设置必要的参数。
create pfile from spfile; *.DB_UNIQUE_NAME=db_primary *.LOG_ARCHIVE_CONfig='DG_CONfig=(db_primary,db_standby)' *.LOG_ARCHIVE_DEST_2='SERVICE=tns_standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db_standby' *.LOG_ARCHIVE_DEST_STATE_2=DEFER *.LOG_FILE_NAME_CONVERT ='/u01/app/oradata/ora235/','/u01/app/oradata/ora235/' *.FAL_SERVER=tns_standby *.FAL_CLIENT=tns_primary *.STANDBY_FILE_MANAGEMENT=AUTO- Primary重新启动
- 复制参数文件到Standby库
- 将Standby端启动到nomount状态
2|72.7 配置主备库的监听文件和网络文件
- 设置Primary库和Standby库的service_name
- Primary库配置listener.ora
- Standby库配置listener.ora
- Primary库和Standby库设置tnsname.ora
重启监听lsnrctl restart
2|82.8. 克隆Standby库
在Primary库执行
[oracle@oracle235 admin]$ rman target sys/li0924@tns_primary auxiliary sys/li0924@tns_standby Recovery Manager: Release 11.2.0.4.0 - Production on Thu Aug 9 23:56:46 2018 copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ORA235 (DBID=2047494122) connected to auxiliary database: ORA235 (not mounted) RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK; Starting Duplicate Db at 09-AUG-18 using target database control file instead of recovery catalog allocated channel: ORA_AUX_disK_1 channel ORA_AUX_disK_1: SID=20 device type=disK contents of Memory Script: { backup as copy reuse targetfile '/u01/app/oracle/dbs/orapwora235' auxiliary format '/u01/app/oracle/dbs/orapwora235' ; } executing Memory Script Starting backup at 09-AUG-18 allocated channel: ORA_disK_1 channel ORA_disK_1: SID=26 device type=disK Finished backup at 09-AUG-18 contents of Memory Script: { backup as copy current controlfile for standby auxiliary format '/u01/app/oradata/ora235/control01.ctl'; restore clone controlfile to '/u01/app/oradata/ora235/control02.ctl' from '/u01/app/oradata/ora235/control01.ctl'; } executing Memory Script Starting backup at 09-AUG-18 using channel ORA_disK_1 channel ORA_disK_1: starting datafile copy copying standby control file output file name=/u01/app/oracle/dbs/snapcf_ora235.f tag=TAG20180809T235658 RECID=4 STAMP=983750219 channel ORA_disK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 09-AUG-18 Starting restore at 09-AUG-18 using channel ORA_AUX_disK_1 channel ORA_AUX_disK_1: copied control file copy Finished restore at 09-AUG-18 contents of Memory Script: { sql clone 'alter database mount standby database'; } executing Memory Script sql statement: alter database mount standby database contents of Memory Script: { set newname for tempfile 1 to "/u01/app/oradata/ora235/temp01.dbf"; switch clone tempfile all; set newname for datafile 1 to "/u01/app/oradata/ora235/system01.dbf"; set newname for datafile 2 to "/u01/app/oradata/ora235/sysaux01.dbf"; set newname for datafile 3 to "/u01/app/oradata/ora235/undotbs01.dbf"; set newname for datafile 4 to "/u01/app/oradata/ora235/users01.dbf"; set newname for datafile 5 to "/data/oracle/data/lottu01.dbf"; backup as copy reuse datafile 1 auxiliary format "/u01/app/oradata/ora235/system01.dbf" datafile 2 auxiliary format "/u01/app/oradata/ora235/sysaux01.dbf" datafile 3 auxiliary format "/u01/app/oradata/ora235/undotbs01.dbf" datafile 4 auxiliary format "/u01/app/oradata/ora235/users01.dbf" datafile 5 auxiliary format "/data/oracle/data/lottu01.dbf" ; sql 'alter system archive log current'; } executing Memory Script executing command: SET NEWNAME renamed tempfile 1 to /u01/app/oradata/ora235/temp01.dbf in control file executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting backup at 09-AUG-18 using channel ORA_disK_1 channel ORA_disK_1: starting datafile copy input datafile file number=00005 name=/data/oracle/data/lottu01.dbf output file name=/data/oracle/data/lottu01.dbf tag=TAG20180809T235706 channel ORA_disK_1: datafile copy complete, elapsed time: 00:01:45 channel ORA_disK_1: starting datafile copy input datafile file number=00001 name=/u01/app/oradata/ora235/system01.dbf output file name=/u01/app/oradata/ora235/system01.dbf tag=TAG20180809T235706 channel ORA_disK_1: datafile copy complete, elapsed time: 00:00:35 channel ORA_disK_1: starting datafile copy input datafile file number=00002 name=/u01/app/oradata/ora235/sysaux01.dbf output file name=/u01/app/oradata/ora235/sysaux01.dbf tag=TAG20180809T235706 channel ORA_disK_1: datafile copy complete, elapsed time: 00:00:35 channel ORA_disK_1: starting datafile copy input datafile file number=00003 name=/u01/app/oradata/ora235/undotbs01.dbf output file name=/u01/app/oradata/ora235/undotbs01.dbf tag=TAG20180809T235706 channel ORA_disK_1: datafile copy complete, elapsed time: 00:00:25 channel ORA_disK_1: starting datafile copy input datafile file number=00004 name=/u01/app/oradata/ora235/users01.dbf output file name=/u01/app/oradata/ora235/users01.dbf tag=TAG20180809T235706 channel ORA_disK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 10-AUG-18 sql statement: alter system archive log current contents of Memory Script: { backup as copy reuse archivelog like "/data/arch/1_3_983660602.dbf" auxiliary format "/data/arch/1_3_983660602.dbf" ; catalog clone archivelog "/data/arch/1_3_983660602.dbf"; switch clone datafile all; } executing Memory Script Starting backup at 10-AUG-18 using channel ORA_disK_1 channel ORA_disK_1: starting archived log copy input archived log thread=1 sequence=3 RECID=19 STAMP=983750428 output file name=/data/arch/1_3_983660602.dbf RECID=0 STAMP=0 channel ORA_disK_1: archived log copy complete, elapsed time: 00:00:01 Finished backup at 10-AUG-18 cataloged archived log archived log file name=/data/arch/1_3_983660602.dbf RECID=1 STAMP=983750429 datafile 1 switched to datafile copy input datafile copy RECID=4 STAMP=983750429 file name=/u01/app/oradata/ora235/system01.dbf datafile 2 switched to datafile copy input datafile copy RECID=5 STAMP=983750429 file name=/u01/app/oradata/ora235/sysaux01.dbf datafile 3 switched to datafile copy input datafile copy RECID=6 STAMP=983750429 file name=/u01/app/oradata/ora235/undotbs01.dbf datafile 4 switched to datafile copy input datafile copy RECID=7 STAMP=983750429 file name=/u01/app/oradata/ora235/users01.dbf datafile 5 switched to datafile copy input datafile copy RECID=8 STAMP=983750429 file name=/data/oracle/data/lottu01.dbf contents of Memory Script: { set until scn 955597; recover standby clone database delete archivelog ; } executing Memory Script executing command: SET until clause Starting recover at 10-AUG-18 using channel ORA_AUX_disK_1 starting media recovery archived log for thread 1 with sequence 3 is already on disk as file /data/arch/1_3_983660602.dbf archived log file name=/data/arch/1_3_983660602.dbf thread=1 sequence=3 media recovery complete, elapsed time: 00:00:00 Finished recover at 10-AUG-18 Finished Duplicate Db at 10-AUG-182|92.9. 启用日志传送
在 Primary 端启动日志传送
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;2|102.10. 启用实时应用redo
在 Primary Database 产生的 Redo 日志;传送到 Standby Database;是通过 LGWR 或者 ARCH 进程完成。这个很好理解。默认情况下是由 ARCH 进程。有参数 *.LOG_ARCHIVE_DEST_2 控制的。使用 ARCH 进程; Primary Database 和 Standby Database 存在数据延迟。若 Primary Database 出现异常;容易造成部分数据丢失。为了避免数据丢失,必须要使用 LGWR 进程,需要用到 Standby Redolog。而LGWR 又分SYNC(同步)和ASYNC(异步)两种方式。
- SYNC方式:对网络要求比较高;必须等待写入本地日志文件操作和通过LNSn进程的网络传送都成功,Primary Database 上的事务才能提交成功。使用LGWR SYNC方式时,可以同时使用NET_TIMEOUT参数,这个参数单位是秒,代表如果多长时间内网络发送没有响应,LGWR 进程会抛出错误。因此对 Primary Database 性能有影响。
- ASYNC方式:采用异步方式;Primary Database 上的事务提交跟日志是否已经传送没有影响。
1. 在 Primary Database上执行;
alter system set log_archive_dest_2='SERVICE=tns_standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db_standby' scope=both;2. 在Standby Database上执行;
alter system set log_archive_dest_2='SERVICE=tns_primary LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db_primary' scope=both;3. Standby Database启动实时应用redo
alter database recover managed standby database using current logfile ;4. 验证结果
# 在Primary Database 上创建表t_lottu02 sql> set sqlPROMPT Primary> Primary>conn lottu/li0924 Connected. Primary>create table t_lottu02 as select level id,'lottu' name from dual connect by level <= 3; Table created. # 在Standby Database上查看 sql> set sqlPROMPT StandBy> StandBy>conn lottu/li0924 Connected. StandBy>select * from t_lottu02; ID NAME ---------- ----- 1 lottu 2 lottu 3 lottu
原文:https://www.cnblogs.com/lottu/p/9542053.html
__EOF__
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。