Skip to main content

BLOCK RECOVERY

1) Create tablespace TEST
create tablespace TEST datafile '/u008/app/oradata/GOOGLE/test01.dbf' size 10m autoextend on next 10m maxsize 100m;


2) Create User TEST and grant him necessary privileges
create user test identified by test
default tablespace test;

grant dba to test;

3) Connect as TEST and create a table
create table test (no number);

4) Insert random records to this table
begin
for i in 1..1000000
loop
inset into test values(i);
end loop;
commit;
end;
/

5) Verify there are no corrupt blocks
dbv file=/u008/app/oradata/GOOGLE/test01.dbf blocksize=8192

DBVERIFY: Release 11.2.0.2.0 - Production on Fri Dec 10 11:27:40 2010

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

DBVERIFY - Verification starting : FILE = /u008/app/oradata/GOOGLE/test01.dbf


DBVERIFY - Verification complete

Total Pages Examined         : 2560
Total Pages Processed (Data) : 1568
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 161
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 831
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 934875 (0.934875)

6) Determine the blocks allocated to the TEST segment
SQL> SELECT DISTINCT MIN(DBMS_ROWID.ROWID_RELATIVE_FNO(rowid)) as FILE_NO,
   MIN(DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid)) as BLOCK_NO  FROM test.test;

   FILE_NO   BLOCK_NO
---------- ----------
         8        131

7) Query the EXTENT information for the TEST segment
SQL> select SEGMENT_NAME, SEGMENT_TYPE, TABLESPACE_NAME, EXTENT_ID, FILE_ID,BLOCK_ID,BLOCKS from dba_extents where owner='TEST' and segment_name='TEST';
SEGMENT_NA SEGMENT_TYPE       TABLESPACE_NAME                 EXTENT_ID    FILE_ID   BLOCK_ID     BLOCKS
---------- ------------------ ------------------------------ ---------- ---------- ---------- ----------
TEST       TABLE              TEST                                    0          8        128          8
TEST       TABLE              TEST                                    1          8        136          8
TEST       TABLE              TEST                                    2          8        144          8
TEST       TABLE              TEST                                    3          8        152          8
TEST       TABLE              TEST                                    4          8        160          8
TEST       TABLE              TEST                                    5          8        168          8
TEST       TABLE              TEST                                    6          8        176          8
TEST       TABLE              TEST                                    7          8        184          8
TEST       TABLE              TEST                                    8          8        192          8
TEST       TABLE              TEST                                    9          8        200          8
TEST       TABLE              TEST                                   10          8        208          8
TEST       TABLE              TEST                                   11          8        216          8
TEST       TABLE              TEST                                   12          8        224          8
TEST       TABLE              TEST                                   13          8        232          8
TEST       TABLE              TEST                                   14          8        240          8
TEST       TABLE              TEST                                   15          8        248          8
TEST       TABLE              TEST                                   16          8        256        128
TEST       TABLE              TEST                                   17          8        384        128
TEST       TABLE              TEST                                   18          8        512        128
TEST       TABLE              TEST                                   19          8        640        128
TEST       TABLE              TEST                                   20          8        768        128
TEST       TABLE              TEST                                   21          8        896        128
TEST       TABLE              TEST                                   22          8       1024        128
TEST       TABLE              TEST                                   23          8       1152        128
TEST       TABLE              TEST                                   24          8       1280        128
TEST       TABLE              TEST                                   25          8       1408        128
TEST       TABLE              TEST                                   26          8       1536        128
TEST       TABLE              TEST                                   27          8       1664        128

8) Add primary key constraint - as a proof that we don't have any corruption in the TEST segment
SQL> alter table test add constraint pk_no_test primary key(no);

Table altered.


9) You can see the total number of records in the TEST segment
SQL> select count(*) from test.test;

  COUNT(*)
----------
   1000000

10) You can analyze the TEST segment - which proves there is no corruption
SQL> analyze table test.test validate structure;

Table analyzed.

11) Flush the buffers (if any) to disk
SQL> ALTER SYSTEM FLUSH BUFFER_CACHE;

System altered.

12) Verify that you have a backup of TEST tablespace - if not take a backup
RMAN>  list backup of tablespace "TEST";

using target database control file instead of recovery catalog

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


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1       Full    1.00G      DISK        00:01:35     10-DEC-10
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20101210T112407
        Piece Name: /u008/rman_bkp/03lv70an_1_1.rman
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  8       Full 934951     10-DEC-10 /u008/app/oradata/GOOGLE/test01.dbf


