如果有一天你的主库宕机了,然后起不来了,或者机器能起来,但是你不敢确认数据库能起来,现在盘柜是没有损坏的,能够挂载到其他主机并能正常访问的,这时你应该先把主库上所有的联机日志做一个备份,然后再做其他动作。下面来做这个试验。
Standby Database为物理备库,采用最大性能模式,并使用arch方式传递日志。
现在在主库上建一张表,然后插入一些数据:
create table test as select * from dba_objects;
commit;
select count(*) from test;
COUNT(*)
----------
5752
然后模拟主机宕机,数据库crash掉:
shutdown abort;
因为插入的数据量比较小,还不至于引起归档,所以备库上是没有应用该日志的,也就没有这张表:
select count(*) from test
*
ERROR at line 1:
ORA-00942: table or view does not exist
这时你是不是想着去failover备库啊,别急,先检查一下备库是不是把所有的日志都应用了:
select max(a.sequence#), max(b.sequence#) from v$archived_log a, v$log b where a.dest_id=2 and b.archived='YES';
MAX(A.SEQUENCE#) MAX(B.SEQUENCE#)
---------------- ----------------
62 66
在这肯定是没有应用全的,如果failover了肯定会丢失一部分数据,所以要做恢复了:
alter database recover managed standby database cancel;
recover automatic standby database;
ORA-00279: change 31825494112 generated at 09/11/2008 16:05:56 needed for thread 1
ORA-00289: suggestion : /u02/orcl/arch/TEST/1_66.dbf
ORA-00280: change 31825494112 for thread 1 is in sequence #66
ORA-00278: log file '/u02/orcl/arch/TEST/1_66.dbf' no longer needed for this recovery
ORA-00308: cannot open archived log '/u02/orcl/arch/TEST/1_66.dbf'
ORA-27037: unable to obtain file status
HP-UX Error: 2: No such file or directory
Additional information: 3
Specify log: {
/u02/orcl/arch/TEST/redo01.log
ORA-00310: archived log contains sequence 65; sequence 66 required
ORA-00334: archived log: '/u02/orcl/arch/TEST//redo01.log'
提示要下一个归档日志的时候,手动指定第一个联机日志,报ORA-00310错误,看来这个不是想要的联机日志,指定下一个:
recover automatic standby database;
ORA-00279: change 31825494112 generated at 09/11/2008 16:05:56 needed for thread 1
ORA-00289: suggestion : /u02/orcl/arch/TEST/1_66.dbf
ORA-00280: change 31825494112 for thread 1 is in sequence #66
ORA-00278: log file '/u02/orcl/arch/TEST/1_66.dbf' no longer needed for this recovery
ORA-00308: cannot open archived log '/u02/orcl/arch/TEST/1_66.dbf'
ORA-27037: unable to obtain file status
HP-UX Error: 2: No such file or directory
Additional information: 3
Specify log: {
/u02/orcl/arch/TEST/redo02.log
Log applied.
Media recovery complete.
日志被成功应用了,看来这个思路是正确的,打开数据库,看看数据是否正确:
alter database open read only;
select count(*) from test;
COUNT(*)
----------
5752
数据被成功恢复,然后就可以转换为主库了。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/339291/viewspace-446880/ ,如需转载,请注明出处,否则将追究法律责任。