13 oracle数据库坏块-逻辑坏块

逻辑数据坏块的场景
1)oracle bug也可能导致逻辑坏块的产生. 特别是parallel dml. 例如:
Bug 5621677 Logical corruption with PARALLEL update
Bug 6994194 Logical corruption from UPDATE DML
Bug 15980234 ORA-1400 / logical corruption from direct path INSERT ALL(fail with
ORA-1400, in direct path / PDML) 。
2)多数情况下逻辑坏块可能都是软件问题导致,当然数据库异常也可能导致。比如掉电的情况下,
就可能导致块内数据不一致
逻辑数据坏块检测工具
RMAN备份恢忽略soft corruption
soft corruption的块不计入maxcorrupt
media recovery会忽略soft corrupt
RMAN validate命令不会在alert中记录soft corrupt的信息,但是会在v$database_block_corruption中记录
DBV可以检测soft corruption
如果不设置event10231或者类似事件,那么soft corruption的块再次访问时报ORA-1578

逻辑数据坏块的检测

exp\expdp     该方式存在缺陷,是发现逻辑坏块后就会报错,不再继续检测.如果是索引逻辑坏块,那么exp是检测不到的
rman        同检测物理坏块一样,rman备份也具备检测逻辑坏块的功能,而且用的很多.
           通常我们在进行数据库不完全恢复时,很多时候可能需要使用隐含参数强制打开数据库,打开之后我们都建议
         使用rman进行检查,确认是否存在逻辑坏块等等,以免open后数据库出现异常
bbed        上面有介绍
sql查询       select select count(1) table_name ;
         select /*+index_ffs(xxx) */ count(1) from table_name;
analyze命令       analyze index idx_name validate structure;
         analyze table idx_name validate structure cascade online;
db_block_checking参数 在10g版本中,该参数默认是false,如果设置为true,那么可以进行逻辑坏块的检测,实际上设置以后, oracle在写入时就会进行check,避免产生逻辑坏块

逻辑坏块的分类
data block     通常我们是最大程度的将segment内的数据抢救出来,然后处理掉坏块.(如果是个别坏块,可以手工修复)
index block     对于index logical 坏块,一般来讲,我们通过rebuild就可以解决(有时或许不行,可以drop然后重建)
segment header/bitmap block ...etc   这种情况下比较复杂

模拟逻辑坏块
在很多情况下逻辑坏块都发生在索引上,所以这里我们以模拟索引逻辑坏块为例进行说明

YHQT@ orcl >create table yhqtest_6 as select owner,object_id,object_name from dba_objects where rownum<300;
Table created.
YHQT@ orcl >create index idx_yhqt6_id on yhqtest_6(object_id);
Index created.
YHQT@ orcl >select owner,object_id from dba_objects where object_name=upper('idx_yhqt6_id');
OWNER OBJECT_ID
------------------------------ ----------
YHQT 88407
YHQT@ orcl >alter session set events 'immediate trace name treedump level 88407';
Session altered.

--查看trace结果

[oracle@DSI ~]$ more /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_2354.trc
*** 2019-07-15 16:00:53.250
*** MODULE NAME:(SQL*Plus) 2019-07-15 16:00:53.250
*** ACTION NAME:() 2019-07-15 16:00:53.250 ----- begin tree dump
leaf: 0x28000db 41943259 (0: nrow: 299 rrow: 299)
----- end tree dump
YHQT@ orcl >select dbms_utility.data_block_address_file(TO_NUMBER('28000db','XXXXXXXX')) file_id,
dbms_utility.data_block_address_block(TO_NUMBER('28000db','XXXXXXXX')) block_id from dual; 2 FILE_ID BLOCK_ID
---------- ----------
10 219

--使用bbed查看并修改