13) Corrupt the block number 131 (obtained from the above query) by writting random data
dd of=/u008/app/oradata/GOOGLE/test01.dbf bs=8192 conv=notrunc seek=131 <<EOF
CORRUPT corrupt CORRUPT corrupt CORRUPT corrupt CORRUPT corrupt CORRUPT corrupt
EOF
0+1 records in
0+1 records out
80 bytes (80 B) copied, 0.0266781 seconds, 3.0 kB/s

14) Corrupt one more block number 132 by writting random data
dd of=/u008/app/oradata/GOOGLE/test01.dbf bs=8192 conv=notrunc seek=132 <<EOF
CORRUPT THIS BLOCK. A LONGER String may be NEEDED. This makes a longer stringx
EOF
0+1 records in
0+1 records out
79 bytes (79 B) copied, 0.0109626 seconds, 7.2 kB/s

15) Prove that this has corrupted the TEST segment
SQL> select count(*) from test;
select count(*) from test
                     *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 8, block # 131)
ORA-01110: data file 8: '/u008/app/oradata/GOOGLE/test01.dbf'

16) Another proof that the segment TEST is corrupt
SQL> analyze table test validate structure;
analyze table test validate structure
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 8, block # 131)
ORA-01110: data file 8: '/u008/app/oradata/GOOGLE/test01.dbf'

17) Normal backup of this datafile would also fail
RMAN> backup tablespace "TEST" format='/u008/rman_bkp/%U.rman';

Starting backup at 10-DEC-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=25 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=00008 name=/u008/app/oradata/GOOGLE/test01.dbf
channel ORA_DISK_1: starting piece 1 at 10-DEC-10
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 12/10/2010 11:43:42
ORA-19566: exceeded limit of 0 corrupt blocks for file /u008/app/oradata/GOOGLE/test01.dbf


18) DB Verify confirms that the datafile has 2 corrupted blocks 131 and 132
[oracle@oracle6 ~]$ dbv file=/u008/app/oradata/GOOGLE/test01.dbf blocksize=8192

DBVERIFY: Release 11.2.0.2.0 - Production on Fri Dec 10 11:44:04 2010

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

DBVERIFY - Verification starting : FILE = /u008/app/oradata/GOOGLE/test01.dbf
Page 131 is marked corrupt
Corrupt block relative dba: 0x02000083 (file 8, block 131)
Bad header found during dbv:
Data in bad block:
type: 67 format: 7 rdba: 0x20545055
last change scn: 0x7075.72726f63 seq: 0x74 flg: 0x20
spare1: 0x52 spare2: 0x52 spare3: 0x5252
consistency value in tail: 0x43db0601
check value in block header: 0x4f43
block checksum disabled

Page 132 is marked corrupt
Corrupt block relative dba: 0x02000084 (file 8, block 132)
Bad header found during dbv:
Data in bad block:
type: 67 format: 7 rdba: 0x20545055
last change scn: 0x4220.53494854 seq: 0x4c flg: 0x4f
spare1: 0x52 spare2: 0x52 spare3: 0x202e
consistency value in tail: 0x43db0601
check value in block header: 0x4b43
computed block checksum: 0x4f15



DBVERIFY - Verification complete

Total Pages Examined         : 5120
Total Pages Processed (Data) : 1566
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 2092
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 203
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 1257
Total Pages Marked Corrupt   : 2
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 936009 (0.936009)



19) But since RMAN has failed on the first corrupted block the view shows corrupt count as 1
SQL> select * from v$database_block_corruption;

     FILE#     BLOCK#     BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
         8        131          1                  0 CORRUPT


20) Force RMAN to complete the backup of datafile even when we have corrupt blocks. Use MAXCORRUPT clause.
This would populate the v$database_block_corruption view with the total number of blocks found corrupt

run {
set maxcorrupt for datafile "/u008/app/oradata/GOOGLE/test01.dbf" to 10;
backup tablespace "TEST" format='/u008/rman_bkp/%U.rman';
}

executing command: SET MAX CORRUPT

Starting backup at 10-DEC-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00008 name=/u008/app/oradata/GOOGLE/test01.dbf
channel ORA_DISK_1: starting piece 1 at 10-DEC-10
channel ORA_DISK_1: finished piece 1 at 10-DEC-10
piece handle=/u008/rman_bkp/08lv720m_1_1.rman tag=TAG20101210T115254 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 10-DEC-10


