当oracle data guard中如主库出现当机时,需要将从库切换为主库,以下从实验环境模拟主从库切换操作:
1.查看主从库角色
192.168.88.120:
p_w_picpath
192.168.88.119:
p_w_picpath
2.将主库(88.120)切换为从库
alter database commit to switchover to physical standby with sessionB shutdown;
p_w_picpath
shutdown immediate; 
startup nomount;
alter database mount standby database;
recover managed standby database disconnect;
ORACLE 11G DATA GUARD主从切换_第1张图片
3.主库切换完成,开启数据库
alter database open或shutdown以后startup
ORACLE 11G DATA GUARD主从切换_第2张图片
4..将从库切换为主库
alter database commit to switchover to primary;
shutdown immediate
startup
ORACLE 11G DATA GUARD主从切换_第3张图片
5.在从库上应用重做日志
alter database recover managed standby database disconnect from session;
6..查看切换后状态
192.168.88.119:
p_w_picpath
192.168.88.120:
p_w_picpath
7..验证切换是否成功(角色切换过来后需要查看日志是否能正确从新的主库同步到备用库)
在主从库上分别执行
SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
新主库88.119:
ORACLE 11G DATA GUARD主从切换_第4张图片
新从库88.120:
ORACLE 11G DATA GUARD主从切换_第5张图片
通过主从库新的归档应用和确认状态可查看到两个库的角色已经成功切换!