码迷,mamicode.com
首页 > 其他好文 > 详细

场景7 Data Guard

时间:2016-08-10 09:52:37      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:

场景7  Data Guard

官方文档 :Oracle Data Guard Concepts and Administration

用于数据容灾,通过主备库同步(主库将redo日志传送到备库,一个主库可对应多个备库(30)),实现异地容灾

1. 构建测试库

2. 构建读写分离的环境

3. 实现滚动升级

4. 数据备份

 

数据容灾 :

1. 基于存储复制

2. 基于逻辑卷复制(镜像)

3. 基于应用(redo log)

 

redo log : DML/DDL, 记录数据块变化,用于recovery

 

RAC 高可用性,一个库可用多个实例来访问

 

Golden Gate : 更灵活,成本更高

 

物理备库 :收到redo日志后,直接做recovery

逻辑备库 :收到redo日志后,通过logminer抽取日志中sql, 执行sql

1. physical dg : 相当于主库的克隆,相同的名字,相同的id,支持主库所有的应用,在open状态下只读 read only(Active)可将所有写的操作放在主库上,所有读的操作放在备库上

2. logical dg : 和主库是两个独立的数据库,不同的名字,不同的id, 可以open到读写read write状态,(部分DDL操作及数据类型不受支持,如 lob, 一般可用于建立物化视图,建立辅助索引,升级

 

1. physical dg的构建

2. 保护模式的切换(最大保护,最佳性能(默认),最高可用性)

3. snapshot dg

4. dg 切换

5. broker (FSF) 自动切换

 

 

最大保护模式maximum protection(同步方式sync传送日志) :备库RFS确认后(ack),主库才能完成提交任务,若主库一直收不到确认(默认10分钟),则自动shutdown abort, 因此该模式需要至少两个以上的备库,可以保证数据零丢失(主备库间无任何数据差异),但对生产环境影响 较大,网络必须快,备库不能有问题,不然影响主库

LNS (log network service) : 主库发送日志

RFS (receive file service) :备库接收日志,写入本地standby redo log files

 

最佳性能模式maximum performance(异步方式async传送日志):不需备库确认日志收到后,主库就能完成提交,若redo日志传送失败,且主库已发生日志切换,可讲archive log传送给备库

 

最高可用性模式maximum availability(同步方式传送日志):备库RFS确认后(ack),主库才能完成提交任务(最大保护模式),若主库一直收不到确认(默认10分钟),则自动转换成最佳性能模式,恢复正常后,又自动转换成最大保护模式

 

MRP (media recover process) : 介质恢复进程

LSP (logical standby coordinator process) : 逻辑

 

eg :

desc v$database

select name, force_logging from v$database;

alter database force logging;

archive log list;

 

搭建DG :

1. 修改初始化文件

eg :

show parameter spfile;

create pfile from spfile;

cd $oracle_home/db

vi init.ora

 

 

GAP : 日志间隙

 

FAL_SERVER :

 

DB_FILE_NAME_CONVERT=‘/u01/app/oracle/oradata/shdb/‘, ‘/u01/app/oracle/oradata/prod/‘, ‘/u01/app/oracle/oradata/shdb/‘, ‘/u02/app/oracle/oradata/prod/‘

LOG)FILE_NAME_CONVERT=…

数据文件路径转换 :主备库数据文件路径不一致

 

eg :

select name from v$datafile;

select member from v4logfile;

 

 

eg :

startup force gnomon pfile=‘ORACLE_HOME/dbs/initprod.ora’;

show parameter name

show parameter log

create spoil from file;

startup force mount;

alter database create standby controlfile as ‘/home/oracle/std_control01.ctl’;

 

 

 

su -oracle

tail -f /u01/app/oracle/diag/

 

vi etc/hosts

ping …

 

cd $ORACLE_HOME/dbs

ls

scp initprod.ora enmo:$ORACLE_HOME/dbs/initshdb.ora

