Oracle 10.2.0.1下新建的Dataguard的主备机间日志不同步,发生了“ORA-16416: 切换目标与主目标不同步”错误,通过在主库上重建一份standby controlfile,拷贝到备机替换原先的controlfile,重启即解决问题
主库上操作:
SQL> select database_role,open_mode,protection_mode,protection_level,switchover_status from v$database;
DATABASE_ROLE OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL SWITCHOVER_STATUS
---------------- ---------- -------------------- -------------------- --------------------
PRIMARY READ WRITE MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE SESSIONS ACTIVE
--尝试切换:
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> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN ;
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN
*
ERROR at line 1:
ORA-16416: Switchover target is not synchronized with the primary
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
// the switchover operation was attempted.
// *Action: Allow the switchover target to become synchronized and then
// re-attempt the switchover.
SQL>
shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL>
startup mount
ORACLE 例程已经启动。
Total System Global Area 243269632 bytes
Fixed Size 1218748 bytes
Variable Size 75499332 bytes
Database Buffers 163577856 bytes
Redo Buffers 2973696 bytes
数据库装载完毕。
SQL>
alter database create standby controlfile as '/data/rman_backup/sdtby_control01.ctl';
数据库已更改。
SQL>
alter database open;
数据库已更改。
先停止备库,再把生成的sdtby_control01.ctl文件拷贝到备机,替换掉原先备机的控制文件。
三个控制文件就复制三份,替换完原来的三个即可
然后在备库上操作:
SQL> startup mount;
ORACLE 例程已经启动。
Total System Global Area 243269632 bytes
Fixed Size 1218748 bytes
Variable Size 75499332 bytes
Database Buffers 163577856 bytes
Redo Buffers 2973696 bytes
数据库装载完毕。
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 OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL SWITCHOVER_STATUS
---------------- ---------- -------------------- -------------------- --------------------
PHYSICAL STANDBY MOUNTED MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE TO PRIMARY
SQL> select max(SEQUENCE#) from v$archived_log;
MAX(SEQUENCE#)
--------------
49
SQL> archive log list;
数据库日志模式 存档模式
自动存档 启用
存档终点 /orahome/arch
最早的联机日志序列 45
下一个存档日志序列 0
当前日志序列 50
现在v$archived_log表里有数据了。
再次切换
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN ;