一、问题说明
在做物理DG主备库切换时,遇到ORA-16139: media recovery required错误
在当前备库执行过程展示如下:
SQL> select name,DATABASE_ROLE from v$database;NAME DATABASE_ROLE
--------- ----------------
RUIADG PHYSICAL STANDBYSQL> select name,DATABASE_ROLE from v$database;NAME DATABASE_ROLE
--------- ----------------
RUIADG PHYSICAL STANDBYSQL> select switchover_status from v$database;SWITCHOVER_STATUS
--------------------
SWITCHOVER LATENTSQL> alter database commit to switchover to primary;
alter database commit to switchover to primary
*
ERROR at line 1:
ORA-16139: media recovery required
二、原因定位
怀疑可能是由于有日志未应用造成的,执行如下语句查询:
SQL> select APPLIED,SEQUENCE# from v$archived_log;APPLIED SEQUENCE#
--------- ----------
YES 9
YES 10
YES 10
YES 11
YES 11
YES 12
YES 12
YES 13
YES 13
NO 14
YES 14APPLIED SEQUENCE#
--------- ----------
NO 20
NO 17
NO 16
NO 15
NO 18
NO 19
NO 21
NO 22
NO 23
NO 24
NO 25APPLIED SEQUENCE#
--------- ----------
NO 26
NO 27
NO 28
NO 2926 rows selected.
果然有很多日志未应用。
三、处理方式
执行如下命令:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;Database altered.
再次执行切换命令:
SQL> alter database commit to switchover to primary;Database altered.
没有报错
此时查看数据库当前角色,已修改为Primary:
SQL> select name,DATABASE_ROLE from v$database;NAME DATABASE_ROLE
--------- ----------------
RUIADG PRIMARY