
测试环境:Windows Server 2003 Enterprise Edition SP2
数据库环境:Oracle 10.2
我们来继续上回实验操作,当我们实现主备库同步后,接下来讲讲主备库是如何切换的?
1、确认主库可以进行角色切换,首先查看SWITCHOVER_STATUS值是什么,执行以下语句:
SQL> select switchover_status from v$database;SWITCHOVER_STATUS--------------------SESSIONS ACTIVE
如果返回TO STANDBY 或 SESSIONS ACTIVE,那么主库可以进行切换。
[主库切换操作]
如果SWITCHOVER_STATUS为 TO STANDBY,执行:
SQL> alter database commit to switchover to physical standby;SQL> shutdown immediateSQL> startup mount
如果SWITCHOVER_STATUS值为 SESSIONS ACTIVE,则执行:
SQL> alter database commit to switchover to physical standby with session shutdown;SQL> shutdown immediateSQL> startup mount
本次试验SWITCHOVER_STATUS值为 SESSIONS ACTIVE ,所以执行结果如下:
SQL> alter database commit to switchover to physical standby with session shutdown;数据库已更改。SQL> shutdown immediateORA-01507: 未装载数据库ORACLE 例程已经关闭。SQL> startup mountORACLE 例程已经启动。Total System Global Area 289406976 bytesFixed Size 2003752 bytesVariable Size 100666584 bytesDatabase Buffers 184549376 bytesRedo Buffers 2187264 bytes数据库装载完毕。
[备库切换操作]
2、刚配置完备库并同步后,第一次执行以下语句:
SQL> select switchover_status from v$database;SWITCHOVER_STATUS--------------------NOT ALLOWED
显示SWITCHOVER_STATUS的值为NOT ALLOWED,这是正常现象,官方文档解释为NOT ALLOWED - Either this is a standby database and the primary database has not been switched first or this is a primary database and there are no standby databases.
即第一次这种状态是正常的,当你先把主库switchover 后,备库就由not allow 变成 to primary了。
SQL> select switchover_status from v$database;SWITCHOVER_STATUS--------------------TO PRIMARY
3、将备库切换,由于SWITCHOVER_STATUS值为 TO PRIMARY,故而执行以下语句:
SQL> alter database commit to switchover to primary;数据库已更改。SQL> alter database open;数据库已更改。
如果是SWITCHOVER_STATUS值为 SESSIONS ACTIVE,则执行:
SQL>alter database commit to switchover to primary with session shutdown;
至此,Oracle Data Guard详细配置已完成了,谢谢各位XDJM捧场!
【完毕】






