本次实验是基于之前的DG环境,具体环境搭建可参考:
http://blog.csdn.net/shiyu1157758655/article/details/55253132
我们配置DG的目的就是为了在主库出现故障时,备库能够提供服务,保证业务的正常运行。DG的故障切换分为switchover和failover两种:
登录主库
$sqlplus / as sysdba
SQL> select switchover_status from v$database;(查看主库状态)
查询结果是TO STANDBY 或 SESSIONS ACTIVE表明可以进行切换;
SQL> ALTER DATABASE COMMITTO SWITCHOVER TO PHYSICAL STANDBY;
SQL>shutdown immediate;
SQL> startup mount;
SQL> select database_role from v$database;
登录备库:
$sqlplus / as sysdba
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
TO PRIMARY 或 SESSIONS ACTIVE表明可以切换成主库;
现在可以把备库切换成主库了
SQL> alter database committo switchover to primary with session shutdown;
SQL> ALTER DATABASE OPEN;
SQL> select switchover_status,database_role,open_mode from v$database;
从上图可以看出,我们已经switchover切换成功了!
记住:这时候要在现在的备库上开启同步:
SQL> alter database recover managed standby database using current logfile disconnect from session;
为了能够在failover后能够恢复DG,需要在主库上开启flashback
关于开启flashback 可以参考:
http://blog.csdn.net/shiyu1157758655/article/details/55095760
如果不开启flashback的话,DG就要重新搭建
由于主库已经不可访问,我们所有的操作都在备库完成:
SQL> alter database recover managed standbydatabase cancel;
SQL> alter database recover managed standby database finish force;
SQL> select database_role from v$database;
SQL> alter database commit to switchover toprimary;
SQL> alter database open; 或者 shutdown immediate+startup
现在利用flashback重建DG
在新的主库上执行下面操作:
SQL> select to_char(standby_became_primary_scn) from v$database;
在之前的主库上,也就是现在的备库上执行下面的操作:
SQL>startup mount
SQL> flashback database to scn 9978113; //这个值为在新主库上查询到的SCN值
SQL> alter database convert to physical standby;
SQL> shutdown immediate
SQL> startup
SQL> alter database recover managed standby database using current logfile disconnect from session;
至此failover 切换和切换过如何恢复就已经完成
如果有配置错误还请不啬指出,欢迎加入oracle qq群: 425614362