=====先对主库操作(主库变备库)=======
2.先查询状态
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
switchover_status 有可能的值:TO STANDBY(可以切换)、SESSIONS ACTIVE(有活动会话,也可以切换,但是切换回导致会话断)、NOT ALLOWED(不允许切换,官方说不允许,但是有做实验成功的)
2.修改状态
执行Alter database commit to switchover to physical standby ;
或者alter database commit to switchover to physical standby with session shutdown;
--不管上面查的status是什么状态,都执行这个(最后not allowed状态暂时没试过)
3.关闭数据库(上面的操作好像已经把数据库关闭了,没关系再执行一次)
shutdown immediate;
4.起数据库到nomount状态
startup nomount;
5.起mount使用standby database
alter database mount standby database;
6.断开会话,应用redo apply
alter database recover managed standby database disconnect from session;
======备库的操作(备库变主库)=====================
1.先查询状态
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
2.将备库切成主库
执行alter database commit to switchover to primary with session shutdown;(status是TO STANDBY)
或者ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;(status是ACTIVE SESSION)
如果上面报
--如果报ORA-16139: media recovery required,可能是由于未应用日志引起,可先执行
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
3.关数据库(其实数据已经关闭,确认下较好)
shutdown immediate;
4.打开数据库
startup
==================测试=================
主库切换日志观察备库有没有新的日志被应用
select sequence#, first_time, next_time,applied from v$archived_log order by sequence#
SEQUENCE# FIRST_TIM NEXT_TIME APPLIED
---------- --------- --------- ---------
341 14-MAR-16 14-MAR-16 YES
342 14-MAR-16 14-MAR-16 YES
343 14-MAR-16 14-MAR-16 YES