三、角色转换的类型
数据库之间的转换有switchover和failover两种方式。
switchover
switchover是primary数据库和它的一个standby数据库之间角色的切换,通常是有计划的数据库转换,保证不会有数据丢失。
failover
failover发生在primary数据库失败之后,它的一个standby接替它成为primary数据库。failover通常发生primary数据库不可恢复的情况下,根据数据库保护模式的不一样failover可能会有数据丢失。
2、转换目标的选择
对于switchover操作来说,遵循以下的步骤:
首先选择未应用的redo的standby,这个可以通过SHOW DATABASE db_unique_name RecvQEntries看到。
对于物理和逻辑standby同时存在时,优先选择redo apply queue最小的物理standby,因为物理standby在转换之后所有的standby都能正常工作,而转换到逻辑standby之后同一组里面的物理standby将要重建。
对failover操作来说,遵循以下的步骤:
为降低数据丢失的数量,首先要选择应用日志最多的standby。
对于物理和逻辑standby同时存在时,优先选择物理standby,因为物理standby在转换之后所有的standby都能正常工作,而转换到逻辑standby之后同一组里面的standby将要重建。另外一个如果逻辑standby使用DBMS_LOGSTDBY.SKIP忽略了一部分数据库话也会造成数据丢失。
3、Data Guard转换的三个层次
第一个层次是在没有配置broker的环境中,在这种环境下,如果要进行数据库的角色却换的话通常需要3个步骤:
首先是检查data guard环境中的数据库是否满足转换的条件。
然后登陆到primary数据库运行sql转换角色,再重启primary数据库使其变成standby。
再登录到要转换的standby数据库上,运行sql转换角色,再重新启动standby以变成新的primary。
第二个层次是配置了broker但是没有配置FSF(fast-start failover)的环境中,在这里做switchover和failover都只需要一个简单的命令,剩下的重启primary和standby的操作就交给broker去做了。
第三个层次是配置了FSF的机器,这时候数据库的状态由FSF Observer监控着,一旦primary数据库出现了问题需要failover操作,FSF会自动进行数据库的转换,根本就不需要人来参与了。
broker管理下的switchover的过程:
1)检查primary和standby是否online,是否有错误,如果有错误则switchover失败。
2)如果primary是RAC,则关掉RAC中所有不参与switchover的instance。
3)将primary数据库转换成standby数据库,然后将目标standby数据库转换成新的primary数据库。
4)更新broker控制文件记录转换之后的数据库角色信息。
5)如果新的standby是物理standby的话将会重启之,然后开始redo log应用。RAC环境中将会重启那些被关闭的instance。
6)如果是物理standby环境的话重启新的primary数据库然后开始rodo log的传送到其他的standby中。
最后broker会确认转换之后的新primary和standby都工作正常,redo log传送和应用都正常。对于那些没有参与switchover的standby将会保持不变。
1、切换主库到备库
DGMGRL> switchover to source_st; --这个source_st是我的环境中的备库的名字
Performing switchover NOW, please wait...
Operation requires shutdown of instance "source" on database "source_pr"
Shutting down instance "source"...
ORA-01109: database not open
Database dismounted.
Oracle instance shut down.
Operation requires shutdown of instance "source" on database "source_st"
Shutting down instance "source"...
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "source" on database "source_pr"
Starting instance "source"...
ORACLE instance started.
Database mounted.
Operation requires startup of instance "source" on database "source_st"
Starting instance "source"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "source_st"
2、切换后的观察与日志检查
略。
3、切回主库到备库
DGMGRL> switchover to source_pr; --这个source_pr是我的环境中的主库的名字
Performing switchover NOW, please wait...
Operation requires shutdown of instance "source" on database "source_st"
Shutting down instance "source"...
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Operation requires shutdown of instance "source" on database "source_pr"
Shutting down instance "source"...
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "source" on database "source_st"
Starting instance "source"...
ORACLE instance started.
Database mounted.
Operation requires startup of instance "source" on database "source_pr"
Starting instance "source"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "source_pr"
4、切换后的观察与日志检查
略。
更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