BBED> set file 10 block 219
FILE# 10
BLOCK# 219
BBED> map /v
File: /u01/app/oracle/oradata/orcl/yhqt01.dbf (10)
Block: 219 Dba:0x028000db
------------------------------------------------------------ BBED> p kdxle
struct kdxle, 32 bytes @100
struct kdxlexco, 16 bytes @100
ub1 kdxcolev @100 0x00
ub1 kdxcolok @101 0x00
ub1 kdxcoopc @102 0x80
ub1 kdxconco @103 0x02
ub4 kdxcosdc @104 0x00000000
sb2 kdxconro @108 299
sb2 kdxcofbo @110 634
sb2 kdxcofeo @112 4246
sb2 kdxcoavs @114 3612
sb2 kdxlespl @116 0
sb2 kdxlende @118 0
ub4 kdxlenxt @120 0x00000000
ub4 kdxleprv @124 0x00000000
ub1 kdxledsz @128 0x00
ub1 kdxleflg @129 0x00 (NONE) BBED> dump /v offset 108 count 32
File: /u01/app/oracle/oradata/orcl/yhqt01.dbf (10)
Block: 219 Offsets: 108 to 139 Dba:0x028000db
-------------------------------------------------------
2b017a02 96101c0e 00000000 00000000 l +.z.............
YHQT@ orcl >select to_char(299,'xxxxxx') from dual; TO_CHAR
-------
12b
BBED> modify /x 2a offset 108
File: /u01/app/oracle/oradata/orcl/yhqt01.dbf (10)
Block: 219 Offsets: 108 to 139 Dba:0x028000db
------------------------------------------------------------------------
2a017a02 96101c0e 00000000 00000000 00000000 00000000 601f0000 541f481f <32 bytes per line> BBED> sum apply
Check value for File 10, Block 219:
current = 0xf239, required = 0xf239

 使用rman进行查看

RMAN> backup validate check logical database;
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
5 FAILED 0 81 64011 10373342
File Name: /home/oracle/backup/test01.tts
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 3 20628
Index 0 13088
Other 0 30203
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
10 FAILED 0 6190 6400 10411019
File Name: /u01/app/oracle/oradata/orcl/yhqt01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 2 53
Index 1 2
Other 1 155

用视图查询

YHQT@ orcl >select * from v$database_block_corruption;

     FILE#     BLOCK#	  BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
10 135 1 0 FRACTURED
10 160 1 0 ALL ZERO
5 2199 1 9533291 CORRUPT
5 2207 1 9579846 CORRUPT
5 2231 1 9620379 CORRUPT
10 151 1 10410172 CORRUPT
10 219 1 10411020 CORRUPT
CORRUPTION_CHANGE#值= 10410172,我们可以发现,corruption_change#值是大于0,那么表示是逻辑坏块

--查询坏块所在的对象

set autot off
set lines 150
col segment_name for a15
col owner for a20
SELECT tablespace_name, segment_type, owner, segment_name
FROM dba_extents
WHERE file_id = 10
and 219 between block_id AND block_id + blocks - 1;
YHQT@ orcl >SELECT tablespace_name, segment_type, owner, segment_name
FROM dba_extents
WHERE file_id = 10
and 219 between block_id AND block_id + blocks - 1; 2 3 4 TABLESPACE_NAME SEGMENT_TYPE OWNER SEGMENT_NAME
------------------------------ ------------------ -------------------- ---------------
YHQT INDEX YHQT IDX_YHQT6_ID

使用dbms_repair检测

创建repair table
YHQT@ orcl >conn / as sysdba
YHQT@ orcl >BEGIN
DBMS_REPAIR.ADMIN_TABLES (
TABLE_NAME => 'REPAIR_TABLE',
TABLE_TYPE => dbms_repair.repair_table,
ACTION => dbms_repair.create_action,
TABLESPACE => 'YHQT');
END;
/
检查对象上是否存在坏块
YHQT@ orcl >set serveroutput on
DECLARE num_corrupt INT;
BEGIN
num_corrupt := 0;
DBMS_REPAIR.CHECK_OBJECT (
SCHEMA_NAME => 'YHQT',
OBJECT_NAME => 'YHQTEST_6',
REPAIR_TABLE_NAME => 'REPAIR_TABLE',
corrupt_count => num_corrupt);
DBMS_OUTPUT.PUT_LINE('number corrupt: ' || TO_CHAR (num_corrupt));
END;
/
通过check后,就可以查询repair table了
SYS@ orcl >col CORRUPT_DESCRIPTION for a100
SYS@ orcl >select OBJECT_ID,RELATIVE_FILE_ID,BLOCK_ID,CORRUPT_TYPE,OBJECT_NAME,CORRUPT_DESCRIPTION FROM repair_table;

---修复逻辑块错误--index

