Search This Blog

Total Pageviews

Friday 29 April 2011

Oracle Block recovey using RMAN

RMAN Block RECOVERY
perform Block Media Recovery using RMAN
ORA-01578: ORACLE data block corrupted
RMAN RECOVER BLOCK


SQL> select FILE_NAME from dba_data_files ;

FILE_NAME
--------------------------------------------------------------------------------
/opt/app/oracle/oradata/orcl/users01.dbf
/opt/app/oracle/oradata/orcl/undotbs01.dbf
/opt/app/oracle/oradata/orcl/sysaux01.dbf
/opt/app/oracle/oradata/orcl/system01.dbf
/opt/app/oracle/oradata/orcl/example01.dbf



SQL> create tablespace anujtest datafile '/opt/app/oracle/oradata/orcl/anujtest.dbf' size 10m
autoextend on next 5m extent management local segment space management auto ;

Tablespace created.


apt-lnxtst-01:ORCL\sys> create user anujtest identified by anujtest default tablespace anujtest quota unlimited on anujtest ;

User created.



grant connect , resource to anujtest ;


apt-lnxtst-01:ORCL\sys> conn anujtest/anujtest
Connected.


orcl\anujtest> connect / as sysdba
Connected.



apt-lnxtst-01:ORCL\sys>conn anujtest/anujtest
Connected.

orcl\anujtest> create table test as select * from all_objects ;
Table created.



SQL> connect / as sysdba
Connected.
SQL> col FILE_NAME format a50
SQL> select FILE_NAME,FILE_ID from dba_data_files;

FILE_NAME FILE_ID
-------------------------------------------------- ----------
/opt/app/oracle/oradata/orcl/users01.dbf 4
/opt/app/oracle/oradata/orcl/undotbs01.dbf 3
/opt/app/oracle/oradata/orcl/sysaux01.dbf 2
/opt/app/oracle/oradata/orcl/system01.dbf 1
/opt/app/oracle/oradata/orcl/example01.dbf 5
/opt/app/oracle/oradata/orcl/anujtest.dbf 6 <<<<<<<<<<<<-------

6 rows selected.


RMAN> connect target /

connected to target database: ORCL (DBID=1267852645)

RMAN> backup datafile 6 tag=good;

Starting backup at 29-APR-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=53 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/opt/app/oracle/oradata/orcl/anujtest.dbf
channel ORA_DISK_1: starting piece 1 at 29-APR-11
channel ORA_DISK_1: finished piece 1 at 29-APR-11
piece handle=/opt/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_29/o1_mf_nnndf_GOOD_6vnsol06_.bkp tag=GOOD comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 29-APR-11



RMAN> list backup;


List of Backup Sets
===================


BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1 Full 7.48M DISK 00:00:01 29-APR-11
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: GOOD
Piece Name: /opt/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_29/o1_mf_nnndf_GOOD_6vnsol06_.bkp
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
6 Full 7522958 29-APR-11 /opt/app/oracle/oradata/orcl/anujtest.dbf


RMAN>Ctrl+d or exit

Recovery Manager complete.


SQL> col SEGMENT_NAME format a20



SQL> r
1 select segment_name , header_file , header_block from dba_segments
2 where segment_name = 'TEST'
3* and owner = 'ANUJTEST'

SEGMENT_NAME HEADER_FILE HEADER_BLOCK
-------------------- ----------- ------------
TEST 6 130



to get file name



col name format a70
select a.name from v$datafile a , dba_segments b
where a.file#=b.header_file and b.segment_name='TEST'

NAME
----------------------------------------------------------------------
/opt/app/oracle/oradata/orcl/anujtest.dbf



The header of the table is in block 130, so if the block 131 or so are corrupted we will get an error when we try to select data from the table.
Lets corrupt block 12 using the "dd" command in Linux.



oracle@apt-amd-02:/opt/app/oracle/oradata/orcl> dd of=anujtest.dbf bs=8192 conv=notrunc seek=130 << EOF
anuj Corrupted.
EOF

