Oracle壞塊修復處理實驗

梓沐發表於2016-02-15

壞塊分為物理壞塊和邏輯壞塊,前者是硬體問題產生,後者是oracle內部資料有問題。

給資料庫開啟歸檔模式

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

SQL> startup mount

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_corruption檢視

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.此時使用rmanexp匯出檔案時會提示錯誤

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再次驗證file6資料檔案

[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


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29812844/viewspace-1988808/,如需轉載,請註明出處,否則將追究法律責任。

相關文章