1).模拟主库挂掉
====================
SQL>shutdown abort
====================
2).备库激活前准备
====================
a).将日志发送到备库(只能开一个节点)
--------------------
--主库能Mount则可以尝试一下方式;
SQL> startup mount;
SQL> alter system flush redo to '<target_standby_db_unique_name>';
--主库不能Mount则进行一下动作:
----在备库查看已经归档的最大sequence,和gap情况(gap需要解决一个再查询确认是否还有);
SQL> SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) OVER (PARTITION BY thread#) AS LAST from V$ARCHIVED_LOG;
SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
----将文件copy到备库之后进行恢复:
SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE '<path/file_name>';
--------------------
b).停止并结束备库日志应用
--------------------
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
--如果不能成功finish,则直接进激活,并打开数据库:
SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;
--如果finish成功之后,则确认是否可以切成primary
--------------------
c).确认是否可以切换
--------------------
--原备库执行, 返回值需要是:TO PRIMARY 或 SESSIONS ACTIVE
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
--如果可以则进行切换:
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
====================
3).打开数据库
====================
====================
SQL>shutdown abort
====================
2).备库激活前准备
====================
a).将日志发送到备库(只能开一个节点)
--------------------
--主库能Mount则可以尝试一下方式;
SQL> startup mount;
SQL> alter system flush redo to '<target_standby_db_unique_name>';
--主库不能Mount则进行一下动作:
----在备库查看已经归档的最大sequence,和gap情况(gap需要解决一个再查询确认是否还有);
SQL> SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) OVER (PARTITION BY thread#) AS LAST from V$ARCHIVED_LOG;
SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
----将文件copy到备库之后进行恢复:
SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE '<path/file_name>';
--------------------
b).停止并结束备库日志应用
--------------------
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
--如果不能成功finish,则直接进激活,并打开数据库:
SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;
--如果finish成功之后,则确认是否可以切成primary
--------------------
c).确认是否可以切换
--------------------
--原备库执行, 返回值需要是:TO PRIMARY 或 SESSIONS ACTIVE
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
--如果可以则进行切换:
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
====================
3).打开数据库
====================
SQL> ALTER DATABASE OPEN;
注:此方案参照官方文档外加自己理解进行翻译。