怕以后忘了,做个试验记录一下,这个switch比较常规
1】主--备库先查一遍,如下的话就可以开始了两者当前序列一致角色状态如下--主库SQL> archive log list;数据库日志模式 存档模式自动存档 启用存档终点 /u01/app/oracle/oradata/test/flash_recovery_area最早的联机日志序列 524下一个存档日志序列 526当前日志序列 526SQL> select switchover_status,database_role from v$database;SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------TO STANDBY PRIMARY--备库
SQL> archive log list;数据库日志模式 存档模式自动存档 启用存档终点 /u01/app/oracle/oradata/test/flash_recovery_area最早的联机日志序列 524下一个存档日志序列 0当前日志序列 526SQL> select switchover_status,database_role from v$database;SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------NOT ALLOWED PHYSICAL STANDBY2】切换
--主库--将primary角色转换为standby角色SQL> alter database commit to switchover to physical standby;数据库已更改。
SQL> shutdown immediateORA-01012: not logged on--shutdown immediate
SQL> startup mountORACLE 例程已经启动。Total System Global Area 3975139328 bytes
Fixed Size 2259360 bytesVariable Size 2768242272 bytesDatabase Buffers 1191182336 bytesRedo Buffers 13455360 bytes数据库装载完毕。mount之后原主库成了备库
SQL> select switchover_status,database_role from v$database;SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------RECOVERY NEEDED PHYSICAL STANDBY--备库
--查看standby状态SQL> select switchover_status,database_role from v$database;SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------SESSIONS ACTIVE PHYSICAL STANDBY--将--备库的角色修改为primary
/*执行下面时需要关闭其他sql窗口,否则报下面的错SQL> alter database commit to switchover to primary;
alter database commit to switchover to primary*第 1 行出现错误:ORA-01093: ALTER DATABASE CLOSE 仅允许在没有连接会话时使用*/确认没有会话连接了执行结果
SQL> alter database commit to switchover to primary;数据库已更改。
原备库变成原主库那样了,
SQL> select switchover_status,database_role from v$database;SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------NOT ALLOWED PRIMARY原主库呢,刚才mount了,需要recover,现在新主库也open了,可以开始recover了
SQL> select status from v$instance;STATUS
------------MOUNTEDSQL> alter database recover managed standby database disconnect from session;
SQL> recover managed standby database cancel;
完成介质恢复。SQL> alter database open;数据库已更改。
开启实时应用
SQL> alter database recover managed standby database using current logfile disconnect from session;数据库已更改。
--这时新备库正常了
SQL> select switchover_status,database_role from v$database;SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------NOT ALLOWED PHYSICAL STANDBY检查】
新主库切换日志查看下两边序列是否一致(简单方式)alter system switch logfile;archive log list;查看主、备库是否有gap
SELECT STATUS,GAP_STATUS FROM V$ARCHIVE_DEST_STATUS WHERE DEST_ID=2;