SYS@ orcl >conn yhqt/***
Connected.
YHQT@ orcl >alter index IDX_YHQT6_ID rebuild;
Index altered.
YHQT@ orcl >select * from v$database_block_corruption;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
10 135 1 0 FRACTURED
10 160 1 0 ALL ZERO
5 2199 1 9533291 CORRUPT
5 2207 1 9579846 CORRUPT
5 2231 1 9620379 CORRUPT
10 151 1 10410172 CORRUPT
10 219 1 10411020 CORRUPT
7 rows selected. YHQT@ orcl >analyze table yhqtest_6 validate structure cascade online;
analyze table yhqtest_6 validate structure cascade online
*
ERROR at line 1:
ORA-01499: table/index cross reference failure - see trace file
YHQT@ orcl >drop index IDX_YHQT6_ID;
Index dropped.
YHQT@ orcl >create index idx_yhqt6_id on yhqtest_6(object_id);
Index created.
YHQT@ orcl >analyze table yhqtest_6 validate structure cascade online;
Table analyzed.

使用expdp备份

[oracle@DSI ~]$ expdp system/**** DIRECTORY=dump_file_dir_test compression=all schemas=YHQT dumpfile=schemas_YHQT_%U.DMP parallel=2 logfile=schemas_YHQT_20190715.log

修复上一篇物理坏块测试中的

2.The block is Fractured/Incomplete - header and footer of the block do not match

分析alert日志

Mon Jul 15 11:12:19 2019
Hex dump of (file 10, block 143) in trace file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_2354.trc
Corrupt block relative dba: 0x0280008f (file 10, block 143)
Fractured block found during multiblock buffer read
Data in bad block:
type: 6 format: 2 rdba: 0x0280008f
last change scn: 0x0000.009e53f5 seq: 0x1 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x54f50601 ===>>>tail=2 lower bytes of SCN Base+type+seq=53f5+06+01 而改变之后的值是54f50601
check value in block header: 0x46ca
computed block checksum: 0x0
Reading datafile '/u01/app/oracle/oradata/orcl/yhqt01.dbf' for corruption at rdba: 0x0280008f (file 10, block 143)
Reread (file 10, block 143) found same corrupt data (no logical check)
Mon Jul 15 11:12:19 2019
Corrupt Block Found
TSN = 10, TSNAME = YHQT
RFN = 10, BLK = 143, RDBA = 41943183
OBJN = 88385, OBJD = 88385, OBJECT = YHQTEST_2, SUBOBJECT =
SEGMENT OWNER = YHQT, SEGMENT TYPE = Table Segment
Corrupt Block Found
TSN = 10, TSNAME = YHQT
RFN = 10, BLK = 143, RDBA = 41943183
OBJN = 88385, OBJD = 88385, OBJECT = YHQTEST_2, SUBOBJECT =
SEGMENT OWNER = YHQT, SEGMENT TYPE = Table Segment
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_2354.trc (incident=67366):
ORA-01578: ORACLE data block corrupted (file # 10, block # 143)
ORA-01110: data file 10: '/u01/app/oracle/oradata/orcl/yhqt01.dbf'
Incident details in: /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_67366/orcl_ora_2354_i67366.trc
Mon Jul 15 11:12:21 2019
Sweep [inc][]: completed
Errors in file /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_2354.trc (incident=67367):
ORA-01578: ORACLE data block corrupted (file # 10, block # 143)
ORA-01110: data file 10: '/u01/app/oracle/oradata/orcl/yhqt01.dbf'
Incident details in: /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_67367/orcl_ora_2354_i67367.trc
Hex dump of (file 10, block 135) in trace file /u01/app/oracle/diag/rdbms/orcl/orcl/incident/incdir_67366/orcl_m000_2539_i67366_a.trc

用bbed修改

BBED> p tailchk
ub4 tailchk @8188 0x54f50601
BBED> modify /x 0106f553 offset 8188
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /u01/app/oracle/oradata/orcl/yhqt01.dbf (10)
Block: 143 Offsets: 8188 to 8191 Dba:0x0280008f
------------------------------------------------------------------------
0106f553
<32 bytes per line>
BBED> sum apply
Check value for File 10, Block 143:
current = 0x41ca, required = 0x41ca
YHQT@ orcl >alter system flush buffer_cache;
YHQT@ orcl >set linesize 999
YHQT@ orcl >select * from yhqtest_2; ID NAME
---------- ---------===查询正常,数据也还在
1 yhq

13 oracle数据库坏块-逻辑坏块(模拟/修复)的更多相关文章

  1. oracle 数据库(表)的逻辑备份与恢复

    一.介绍逻辑备份是指使用工具export将数据对象的结构和数据导出到文件的过程.逻辑恢复是指当数据库对象被误操作而损坏后使用工具import利用备份的文件把数据对象导入到数据库的过程.物理备份即可在数 ...

  2. 十二、oracle 数据库(表)的逻辑备份与恢复

    一.介绍逻辑备份是指使用工具export将数据对象的结构和数据导出到文件的过程.逻辑恢复是指当数据库对象被误操作而损坏后使用工具import利用备份的文件把数据对象导入到数据库的过程.物理备份即可在数 ...

  3. 关于oracle数据库

    Oracle数据库是做什么的? oracle数据库和其他数据库一样,都是保存数据的,同时可以去查询,修改,删除等oracle和其他数据不一样的地方在于,它又复杂的机制可以保证在数据库服务器突然坏了的情 ...

  4. Oracle数据库体系结构(7) 表空间管理1

    表空间是Oracle数据库最大的逻辑存储结构,有一系列段构成.Oracle数据库对象存储结构的管理主要是通过表空间的管理实现的. 1.表空间的分类 表空间根据存储类型不同分为系统表空间和非系统表空间 ...

  5. Oracle数据库结构

    之前写了一篇文章<Oracle-知识结构漫谈> 粗略的介绍了Oracle数据库接口,在这里再更加详细的描述一下,当做是对原有知识的巩固,温故知新. Oracle体系结构数据库的体系结构是从 ...

  6. Oracle数据库系统结构(一) 

    1.Oracle数据库系统结构概述 Oracle数据库由存放在磁盘上的数据库(DB)和对磁盘上的数据库进行管理的数据库管理系统(DBMS)两部分构成,分别对应着数据库的存储结构和软件结构. Oracl ...

  7. oracle数据库相关知识点

    已知表如下:

  8. Oracle数据库管理员面试题

    Oracle数据库管理员面试题 1.模拟使用oracle的flashback找回过去某个时间点的数据,实现误操作的恢复. http://www.txw100.com/soft/2013/08/547. ...

  9. 对Oracle数据库坏块的理解

    1.物理坏块和逻辑坏块 在数据库中有一个概念叫做数据块的一致性,Oracle的数据块的一致性包括了两个层次:物理一致性和逻辑一致性,如果一个数据块在这两个层次上存在不一致性,那就对应到了我们今天要要说 ...

随机推荐

  1. linux centos中安装flash player

    本机为centos 7.0 64 1.用火狐浏览器随便打开一个视频网站,找到一个视频点进去,网站会提示未安装flash player.点击进去到adobe官网.2.下载flash player插件,可 ...

  2. 接口开发中 遇到的坑——Java byte与C# byte 数据转换问题

    前提: 公司与其他公司进行接口对接 需要使用Byte[]数据流传输数据 原本想法如下:直接IO生成就ok了 using System; using System.IO; using System.Te ...

  3. yum 报错2

    Cannot retrieve metalink for repository: epel/x86_64. Please verify its path and try again 打开/etc/yu ...

  4. 001-cut 的用法

    [root@zabbix ~]# , /etc/passwd root: bin: daemon: adm: shutdown: halt: mail: operator: games: nobody ...

  5. Eureka实现高可用及为Eureka设置登录账号和密码

    本文通过两个eureka相互注册实现注册中心的高可用,同时为注册中心配置认证登录. 需要用到的maven配置 <dependency> <groupId>org.springf ...

  6. CentOS 7安装MySQL 8——萌新超详细教程

          1.配置MySQL 8.0的安装源:   sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-1.n ...

  7. 【练习】(a,b)和(b,a)是相同的,如何去除(b,a)保留(a,b)

    [(0, 3), (0, 11), (1, 8), (1, 9), (1, 15), (3, 0), (8, 1), (8, 9), (8, 15), (9, 1), (9, 8), (9, 15), ...

  8. thinkphp之cookie操作

    cookie设置 命名空间 代码

  9. JavaScript精进篇

    JavaScript是所有前端框架中最基础的框架,在工作了两年以后又重新回到了这里.过去两年里用的最多的前端框架是jquery,因为它简单易上手,而jquery就是封装了JavaScript.重新系统 ...

  10. day_14 匿名函数与内置函数连用 作业题

    ''' 要求: 从文件中取出每一条记录放入列表中,列表的每个元素都是` {'name':'egon','sex':'male','age':18,'salary':3000}`的形式 ''' all_ ...