您的位置:首页 > 其它

lob表中出现坏块的处理方法

2016-03-03 13:37 309 查看
lob表中出现坏块的处理方法
1)创建lob 表

SQL> create table lobdemo(a number,b clob)
2 lob(b) store as (
3 tablespace test_lob
4 chunk 8k
5 disable storage in row
6 );
然后插入数据,至tablespace test_lob满。
dd of 创建坏块
[oracle@test1 ~]$ dd of=/oradata/testlob.dbf bs=8192 conv=notrunc seek=222<<EOF
[oracle@test1 bin]$ ./dbv file=/oradata/testlob.dbf blocksize=8192

DBVERIFY: Release 11.2.0.4.0 - Production on Thu Mar 3 02:24:17 2016

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

DBVERIFY - Verification starting : FILE = /oradata/testlob.dbf
Page 222 is marked corrupt
Corrupt block relative dba: 0x014000de (file 5, block 222)
Bad header found during dbv:
Data in bad block:
type: 67 format: 7 rdba: 0x69747075
last change scn: 0x6c62.206e6e6f seq: 0x6f flg: 0x63
spare1: 0x72 spare2: 0x72 spare3: 0xa
consistency value in tail: 0x65f52802
check value in block header: 0x216b
block checksum disabled

ERROR:
ORA-01578: ORACLE data block corrupted (file # 5, block # 222)
ORA-01110: data file 5: '/oradata/testlob.dbf'
至目前已经知道(file # 5, block # 222)

可以测试导出该表也会报错
2)查询坏块所在的表等信息
SQL> select tablespace_name,segment_type,owner,segment_name from dba_extents where file_id =5 and 222 between block_id and block_id + blocks -1;

TABLESPACE_NAME SEGMENT_TYPE OWNER
------------------------------ ------------------ ------------------------------
SEGMENT_NAME
--------------------------------------------------------------------------------
TEST_LOB LOBSEGMENT SYS
SYS_LOB0000088050C00002$$

查到坏块的列信息
SQL> select owner,table_name ,column_name from dba_lobs where segment_name in ('SYS_LOB0000088050C00002$$') and owner='SYS';

OWNER TABLE_NAME
------------------------------ ------------------------------
COLUMN_NAME
--------------------------------------------------------------------------------
SYS LOBDEMO
B
查出rowid

SQL> set concat off
SQL> set serveroutput on
SQL>
SQL> declare
2 n number;
3 error_code number;
4 bad_rows number := 0;
5 ora1578 EXCEPTION;
6 ora600 EXCEPTION;
7 PRAGMA EXCEPTION_INIT(ora1578, -1578);
8 PRAGMA EXCEPTION_INIT(ora600, -600);
9
10 begin
11 for cursor_lob in (select rowid rid, &&lob_column from &&table_owner.&table_with_lob) loop
12 begin
13 n:=dbms_lob.instr(cursor_lob.&&lob_column,hextoraw('889911')) ;
14 exception
15 when ora1578 then
16 bad_rows := bad_rows + 1;
17 insert into bad_rows values(cursor_lob.rid,1578);
18 commit;
19 when ora600 then
20 bad_rows := bad_rows + 1;
21 insert into bad_rows values(cursor_lob.rid,600);
22 commit;
23 when others then
24 error_code:=SQLCODE;
25 bad_rows := bad_rows + 1;
26 insert into bad_rows values(cursor_lob.rid,error_code);
27 commit;
28 end;
29 end loop;
30 dbms_output.put_line('Total Rows identified with errors in LOB column: '||bad_rows);
31 end;
32 /
Enter value for lob_column: B
Enter value for table_owner: SYS
Enter value for table_with_lob: LOBDEMO
old 11: for cursor_lob in (select rowid rid, &&lob_column from &&table_owner.&table_with_lob) loop
new 11: for cursor_lob in (select rowid rid, B from SYS.LOBDEMO) loop
old 13: n:=dbms_lob.instr(cursor_lob.&&lob_column,hextoraw('889911')) ;
new 13: n:=dbms_lob.instr(cursor_lob.B,hextoraw('889911')) ;
Total Rows identified with errors in LOB column: 1

PL/SQL procedure successfully completed.

[align=left]create table bad_rows (row_id ROWID[/align]
[align=left] ,oracle_error_code number);[/align]

[align=left]declare[/align]
[align=left] n number;[/align]
[align=left] error_code number;[/align]
[align=left] bad_rows number := 0;[/align]
[align=left] ora1578 EXCEPTION;[/align]
[align=left] ora600 EXCEPTION;[/align]
[align=left] PRAGMA EXCEPTION_INIT(ora1578, -1578);[/align]
[align=left] PRAGMA EXCEPTION_INIT(ora600, -600);[/align]

[align=left]begin[/align]
[align=left] for cursor_lob in (select rowid rid, &&lob_column from &&table_owner.&table_with_lob) loop[/align]
[align=left] begin[/align]
[align=left] n:=dbms_lob.instr(cursor_lob.&&lob_column,hextoraw('889911')) ;[/align]
[align=left] exception[/align]
[align=left] when ora1578 then[/align]
[align=left] bad_rows := bad_rows + 1;[/align]
[align=left] insert into bad_rows values(cursor_lob.rid,1578);[/align]
[align=left] commit;[/align]
[align=left] when ora600 then[/align]
[align=left] bad_rows := bad_rows + 1;[/align]
[align=left] insert into bad_rows values(cursor_lob.rid,600);[/align]
[align=left] commit;[/align]
[align=left] when others then[/align]
[align=left] error_code:=SQLCODE;[/align]
[align=left] bad_rows := bad_rows + 1;[/align]
[align=left] insert into bad_rows values(cursor_lob.rid,error_code);[/align]
[align=left] commit; [/align]
[align=left] end;[/align]
[align=left] end loop;[/align]
[align=left] dbms_output.put_line('Total Rows identified with errors in LOB column: '||bad_rows);[/align]
[align=left]end;[/align]
[align=left]/[/align]
----------------------------可能要退出sqlplus


ORA-1578 ORA-26040 in a LOB segment - Script to solve the errors (文档 ID 293515.1)
SQL> SELECT * FROM bad_rows
2 ;

ROW_ID ORACLE_ERROR_CODE
------------------ -----------------
AAAVfyAABAAAXlJABG 1578

SQL> truncate table bad_rows
2 ;

Table truncated.
SQL> update lobdemo set B=empty_clob() where rowid in('AAAVfyAABAAAXlJABG');

1 row updated.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: