Oracle不良ブロック修復処理の実験

13591 ワード

不良ブロックは物理不良ブロックと論理不良ブロックに分けられ,前者はハードウェア問題発生,後者はoracle内部データに問題があり,今回の実験では後者について行った.
データベースのアーカイブ・モードの有効化
[oracle@cancer ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu Oct 15 17:09:40 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> archive log lst
SP2-0718: illegal ARCHIVE LOG option
SQL> archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     4
Current log sequence           6
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  784998400 bytes
Fixed Size                  2257352 bytes
Variable Size             515903032 bytes
Database Buffers          264241152 bytes
Redo Buffers                2596864 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

1.実験に必要な表領域、ユーザー、表および関連実験データの作成
1.1関連表領域とユーザーの作成
--       1m    
create tablespace test
datafile '/u01/oracle/oradata/orcl/test01.dbf' size 1m;
--  test  
create user test identified by test default tablespace test temporary tablespace temp profile DEFAULT;
--         
grant connect,dba,resource,unlimited tablespace to test;

1.2表とシミュレーションデータの作成
SQL> create table test tablespace test as select * from scott.emp;

Table created.

SQL> insert into test select * from test;

14 rows created.

SQL> insert into test select * from test;

28 rows created.

.....

3584 rows created.

SQL> insert into test select * from test;

7168 rows created.

SQL> commit;

Commit complete.

SQL> insert into test select * from test;
insert into test select * from test
*
ERROR at line 1:
ORA-01653: unable to extend table TEST.TEST by 8 in tablespace TEST

SQL> select count(*) from test;


  COUNT(*)
----------
     14336

テーブルにインデックスを追加
SQL> create index idx_test on test(ename);
Index created

チェックポイントを切り替え、データファイルにデータを書き込む
SQL> alter system checkpoint;

System altered.

2.破壊前にrmanで表領域をバックアップし、修復可能なバックアップを得る
[oracle@cancer ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Oct 15 18:01:08 2015

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

connected to target database: ORCL (DBID=1420957945)

RMAN> backup tablespace "TEST" tag=tt;

Starting backup at 15-OCT-15
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=00006 name=/u01/oracle/oradata/orcl/test01.dbf
channel ORA_DISK_1: starting piece 1 at 15-OCT-15
channel ORA_DISK_1: finished piece 1 at 15-OCT-15
piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2015_10_15/o1_mf_nnndf_TT_c1yyht6m_.bkp tag=TT comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-OCT-15

3.shutdownの後、ultraeditを使用してデータファイルを変更--変更時にヘッダを開かないでください.oracleを起動すると、クエリー・テーブルにエラーが表示されます.
SQL> select count(*) from test;
select count(*) from test
                     *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 6, block # 19)
ORA-01110: data file 6: '/u01/oracle/oradata/orcl/test01.dbf'

4.dbv検出を使用
[oracle@cancer ~]$ dbv file=/u01/oracle/oradata/orcl/test01.dbf

DBVERIFY: Release 11.2.0.4.0 - Production on Thu Oct 15 18:12:45 2015

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

DBVERIFY - Verification starting : FILE = /u01/oracle/oradata/orcl/test01.dbf
Page 19 is marked corrupt
Corrupt block relative dba: 0x01800013 (file 6, block 19)   --            
Bad check value found during dbv:
Data in bad block:
 type: 6 format: 2 rdba: 0x01800013
 last change scn: 0x0000.000f0427 seq: 0x1 flg: 0x06
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x04270601
 check value in block header: 0x6c9f
 computed block checksum: 0x8700

Page 86 is marked corrupt
Corrupt block relative dba: 0x01800056 (file 6, block 86)    --            
Bad check value found during dbv:
Data in bad block:
 type: 6 format: 2 rdba: 0x01800056
 last change scn: 0x0000.000f044b seq: 0x1 flg: 0x06
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x044b0601
 check value in block header: 0x38f5
 computed block checksum: 0xe335

Page 92 is marked corrupt
Corrupt block relative dba: 0x0180005c (file 6, block 92)     --            
Bad check value found during dbv:
Data in bad block:
 type: 6 format: 2 rdba: 0x0180005c
 last change scn: 0x0000.000f044b seq: 0x1 flg: 0x06
 spare1: 0x0 spare2: 0x0 spare3: 0x0
 consistency value in tail: 0x044b0601
 check value in block header: 0x5b61
 computed block checksum: 0x3edf



DBVERIFY - Verification complete

Total Pages Examined         : 128
Total Pages Processed (Data) : 107
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 17
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 1
Total Pages Marked Corrupt   : 3      --       3   
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 984304 (0.984304)

ここには、不良ブロックの数と不良ブロックが存在するデータファイルid番号とblock id番号が表示されます.v$database_をクエリーすることもできます.block_牙列缺损
SQL> select * from v$database_block_corruption;
     FILE#     BLOCK#     BLOCKS CORRUPTION_CHANGE# CORRUPTION_TYPE
---------- ---------- ---------- ------------------ ---------------
         6         19          1                  0 CHECKSUM
         6         86          1                  0 CHECKSUM
         6         92          1                  0 CHECKSUM

5.rmanとexpを使用してファイルをエクスポートすると、エラーが表示されます.
5.1.expエクスポート
[oracle@cancer ~]$ exp test/test file=/server/backup/test.dmp

Export: Release 11.2.0.4.0 - Production on Thu Oct 15 18:33:45 2015

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


Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses ZHS16GBK character set (possible charset conversion)

About to export specified users ...
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user TEST
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user TEST
About to export TEST's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export TEST's tables via Conventional Path ...
. . exporting table                           TEST
EXP-00056: ORACLE error 1578 encountered
ORA-01578: ORACLE data block corrupted (file # 6, block # 19)
ORA-01110: data file 6: '/u01/oracle/oradata/orcl/test01.dbf'
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully with warnings.

解決方法:
ALTER SYSTEM SET EVENTS='10231 trace name context forever,level 10' ;

expエクスポート後
ALTER SYSTEM SET EVENTS='10231 trace name context off' ;

5.2 rmanエクスポート
RMAN> backup tablespace "TEST" tag=badblock;

Starting backup at 15-OCT-15
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=00006 name=/u01/oracle/oradata/orcl/test01.dbf
channel ORA_DISK_1: starting piece 1 at 15-OCT-15
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of backup command on ORA_DISK_1 channel at 10/15/2015 18:37:04
ORA-19566: exceeded limit of 0 corrupt blocks for file /u01/oracle/oradata/orcl/test01.dbf

解決方法:
不良ブロックの最大数を設定してバックアップ
RMAN> run
2> {set maxcorrupt for datafile 6 to 10;
3> backup tablespace "TEST" tag=badblock;}

executing command: SET MAX CORRUPT

Starting backup at 15-OCT-15
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=00006 name=/u01/oracle/oradata/orcl/test01.dbf
channel ORA_DISK_1: starting piece 1 at 15-OCT-15
channel ORA_DISK_1: finished piece 1 at 15-OCT-15
piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2015_10_15/o1_mf_nnndf_BADBLOCK_c1z0k7dh_.bkp tag=BADBLOCK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-OCT-15

損失レコード数の表示
SQL> select count(*) from test;

  COUNT(*)
----------
     13825
--        
SQL> select 14336-13825 from dual;

14336-13825
-----------
        511

6.rmanでバックアップしたファイルを使用して修復
[oracle@cancer ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Oct 15 18:57:19 2015

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

connected to target database: ORCL (DBID=1420957945)

RMAN> blockrecover from tag=tt datafile 6 block 19,86,92;

Starting recover at 15-OCT-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=52 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 /u01/oracle/fast_recovery_area/ORCL/backupset/2015_10_15/o1_mf_nnndf_TT_c1yyht6m_.bkp
channel ORA_DISK_1: piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2015_10_15/o1_mf_nnndf_TT_c1yyht6m_.bkp tag=TT
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:01

Finished recover at 15-OCT-15

照会時のレコード数
SQL> select count(*) from test;

  COUNT(*)
----------
     14336

7.dbvを使用してfile 6データファイルを再検証する
[oracle@cancer ~]$ dbv file=/u01/oracle/oradata/orcl/test01.dbf

DBVERIFY: Release 11.2.0.4.0 - Production on Thu Oct 15 19:03:03 2015

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

DBVERIFY - Verification starting : FILE = /u01/oracle/oradata/orcl/test01.dbf


DBVERIFY - Verification complete

Total Pages Examined         : 128
Total Pages Processed (Data) : 110
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 17
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 1
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 984304 (0.984304)

あるいはrmanを用いて検証する(以下の結果は別の実験結果である)
[oracle@cancer ~]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Oct 15 19:29:50 2015

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

connected to target database: ORCL (DBID=1420957945)

RMAN> BACKUP CHECK LOGICAL VALIDATE DATAFILE 6;

Starting backup at 15-OCT-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=44 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=/u01/oracle/oradata/orcl/test01.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
6    FAILED 0              1            128             984304
  File Name: /u01/oracle/oradata/orcl/test01.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       1              110
  Index      0              0
  Other      0              17

validate found one or more corrupt blocks
See trace file /u01/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_26126.trc for details
Finished backup at 15-OCT-15