Sunday, March 23, 2008

1) Database Recovery:

First make a BACKUP of your datafiles, control files, archive log files, and initialization parameters file (init.ora) for your database that crashed.

A)
Complete Recovery: Recover all datafiles needing recovery up to the point of failure.
Check the datafiles needed recovery.

COL df# FORMAT 999
COL df_name FORMAT a20
COL tbsp_name FORMAT a10
COL status FORMAT a7
COL error FORMAT a10
 
SELECT r.FILE# AS df#, d.NAME AS df_name, t.NAME AS tbsp_name, 
       d.STATUS, r.ERROR, r.CHANGE#, r.TIME
FROM V$RECOVER_FILE r, V$DATAFILE d, V$TABLESPACE t
WHERE t.TS# = d.TS#
AND d.FILE# = r.FILE#


COL df# Clear
COL df_name Clear
COL tbsp_name Clear
COL status Clear
COL error Clear

1- Copy the datafiles that need recovery from the last backup.

2- sqlplus "/ as sysdba"
SQL> startup mount
SQL
> select * from v$datafile;

Shows status of datafiles, indicating those that are offline.
SQL> alter database datafile datafile path’ online;
Online the offline datafiles shown above, such as devl_PROD_01.dbf here.
SQL> set autorecovery on
Tells recovery not to ask which redo logs to use (in log_archive_dest).
SQL> recover database;
Recovers all datafiles, as needed, up to the current point in time.
SQL> alter database open;
Opens the database for user access.

You may also need to drop and recreate the TEMP tablespace after a database recovery. See Loss of TEMP Datafile on how to do this.

B) Incomplete Recovery: Recover upto point in the past before the failure occurs.

SQL> recover automatic database until time '2005-02-14:15:45:00';
Automatic is similar to Set Autorecovery On. Use 1 second before the time of failure or of the log to exclude, which, for Oracle 8.x and above, could be found using:
select to_char(a.time,'YYYY-MM-DD:HH24:MI:SS') as time, a.name from (select first_time as time, substr(name,1,58) as name, first_change# as change from v$archived_log union select first_time, 'Redo Log Group ' || to_char(group#), first_change# from v$log) a order by change;

SQL> recover database until cancel;
Accept logs until you type in CANCEL.
SQL> recover automatic database until change 43047423;

The system change numbers (SCN) contained in each archive log file is shown in Oracle 8.x and above using: select name,first_change#,next_change# - 1 from v$archived_log;
SQL> alter database open resetlogs;

Note:-
immediately shut down the database and make a BACKUP

No comments: