偶尔有空上来看看
分类: oracle
2020-12-16 11:42:59
为了确保dg环境可靠,有时需要按计划执行failover验证,执行完验证后,还要复原dg环境,为了简化过程可以考虑使用flashback技术进行复原。
如果没有设置闪回区,先设置。
show parameter db_recovery_file_dest
会显示两个参数,db_recovery_file_dest_size,为闪回区空间大小。db_recovery_file_dest,为闪回区目录位置。应尽量设置大一些。
show parameter db_flashback_retention_target
闪回区内对象(主要考虑闪回日志)保留时间,以分钟为单位,通常验证时间不会超过1天,因此默认值1440即可。
如果没有设置闪回,则按以下步骤设置备库闪回区。
alter system set db_recovery_file_dest_size=500g;
alter system set db_recovery_file_dest='/oradata/flash';
shu immediate
startup mount
alter database flashback on;
alter database open;
alter database recover managed standby database using current logfile disconnect from session;
为了利用flashback database闪回特性,需要先创建一个还原点,后面会用到。
alter database recover managed standby database cancel;
create restore point rp_yanlian guarantee flashback database;
确认还原点
select name,scn,time from v$restore_point;
应该有rp_yanlian的信息
主库切归档并禁止传输
alter system archive log current;
alter system set log_archive_dest_state_3=defer;
备库执行failover,强制切换为主库(模拟灾难场景:主库断电)
alter database recover managed standby database finish force;
alter database commit to switchover to primary;
确认控制文件状态
select controlfile_type from v$database;
应该是current
alter database set standby database to maximize performance;
alter database open;
因为强制断开主库,因此备库后台告警日志会出现fal[server, arc2]: error 16009 creating remote archivelog,忽略。
sqlplus / as sysdba
create table test1 (id int);
insert into test1 values (1);
commit;
select * from test1;
通知业务系统访问,验证连通性及可读写性。
等待演练结束后,恢复dg环境。
shutdown abort
startup mount
flashback database to restore point rp_yanlian;
select controlfile_type from v$database;
应该是backup
alter database convert to physical standby;
shutdown immediate
startup mount
alter database recover managed standby database disconnect;
select controlfile_type from v$database;
应该是standby
主库上
alter system archive log current;
alter system set log_archive_dest_state_3=enable;
备库上验证
alter database recover managed standby database cancel;
alter database open read only;
select * from test1;
这里应该报错ora-00942,说明备库已经与主库一致,测试数据被清除。
shutdown immediate
startup mount
drop restore point rp_yanlian ;
alter database open;
alter database recover managed standby database using current logfile disconnect;
set lin 120 pages 100
col process for a11
col pid for 999999999
col status for a15
col client_process for a11
col client_pid for a11
col group# for a5
col sequence# for 99999999
col block# for 99999999
col blocks for 99999999
col delay_mins for 99999999
col thread# for 99
select process,pid,status,client_process,client_pid,group#,thread#,sequence#,block#,blocks,delay_mins from v$managed_standby;
如果观察到mrp进程对应的block#在增加则说明dg正常。
参考:how to open physical standby for read write testing and flashback (doc id 805438.1)