天天看点

Oracle Datagurad Failover

生产环境中,可能会有各种各样的原因导致数据库不能提供服务,例如数据库库的硬件故障,操作系统故障或软件bug,人为的失误(例如rm -rf /)等,在这种情况下,dataguard显得尤为重要,当主库不可用的时候,可以将备库failover成主库继续提供服务,failover和switchover不同的是,执行failover后,原有的dataguard配置将会失效且有可能会丢失部分数据,所以在生产环境中能用switchover解决的问题则应尽量采用switchover!

一:使用sql命令执行failover

1:查看当前的主库是dg1,物理备库为dg2,将主库关闭,模拟主库故障

[oracle@dg2 ~]$ dgmgrl /  

DGMGRL for Linux: Version 11.2.0.3.0 - 64bit Production  

Copyright (c) 2000, 2009, Oracle. All rights reserved.  

Welcome to DGMGRL, type "help" for information.  

Connected.  

DGMGRL> show configuration;  

Configuration - DG_BROKER_CONFIG  

  Protection Mode: MaxAvailability  

  Databases:  

    dg1 - Primary database  

    dg2 - Physical standby database  

Fast-Start Failover: DISABLED  

Configuration Status:  

SUCCESS  

SQL> select open_mode,database_role,db_unique_name,flashback_on from v$database;  

OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME       FLASHBACK_ON  

-------------------- ---------------- -------------------- ------------------  

READ WRITE           PRIMARY          dg1                  NO  

SQL> shutdown abort  

ORACLE instance shut down. 

2:在备库dg2上执行failover过程,failover执行的命令和switchover类似,只是在这个过程中,主库已经不可用

READ ONLY WITH APPLY PHYSICAL STANDBY dg2                  NO  

SQL> alter database recover managed standby database cancel;  

Database altered.  

READ ONLY            PHYSICAL STANDBY dg2                  NO  

出现这个错误说明日志并未完全的应用

SQL> alter database commit to switchover to primary;  

alter database commit to switchover to primary  

*  

ERROR at line 1:  

ORA-16139: media recovery required  

SQL> alter database recover managed standby database using current logfile disconnect from session;  

SQL> alter database recover managed standby database finish;  

MOUNTED              PRIMARY          dg2                  NO  

SQL> alter database open;  

READ WRITE           PRIMARY          dg2                  NO 

二:使用datagurad broker进行failover

1:开启主库和备库的闪回功能,主要用于主库恢复后的reinstate操作,当前主库为dg2,备库为dg1

READ WRITE           PRIMARY          dg2                  YES  

READ ONLY WITH APPLY PHYSICAL STANDBY dg1                  YES  

[oracle@dg1 ~]$ dgmgrl sys/123456@dg1  

    dg2 - Primary database  

    dg1 - Physical standby database  

SUCCESS 

2:关闭主库dg2,模拟主库故障

ORACLE instance shut down.  

ORA-01034: ORACLE not available  

ORA-16625: cannot reach database "dg2"  

DGM-17017: unable to determine configuration status 

3:执行failover

DGMGRL> failover to dg1;  

Performing failover NOW, please wait...  

Failover succeeded, new primary is "dg1"  

      Warning: ORA-16629: database reports a different protection level from the protection mode  

    dg2 - Physical standby database (disabled)  

      ORA-16661: the standby database needs to be reinstated  

WARNING 

4:重新启动原主库dg2

SQL> startup  

ORACLE instance started.  

Total System Global Area  417546240 bytes  

Fixed Size                  2228944 bytes  

Variable Size             352324912 bytes  

Database Buffers           54525952 bytes  

Redo Buffers                8466432 bytes  

Database mounted.  

ORA-16649: possible failover to another database prevents this database from  

being opened  

MOUNTED              PRIMARY          dg2                  YES 

5:执行reinstate操作

DGMGRL> reinstate database dg2;  

Reinstating database "dg2", please wait...  

Operation requires shutdown of instance "dg" on database "dg2"  

Shutting down instance "dg"...  

ORA-01109: database not open  

Database dismounted.  

Operation requires startup of instance "dg" on database "dg2"  

Starting instance "dg"...  

Unable to connect to database  

ORA-12514: TNS:listener does not currently know of service requested in connect descriptor  

Failed.  

Warning: You are no longer connected to ORACLE.  

Please complete the following steps and reissue the REINSTATE command:  

        start up and mount instance "dg" of database "dg2"  

SQL> conn /as sysdba  

Connected to an idle instance.  

Database opened.  

READ ONLY            PHYSICAL STANDBY dg2                  YES  

DGMGRL> enable database dg2;  

Error: ORA-16661: the standby database needs to be reinstated  

Reinstatement of database "dg2" succeeded  

总结

1:非到万不得已的情况,不使用failover,优先考虑switchover

2:若执行failover,则考虑使用sql命令完成

3:执行failover后,应及时备份数据,并重构dg环境

本文转自东方之子736651CTO博客,原文链接: http://blog.51cto.com/ecloud/1381881,如需转载请自行联系原作者

上一篇: scp命令