scp orapwprod enmo:$ORACLE_HOME/dbs/orapwshdb

scp /home/oracle/std_control

cd /u01/app/oracle/oradata/prod

scp *.dbf enmo:/u01/app/oracle/oradata/shdb

 

备库:

mkdir -p /u01/app/oracle/oradata/shdb

chown -R oracle:oinstall /u01/app/oracle/oradata/shdb

 

mkdir op /dsk1/arch_shdb

chown -R oracle:oinstall /dsk/arch_shdb

 

recover managed standby database disconnect from session;

 

recover managed standby database cancel;

 

主备库切换 :

1. switchover 正常手工切换

2. failover 容灾切换 :主库down了,将备库强制切换成主库

 

eg :

alter system switch logfile;

select name, dbid, database_role, protection_mode, switchover_status from v$database;

select username, sid from v$session where username is not null;

alter database commit to switchover to standby; (主库切换到备库)

alter database commit to switchover to standby with session shutdown; (主库切换到备库, 强制关闭会话)

shutdown immediate;

startup mount;

select name, dbid, database_role, protection_mode, switchover_status from v$database;

 

备库 :

select name, dbid, database_role, protection_mode, switchover_status from v$database;

select username, sid from v$session where username is not null;

select name, dbid, database_role, protection_mode, switchover_status from v$database;

alter system kill session; (强制杀掉绘画)

alter database commit to switchover to primary;

alter database open;

 

recover managed standby database disconnect from session;

select max(sequence#) from v$archived_log;

 

desc v$archive_dest

 

select name, database_role, protection_mode, switchover_status from v$database;

 

 

snapshot dg : 用于应用测试,建立快照,生成一个还原点,测试期间不能和主库同步,但可以继续接收主库的日志,测试完成后,回到还原点,开始recover

 

snapshot 保存到 recover area

 

show parameter recover

alter system set db_recovery_file_dest_size = 2g;

alter system set db_recovery_file_dest = ‘/dsk1’;

alter database convert to snapshot standby;

show parameter recover

show parameter spfile

create spfile from pfile;

startup force mount;

chown -R oracle:dba /dsk1

 

切换模式 :

shutdown immediate;

startup mount

alter database set standby database to maximize protection;

select name, database_role, protection_mode from v$database;

alter database open;

备库 :

select name, database_role, protection_mode from v$database;

alter database open;

 

 

 

eg : 

alter database add standby logfile ‘/u01/app/oracle/oradata/shdb/std_redo01.log’ size 50m;

alter database add standby logfile ‘/u01/app/oracle/oradata/shdb/std_redo02.log’ size 50m;

alter database add standby logfile ‘/u01/app/oracle/oradata/shdb/std_redo03.log’ size 50m;

alter database add standby logfile ‘/u01/app/oracle/oradata/shdb/std_redo04.log’ size 50m;

select member from v$logfile;

select group#, sequence#, status from v$standby_log;

 

eg :

conn scott/tiger

insert into emp1 select * from emp;

commit

insert into emp1 select * from emp;

select count(*) from emp1;

 

commit;

 

主库 :

ifconfig 

 

默认 :MRP只对archive log

 

eg ;

select group#, sequence#, status from v$standby_log;

 

recover managed standby database using current logfile disconnect from session; (启动实时应用)

 

 

Data Guard Broker

dgmgrl

connect sys/oracle@bjdb

create configuration ‘bjdbcfg’ as primary database is ‘bjdb’ connect identifier is ‘bjdb’;

show configuration

add database ‘shdb’ as connect identifier is shdb maintained as physical;

show configuration

enable configuration; (是Broker生效)

show configuration

edit database ‘bjdb’ set property ‘logxptmode’ = ‘sync’;

edit database ‘shdb’ set property ‘logxptmode’ = ‘sync’;

enable fast_start failover;

show configuration

srvctl (需装GI)

 

场景7 Data Guard

标签:

原文地址:http://www.cnblogs.com/jilili/p/5755503.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!