`

Data Guard Broker系列之五:数据库角色转换

 
阅读更多

数据库转换的基本概念

转换的类型

数据库之间的转换有switchover和failover两种方式。

switchover
switchover是primary数据库和它的一个standby数据库之间角色的切换,通常是有计划的数据库转换,保证不会有数据丢失。
failover
failover发生在primary数据库失败之后,它的一个standby接替它成为primary数据库。failover通常发生primary数据库不可恢复的情况下,根据数据库保护模式的不一样failover可能会有数据丢失。

转换目标的选择

对于switchover操作来说,遵循以下的步骤

  1. 首先选择未应用的redo的standby,这个可以通过SHOW DATABASE db_unique_name RecvQEntries看到。
  2. 对于物理和逻辑standby同时存在时,优先选择redo apply queue最小的物理standby,因为物理standby在转换之后所有的standby都能正常工作,而转换到逻辑standby之后同一组里面的物理standby将要重建。

对failover操作来说,遵循以下的步骤

  1. 为降低数据丢失的数量,首先要选择应用日志最多的standby。
  2. 对于物理和逻辑standby同时存在时,优先选择物理standby,因为物理standby在转换之后所有的standby都能正常工作,而转换到逻辑standby之后同一组里面的standby将要重建。另外一个如果逻辑standby使用DBMS_LOGSTDBY.SKIP忽略了一部 分数据库话也会造成数据丢失。

Data Guard转换的三个层次

第一个层次是在没有配置broker的环境中,在这种环境下,如果要进行数据库的角色却换的话通常需要3个步骤:

  1. 首先是检查data guard环境中的数据库是否满足转换的条件。
  2. 然后登陆到primary数据库运行sql转换角色,再重启primary数据库使其变成standby。
  3. 再登录到要转换的standby数据库上,运行sql转换角色,再重新启动standby以变成新的primary。

第二个层次是配置了broker但是没有配置FSF(fast-start failover)的环境中,在这里做switchover和failover都只需要一个简单的命令,剩下的重启primary和standby的操作就交给broker去做了。

第三个层次是配置了FSF的机器,这时候数据库的状态由FSF Observer监控着,一旦primary数据库出现了问题需要failover操作,FSF会自动进行数据库的转换,根本就不需要人来参与了。

broker管理下的switchover和failover

switchover

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将会保持不变。

下面是一个switchover的详细过程

DGMGRL> show configuration
 
Configuration
 
Name:                FSF
 
Enabled:             YES
 
Protection Mode:     MaxAvailability
 
Fast-Start Failover: DISABLED
 
Databases:
    
torcla - Physical standby database
    
torclb - Primary database
 
Current status for "FSF":
SUCCESS
 
DGMGRL> switchover to torcla
Performing switchover NOW, please wait...
Operation requires shutdown of instance "torclb" on database "torclb"
Shutting down instance "torclb"...
ORA-01109: database not open
 
Database dismounted.
ORACLE instance shutdown.
Operation requires shutdown of instance "torcla" on database "torcla"
Shutting down instance "torcla"...
ORA-01109: database not open
 
Database dismounted.
ORACLE instance shutdown.
Operation requires startup of instance "torclb" on database "torclb"
Starting instance "torclb"...
ORACLE instance started.
Database mounted.
Operation requires startup of instance "torcla" on database "torcla"
Starting instance "torcla"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "torcla"
DGMGRL> show configuration

Configuration
 
Name:                FSF
 
Enabled:             YES
 
Protection Mode:     MaxAvailability
 
Fast-Start Failover: DISABLED
 
Databases:
    
torcla - Primary database
    
torclb - Physical standby database
 
Current status for "FSF":
SUCCESS

failover

failover有两种类型:完全failover和立即failover。

完全failover
进行完全failover操作的是很broker会竟可能的恢复数据,同时在failover完成之后会根据情况尽可能的将没有参与failover的standby变成新的primary的可用的standby。
立即failover
立即failover的操作开始之后broker不再去试图恢复更多的数据,另一个就是failover完成之后所有没有参与failover的standby都要重新启用。

调用这两种failover的命令如下

-- 完全failover
FAILOVER TO standby_database_name;
-- 立即failover
FAILOVER TO standby_database_name IMMEDIATE;

broker执行完全failover的过程

  1. 检查primary是否可用,可用的话给出一条警告信息。
  2. 确认目标standby可用,不可用的话failover失败。RAC环境中将关闭standby的其他不参与的instance。
  3. 等待目标standby完成还在队列中的redo信息之后关闭redo log apply或是sql apply。
  4. 将目标standby转换成新的primary。
    • 将新的primary数据库打开为读写模式。
    • 检查其他的standby是否能成为新primary的standby,如果可以的话则该standby的状态保证不变,否则则需要re-enable。
    • 启动redo传送服务将redo传送给那些不需要re-enable的standby数据库。
  5. 如果是RAC环境则重启那些之前关闭的instance。

broker执行立即failover的过程

  1. 确认目标standby可用,不可用的话failover失败。RAC环境中将关闭standby的其他不参与的instance。
  2. 立即停止redo log apply或是sql apply,不管是否还有可恢复的数据,这样可能会造成数据丢失。
  3. 将目标standby转换成新的primary并打开到读写模式,并启动redo传送服务。

一个完全failover的例子

DGMGRL> failover to torclb
Performing failover NOW, please wait…
Failover succeeded, new primary is “torclb”
DGMGRL> show configuration

Configuration

Name: FSF
Enabled: YES
Protection Mode: MaxPerformance
Fast-Start Failover: DISABLED
Databases:
torcla – Physical standby database (disabled)
torclb – Primary database

Current status for “FSF”:
SUCCESS

从上面的状态我们可以看到此时的新standby是不可用的,处于disabled状态。


角色转换之后的数据库的启用

在角色转换之后我们可能还需要进行额外的操作来启用被禁用的数据库,操作已经data guard的类型不同需要启用数据库情况也不同。

转换操作 reinstate或recreate 有问题的primary数据库 重新启用没有参与failover的standby
switchover到物理standby 不需要其他操作 不需要其他操作
switchover到逻辑standby 不需要其他操作 所有物理standby需要recreate
完全failover到物理standby 如果启用了flashback而且retention足够的话可以reinstate,否则只能recreate 对于物理standby如果启用了flashback而且retention足够的话可以reinstate,否则只能recreate
对于逻辑standby必须recreate
完全failover逻辑standby 如果启用了flashback而且retention足够的话可以reinstate,否则只能recreate 所有standby都会被disabled,都需要recreate
立即failover到物理standby或逻辑standby 必须要recreate 所有standby都会被disabled,都需要recreate


reinstate操作

在broker中进行reinstate数据库操作只需要运行一个命令就行了,不过前提是配置了flashback以及足够的retention。

REINSTATE DATABASE db_unique_name;

基本步骤是:

  1. 重启数据库到mount状态
  2. 使用dgmgrl连接到primary数据库
  3. 运行REINSTATE DATABASE命令

下面对上一步failover之后的新standby做一次reinstate操作

DGMGRL> reinstate database torcla
Reinstating database "torcla", please wait...
Operation requires shutdown of instance "torcla" on database "torcla"
Shutting down instance "torcla"...
ORA-01109: database not open
 
Database dismounted.
ORACLE instance shutdown.
Operation requires startup of instance "torcla" on database "torcla"
Starting instance "torcla"...
ORACLE instance started.
Database mounted.
Continuing to reinstate database "torcla" ...
Reinstatemen to fdatabase "torcla" succeeded
DGMGRL> show configuration
 
Configuration
 
Name:                FSF
 
Enabled:             YES
 
ProtectionMode:     MaxPerformance
 
Fast-Start Failover: DISABLED
 
Databases:
    
torcla - Physical standby database
    
torclb - Primary database
 
Current status for "FSF":
SUCCESS

可以看到reinstate之后数据库torcla已经可以正常使用了。

 

参考至:http://www.dbabeta.com/2009/learn-data-guard-broker_role-transition.html

如有错误,欢迎指正

邮箱:czmcj@163.com

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics