主库上操作:
SQL> select database_role,open_mode,protection_mode,protection_level,switchover_status from v$database;
DATABASE_ROLE
---------------- ---------- -------------------- -------------------- --------------------
PRIMARY
--尝试切换:
SQL> alter database commit to switchover to physical standby with session shutdown;
alter database commit to switchover to physical standby with session shutdown
*
第 1 行出现错误:
ORA-16416: 切换目标与主目标不同步
SQL> !oerr ora 16416
16416, 00000, "Switchover target is not synchronized with the primary"
// *Cause: The switchover target incurred an error or has a gap at the time
//
// *Action: Allow the switchover target to become synchronized and then
//
解决方法:
1、startup mount主库,创建备库控制文件,拷贝到备库机器;
SQL> alter database create standby controlfile as '/backup/sdtby_control01.ctl';
数据库已更改。
SQL> alter database open;
数据库已更改。
2、shutdown备库,替换控制文件,startup mount;
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS
-------------------- ----------------
RECOVERY NEEDED
SQL> alter database recover managed standby database disconnect from session;
数据库已更改。
SQL> select database_role,open_mode,protection_mode,protection_level,switchover_status from v$database;
DATABASE_ROLE
---------------- ---------- -------------------- -------------------- --------------------
PHYSICAL STANDBY MOUNTED
SQL> select max(SEQUENCE#) from v$archived_log;
MAX(SEQUENCE#)
--------------
最后验证一下主备库角色是否正确:
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS
-------------------- ----------------
SESSIONS ACTIVE
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS
-------------------- ----------------
TO PRIMARY