0+1 records in
0+1 records out
16 bytes (16 B) copied, 0.000109246 s, 146 kB/s


SQL> select count(*) from anujtest.test ; ----- because whole table in cache

COUNT(*)
----------
55632

SQL> alter system flush buffer_cache;

System altered.

SQL> select count(*) from anujtest.test ;
select count(*) from anujtest.test
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 6, block # 130)
ORA-01110: data file 6: '/opt/app/oracle/oradata/orcl/anujtest.dbf'



oracle@apt-amd-02:/opt/app/oracle/oradata/orcl> rman

Recovery Manager: Release 11.2.0.1.0 - Production on Fri Apr 29 07:45:30 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

RMAN> connect target /

connected to target database: ORCL (DBID=1267852645)

RMAN> BLOCKRECOVER DATAFILE 6 BLOCK 130;

Starting recover at 29-APR-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=50 device type=DISK

channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00006
channel ORA_DISK_1: reading from backup piece /opt/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_29/o1_mf_nnndf_GOOD_6vnsol06_.bkp
channel ORA_DISK_1: piece handle=/opt/app/oracle/flash_recovery_area/ORCL/backupset/2011_04_29/o1_mf_nnndf_GOOD_6vnsol06_.bkp tag=GOOD
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:01

starting media recovery
media recovery complete, elapsed time: 00:00:08

Finished recover at 29-APR-11

RMAN>


now block recovered


SQL> select count(*) from anujtest.test ;

COUNT(*)
----------
55632

ORA-19809: limit exceeded for recovery files

if following error occurred on Oracle database or database hanged due to this error


Errors in file /opt/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_arc3_1202.trc:
ORA-19809: limit exceeded for recovery files
ORA-19804: cannot reclaim 44131328 bytes disk space from 4070572032 limit
ARC3: Error 19809 Creating archive log file to '/opt/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_29/o1_mf_1_330_%u_.arc'




check space is fill !!!!!!!!!

set lines 100
col name format a60
select name
, floor(space_limit / 1024 / 1024) "Size MB"
, ceil(space_used / 1024 / 1024) "Used MB"
from v$recovery_file_dest
order by name
/



oracle@apt-amd-02:~> id
uid=1001(oracle) gid=1000(oinstall) groups=1000(oinstall)
oracle@apt-amd-02:~> rman

Recovery Manager: Release 11.2.0.1.0 - Production on Fri Apr 29 06:56:30 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.


RMAN> connect target /

connected to target database: ORCL (DBID=1267852645)

RMAN> delete force archivelog until time 'sysdate -1'; ---- delete some archive log file

using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=50 device type=DISK
List of Archived Log Copies for database with db_unique_name ORCL
=====================================================================

Key Thrd Seq S Low Time
------- ---- ------- - ---------
91 1 330 A 13-APR-11
Name: /opt/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_29/o1_mf_1_330_6vnqzs5c_.arc

92 1 331 A 13-APR-11
Name: /opt/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_29/o1_mf_1_331_6vnr0q87_.arc

93 1 332 A 13-APR-11
Name: /opt/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_29/o1_mf_1_332_6vnr0x7c_.arc


Do you really want to delete the above objects (enter YES or NO)? yes
deleted archived log
archived log file name=/opt/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_29/o1_mf_1_330_6vnqzs5c_.arc RECID=91 STAMP=749717522
deleted archived log
archived log file name=/opt/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_29/o1_mf_1_331_6vnr0q87_.arc RECID=92 STAMP=749717587
deleted archived log
archived log file name=/opt/app/oracle/flash_recovery_area/ORCL/archivelog/2011_04_29/o1_mf_1_332_6vnr0x7c_.arc RECID=93 STAMP=749717596
Deleted 3 objects


check all the file deleted ....

RMAN> delete force archivelog until time 'sysdate -1';

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=50 device type=DISK
specification does not match any archived log in the repository

Oracle DBA

anuj blog Archive