停止空想

老张的空中之家

如何用RMAN检测数据库的物理或逻辑corruption

作者:admin 发表时间:五月 - 6 - 2009
***
This article is being delivered in Draft form and may contain
errors.  Please use the MetaLink "Feedback" button to advise
Oracle of any issues related to this article.
***

PURPOSE
-------
To explain how RMAN can be used to check for both logical and physical corruption.

SCOPE & APPLICATION
-------------------
This document is intended for database adminstrators of all levels.

Note: No need that RMAN has been used or setup previously.  There is no need for
      a recovery catalog.  No backup is created.  Since a single channel is
      being allocated there is little overhead. The only requirement is that
      Oracle8i or later has to be used and the database is mounted (required
      for a noarchivelog mode database) or open.

During a RMAN backup or RMAN 'backup validate' every block currently used or
previously used is read into memory then written to another portion of memory.
During this memory to memory write the block is checked for corruption.
Therefore RMAN's BACKUP command with the VALIDATE and CHECK LOGICAL clauses
allow a Database Adminstrator to quickly check for both physical and logical
corruption. If the initialization parameter DB_BLOCK_CHECKSUM=TRUE, specifying
CHECK LOGICAL detects all types of corruption that are possible to detect.

How To Use RMAN To Check For Logical And Physical Block Corruption
-------------------------------------------------------------------
            ***  For databases in noarchivelog mode, ***
            ***  the commands that follow only work  ***
            ***  while the database is in mount mode ***

1)  For version 9.2 or higher, query v$database_block_corruption to see if
    there are any rows already listed there.

2)  Set your $ORACLE_SID and $ORACLE_HOME appropriately if not already set.

3)  Start RMAN in nocatalog mode and connect to your database:

From the operating system prompt issue:

      $ rman target / nocatalog

        or

      $ rman target sys/<sys_password> nocatalog

4)  From the RMAN> prompt issue the validate command with the "check logical"
clause:

The following example shows how to validate all datafiles:

       run {
       allocate channel d1 type disk;
       backup check logical validate database;
       release channel d1;
       }

You'll see output like this:

   Starting backup at 15-SEP-04
   allocated channel: ORA_DISK_1
   channel ORA_DISK_1: sid=17 devtype=DISK
   channel ORA_DISK_1: starting full datafile backupset
   channel ORA_DISK_1: specifying datafile(s) in backupset
   input datafile fno=00001 name=C:\ORACLE\ORADATA\ORA92\SYSTEM01.DBF
   input datafile fno=00002 name=C:\ORACLE\ORADATA\ORA92\UNDOTBS01.DBF
   input datafile fno=00005 name=C:\ORACLE\ORADATA\ORA92\EXAMPLE01.DBF
   input datafile fno=00010 name=C:\ORACLE\ORADATA\ORA92\XDB01.DBF
   input datafile fno=00006 name=C:\ORACLE\ORADATA\ORA92\INDX01.DBF
   input datafile fno=00009 name=C:\ORACLE\ORADATA\ORA92\USERS01.DBF
   input datafile fno=00003 name=C:\ORACLE\ORADATA\ORA92\CWMLITE01.DBF
   input datafile fno=00004 name=C:\ORACLE\ORADATA\ORA92\DRSYS01.DBF
   input datafile fno=00007 name=C:\ORACLE\ORADATA\ORA92\ODM01.DBF
   input datafile fno=00008 name=C:\ORACLE\ORADATA\ORA92\TOOLS01.DBF

        <<<<< SCREEN OUTPUT MAY PAUSE HERE FOR A WHILE >>>>>

   channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
   Finished backup at 15-SEP-04

The following example shows how to validate a single datafile:

       run {
       allocate channel d1 type disk;
       backup check logical validate datafile 1;
       release channel d1;
       }

The following example shows how to validate two datafiles:

       run {
       allocate channel d1 type disk;
       backup check logical validate datafile 1, 2;
       release channel d1;
       }

The following example shows how to run a validate with multiple channels.  This
is helpful for very large databases, datafiles, etc:

       run {
       allocate channel d1 type disk;
       allocate channel d2 type disk;
       backup check logical validate database;
       release channel d1;
       release channel d2;
       }

If you wish to monitor the progress of RMAN backup validate, you may issue this
query:

  SQL> select sid, serial#, context, sofar, totalwork,
       round(sofar/totalwork*100,2) "%_complete"
       from v$session_longops
       where opname like 'RMAN%'
         and opname not like '%aggregate%'
         and totalwork != 0
         and sofar <> totalwork
         /

5)  Once the validate process is complete, you either check the alert log or a
    view depending on the version of Oracle being used.  

In Oracle8i corruptions found with the RMAN validate command are only reported
in the alert log.  Oracle8i users must search the alert.log for corruption
errors in the time range during which the validate command was started and when
it finished. Corruptions found are NOT reported back to the RMAN interface.

In Oracle9i and beyond you can query the view name V$DATABASE_BLOCK_CORRUPTION
to determine what corruption, if any, was found by RMAN.  As in Oracle8i,
corruptions found are NOT reported back to the RMAN interface. 

Note that corruption reported in V$DATABASE_BLOCK_CORRUPTION is cleared with each
RMAN backup validate run.  If new corruption is found this view is updated with
the new corruption details. Rows in this view are not removed until another
RMAN backup validate or RMAN backup is run AND during which corruption for a block
is longer detected. To understand what is reported in this view, see the description
of the view as shown in the manual titled Database Reference.
类别:Oracle

发表评论