21) Now it reports that there are 2 corrupt blocks
SQL> select * from v$database_block_corruption;

     FILE#     BLOCK#     BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
         8        131          2                  0 CORRUPT


22) Perform block media recovery for all the corrupt blocks
RMAN> recover corruption list;

Starting recover at 10-DEC-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=147 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 00008
channel ORA_DISK_1: reading from backup piece /u008/rman_bkp/08lv720m_1_1.rman
channel ORA_DISK_1: piece handle=/u008/rman_bkp/08lv720m_1_1.rman tag=TAG20101210T115254
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:05
failover to previous backup

channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00008
channel ORA_DISK_1: reading from backup piece /u008/rman_bkp/03lv70an_1_1.rman
channel ORA_DISK_1: piece handle=/u008/rman_bkp/03lv70an_1_1.rman tag=TAG20101210T112407
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:03

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

Finished recover at 10-DEC-10



23) DB Verify now confirms that there are no corrupt blocks after recovery
[oracle@oracle6 ~]$ dbv file=/u008/app/oradata/GOOGLE/test01.dbf blocksize=8192

DBVERIFY: Release 11.2.0.2.0 - Production on Fri Dec 10 11:58:49 2010

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

DBVERIFY - Verification starting : FILE = /u008/app/oradata/GOOGLE/test01.dbf


DBVERIFY - Verification complete

Total Pages Examined         : 5120
Total Pages Processed (Data) : 1568
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 2092
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 203
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 1257
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 936009 (0.936009)


24) Proof that the TEST segment has no corrupt block;
SQL>  select count(*) from test;

  COUNT(*)
----------
   1000000

25) Another proof that the TEST segment has no corrupt block;
SQL> analyze table test validate structure;

Table analyzed.


26) RMAN backup of the datafile now completes without MAXCORRUPT clause
RMAN> backup tablespace "TEST" format='/u008/rman_bkp/%U.rman';

Starting backup at 10-DEC-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=143 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=00008 name=/u008/app/oradata/GOOGLE/test01.dbf
channel ORA_DISK_1: starting piece 1 at 10-DEC-10
channel ORA_DISK_1: finished piece 1 at 10-DEC-10
piece handle=/u008/rman_bkp/09lv72fk_1_1.rman tag=TAG20101210T120052 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 10-DEC-10


Comments

Popular posts from this blog

Hard dependency with ip address Oracle RAC Cluster.

Command error out due to hard dependency with ip address [-Node1]/app/grid/oracle/product/11.2.0/grid/bin>./crsctl relocate resource RDBMS_DB -n Node2 CRS-2527: Unable to start 'RDBMS_DB' because it has a 'hard' dependency on 'sDB' CRS-2525: All instances of the resource 'sDB' are already running; relocate is not allowed because the force option was not specified CRS-4000: Command Relocate failed, or completed with errors. [-Node1]/app/grid/oracle/product/11.2.0/grid/bin>./crsctl relocate resource sDB  -n Node2 CRS-2529: Unable to act on 'DB' because that would require stopping or relocating 'LISTENER_DB', but the force option was not specified CRS-4000: Command Relocate failed, or completed with errors. [-Node1]/app/grid/oracle/product/11.2.0/grid/bin>./crsctl relocate resource LISTENER_DB  -n Node2 CRS-2527: Unable to start 'LISTENER_DB' because it has a 'hard' dependency on 'sD...

19C NID ( Rename Database)

 [oracle@localhost ~]$ nid DBNEWID: Release 19.0.0.0.0 - Production on Thu Dec 23 00:05:36 2021 Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved. Keyword     Description                    (Default) ---------------------------------------------------- TARGET      Username/Password              (NONE) DBNAME      New database name              (NONE) LOGFILE     Output Log                     (NONE) REVERT      Revert failed change           NO SETNAME     Set a new database name only   NO APPEND      Append to output log           NO HELP        Displays these messages    ...

ORA-01017/ORA-28000 with AUDIT_TRAIL

With default profile in Oracle 11g, accounts are automatically locked 1 day ( PASSWORD_LOCK_TIME ) after 10 failed login attempt ( FAILED_LOGIN_ATTEMPTS ): SQL > SET lines 200 SQL > SET pages 200 SQL > SELECT * FROM dba_profiles WHERE PROFILE = 'DEFAULT' ORDER BY resource_name; PROFILE                         RESOURCE_NAME                      RESOURCE LIMIT ------------------------------ -------------------------------- -------- ---------------------------------------- DEFAULT                         COMPOSITE_LIMIT                 ...