Oracle 查看需要recover的datafile v$recover_file 需要哪些归档日志

To easily and quickly find out if the online redo log files can be used to recover a database.

Scope

This document is addressed to DBAs that want to quickly find the best recovery solution in case of a database crash.

Details

Many databases today are run without archive logging enabled, this 
reduces the available options to quickly recover a database. Basically
2 options are available: 

   a) restore from a backup
   b) recover the database using the online redo logs.

Option a) is straight forward and will not be covered here. Only important
thing to mention is that option a) WILL cause loss of data if there has
been updates/inserts to the database since the backup was taken.

Let us instead take a look at option b):

In case of a database crash or a database that will not startup
due to ORA-1110, ORA-1113 or both, we first need to identify which 
files need to be recovered.

1) First we mount the database then issue the following query:

	select * from v$recover_file; 	

This will give us a list of the files that need media recovery. It
will also give us CHANGE#, i.e. the SCN where the media recovery
must start. To get the name of the file use the FILE# column and
query against v$datafile like this:

	select name from v$datafile
	where file# = 

or like this from 9i:

	select substr(d.name,1,30) fname
	,      r.online_status
	,      r.error
	,      r.change#
	,      r.time
	from v$datafile d, v$recover_file r
	where d.file# = r.file#

2) Next we do:

	archive log list

This will give us the current log sequence. We need the current
log sequence -1. This will give us the last redo log file that
was in use.

3) As the last step we do:
	select recid
	,      stamp
	,      sequence#
	,      first_change#
	,      next_change#
	from v$log_history
	where sequence# = /arch_129.arc
ORA-00280: change 12599 for thread 1 is in sequence #129
Specify log: {=suggested | filename | AUTO | CANCEL}

As the database is not in ARCHIVELOG mode we will not have the 129.arc
file. Instead the name of the redo log file must be entered on the
command line. The filename must include the full path. After the redo
log file has been applied the recover process will return: Log applied.
At this stage 2 things can happened: 

	1) Media Recovery Completed
	2) or additional redo log files must be applied

If 2) then just specify the next redo log file on the command line and
continue to do so until Media Recovery Completed is displayed. This must
be done with all the redo log files also the CURRENT redo log. To find the
CURRENT redo log file one can issue the following query:
   
        select f.member,to_char(v.first_change#)
        ,      v.sequence#  
        from   v$log v
        ,      v$logfile f 
        where  v.group# = f.group# 
        and    v.status='CURRENT';

When the CURRENT redo log has been applied the database can be opened with: 
alter database open;

It is necessary to apply all relevant redo logs otherwise we will not be
able to perform the complete recovery which is the only option we have
when the database is in NOARCHIVELOG mode.

If we do not find any online redo log files which covers the CHANGE# 
from 1) we cannot do a recover of the database or datafile(s). This 
means we are left with only 2 options of bringing the database back online:

1) Restore from a valid backup taken before the crash. Doing so and 
   running the database in NOARCHIVELOG MODE will cause a loss of data. 
   This is unavoidable.

2) Force the database open. This will override Oracle's internal 
   datafile synchronization and consistency check. The result is an 
   inconsistent database. The database MUST now be exported and rebuild 
   as an inconsistent database is unreliable, and hence not supported.
   This last option should only be used in cooperation with Oracle Support

你可能感兴趣的:(数据库,oracle)