Oracle数据块损坏篇之10231内部事件
实验:某个分区数据块损坏,不完全恢复此分区表数据
背景:数据库没有有效备份,某个分区中有数据块损坏。
要求:最大限度恢复此分区数据。
环境:RHEL 6.4 + Oracle 11.2.0.4
1. 初始化实验环境
初始化创建模拟实验环境用到的表空间、业务用户、表,并导入测试数据。
本次实验用到表空间DBS_D_JINGYU, 业务用户JINGYU, 分区表T_PART(含两个分区的测试数据)。
-- 数据表空间
create tablespace dbs_d_jingyu datafile '/u02/oradata/jingyu/dbs_d_jingyu01.dbf' size 30M autoextend off;
-- 临时表空间
create temporary tablespace temp_jingyu tempfile '/u02/oradata/jingyu/temp_jingyu01.tmp' size 30M autoextend off;
-- 索引表空间(可选)
create tablespace dbs_i_jingyu datafile '/u02/oradata/jingyu/dbs_i_jingyu01.dbf' size 30M autoextend off;
-- 假设创建用户 jingyu 密码 jingyu,默认临时表空间 temp_jingyu, 默认数据表空间 dbs_d_jingyu。
CREATE USER jingyu IDENTIFIED BY jingyu
TEMPORARY TABLESPACE temp_jingyu
DEFAULT TABLESPACE dbs_d_jingyu
QUOTA UNLIMITED ON dbs_d_jingyu;
-- 赋予普通业务用户权限
grant resource, connect to jingyu;
-- 赋予DBA用户权限
grant dba to jingyu;
-- 业务用户登录
conn jingyu/jingyu
-- 1.1 创建分区表
create table t_part(
id number,
name varchar2(20),
start_time date,
content varchar2(200)
)partition by range(start_time)
(
partition P20150101 values less than (TO_DATE(' 2015-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace dbs_d_jingyu,
partition P20150102 values less than (TO_DATE(' 2015-01-02 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace dbs_d_jingyu,
partition P20150103 values less than (TO_DATE(' 2015-01-03 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
tablespace dbs_d_jingyu
);
-- 1.2 插入测试数据
--分区P20150102插入10000行数据
begin
for i in 1..10000 loop
insert into t_part values (i,'alfred'||i, to_date('2015-01-01','yyyy-mm-dd'), 'AAAAAAAAAA');
end loop;
commit;
end;
/
--分区P20150103插入20000行数据
begin
for i in 10001..30000 loop
insert into t_part values (i,'alfred'||i, to_date('2015-01-02','yyyy-mm-dd'), 'AAAAAAAAAA');
end loop;
commit;
end;
/
-- 1.3查询表数据量和大小
select count(1) from t_part;
--result: 30000
select count(1) from t_part partition(P20150102);
--result: 10000
select count(1) from t_part partition(P20150103);
--result: 20000
--普通表/分区表的每个分区大约__G大小
set linesize 160
col segment_name for a30
select (t.bytes/1024/1024) "MB", t.owner, t.segment_name, t.partition_name, t.tablespace_name from dba_segments t where segment_name = 'T_PART';
MB OWNER SEGMENT_NAME PARTITION_NAME TABLESPACE_NAME
---------- ------------------------------ ------------------------------ ------------------------------ ------------------------------
8 JINGYU T_PART P20150102 DBS_D_JINGYU
8 JINGYU T_PART P20150103 DBS_D_JINGYU
2. 模拟分区中有数据块损坏情景
我这里使用BBED制造坏块,修改t_part分区表的分区P20150103中的某个块内容,模拟真实环境中有数据块损坏的情景。
--查询分区P20150103的HEADER_BLOCK
select header_file,header_block from dba_segments where segment_name='T_PART' and partition_name='P20150103' and owner='JINGYU';
SQL> select header_file,header_block from dba_segments where segment_name='T_PART' and partition_name='P20150103' and owner='JINGYU';
HEADER_FILE HEADER_BLOCK
----------- ------------
5 1169
--查询某一行记录所在的块
select
rowid,
dbms_rowid.rowid_relative_fno(rowid)rel_fno,
dbms_rowid.rowid_block_number(rowid)blockno,
dbms_rowid.rowid_row_number(rowid) rowno
from t_part where id = 20000;
SQL> select
2 rowid,
3 dbms_rowid.rowid_relative_fno(rowid)rel_fno,
4 dbms_rowid.rowid_block_number(rowid)blockno,
5 dbms_rowid.rowid_row_number(rowid) rowno
6 from t_part where id = 20000;
ROWID REL_FNO BLOCKNO ROWNO
------------------ ---------- ---------- ----------
AAAVveAAFAAAATBABX 5 1217 87
使用bbed工具破坏5号文件1217块内容,
BBED工具:http://www.cnblogs.com/jyzhao/p/5139584.html
[oracle@JY-DB01 ~]$ bbed parfile=/tmp/bbed.par
Password:
BBED: Release 2.0.0.0.0 - Limited Production on Tue Jan 19 11:37:59 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> set dba 5,1217
DBA 0x014004c1 (20972737 5,1217)
BBED> map
File: /u02/oradata/jingyu/dbs_d_jingyu01.dbf (5)
Block: 1217 Dba:0x014004c1
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
struct ktbbh, 72 bytes @20
struct kdbh, 14 bytes @100
struct kdbt[1], 4 bytes @114
sb2 kdbr[177] @118
ub1 freespace[815] @472
ub1 rowdata[6901] @1287
ub4 tailchk @8188
BBED> d /v offset 0 count 128
File: /u02/oradata/jingyu/dbs_d_jingyu01.dbf (5)
Block: 1217 Offsets: 0 to 127 Dba:0x014004c1
-------------------------------------------------------
06a20000 c1044001 52733100 00000106 l ......@.Rs1.....
a18b0000 01000c00 de5b0100 4d733100 l .........[..Ms1.
0000e81f 021f3200 81044001 02001b00 l ......2...@.....
5d0b0000 fc0fc000 df030600 b1200000 l ]............ ..
52733100 00000000 00000000 00000000 l Rs1.............
00000000 00000000 00000000 00000000 l ................
00000000 0001b100 ffff7401 a3042f03 l ..........t.../.
2f030000 b100711f 4a1f231f fc1ed51e l /.....q.J.#.....
<16 bytes per line>
BBED> modify /x 19901010 offset 0
File: /u02/oradata/jingyu/dbs_d_jingyu01.dbf (5)
Block: 1217 Offsets: 0 to 127 Dba:0x014004c1
------------------------------------------------------------------------
19901010 c1044001 52733100 00000106 a18b0000 01000c00 de5b0100 4d733100
0000e81f 021f3200 81044001 02001b00 5d0b0000 fc0fc000 df030600 b1200000
52733100 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 0001b100 ffff7401 a3042f03 2f030000 b100711f 4a1f231f fc1ed51e
<32 bytes per line>
BBED> sum apply
Check value for File 5, Block 1217:
current = 0xa9ae, required = 0xa9ae
BBED>
至此破坏了5号文件,1217块。
查询v$database_block_corruption
select * from v$database_block_corruption;
SQL> select * from v$database_block_corruption;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
5 1217 1 0 CORRUPT
--此时查询分区表T_PART
alter system flush buffer_cache;
select count(1) from t_part;
--查询报错ORA-01578
select count(1) from t_part partition(P20150102);
--查询正常,即分区P20150102未受影响
select count(1) from t_part partition(P20150103);
--查询报错ORA-01578
--尝试逻辑导出表数据失败
[oracle@JY-DB01 ~]$ exp jingyu/jingyu tables=t_part file=t_part.dmp log=exp_t_part.log
Export: Release 11.2.0.4.0 - Production on Tue Jan 19 11:52:21 2016
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, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table T_PART
. . exporting partition P20150101 0 rows exported
. . exporting partition P20150102 10000 rows exported
. . exporting partition P20150103
EXP-00056: ORACLE error 1578 encountered
ORA-01578: ORACLE data block corrupted (file # 5, block # 1217)
ORA-01110: data file 5: '/u02/oradata/jingyu/dbs_d_jingyu01.dbf'
Export terminated successfully with warnings.
[oracle@JY-DB01 ~]$
3. 尝试使用Oracle内部事件10231进行不完全恢复
使用Oracle 10231内部事件可以跳过坏块
--启用10231内部事件
alter system set events='10231 trace name context forever,level 10';
--关闭10231内部事件
alter system set events='10231 trace name context off';
测试设置10231事件后是否可以逻辑导出:
[oracle@JY-DB01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue Jan 19 14:01:43 2016
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, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
SQL> alter system set events='10231 trace name context forever,level 10';
System altered.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
[oracle@JY-DB01 ~]$ exp jingyu/jingyu tables=t_part file=t_part.dmp log=exp_t_part.log
Export: Release 11.2.0.4.0 - Production on Tue Jan 19 14:01:57 2016
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, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table T_PART
. . exporting partition P20150101 0 rows exported
. . exporting partition P20150102 10000 rows exported
. . exporting partition P20150103 19823 rows exported
Export terminated successfully without warnings.
--成功导出后记得要关闭10231内部事件
alter system set events='10231 trace name context off';
20000 - 19823 = 177行,也就是说该数据块损坏直接导致了177行数据丢失。不过还好,保住了大部分数据。
实际上设置10231内部事件后,如果上面逻辑导出没问题,这种情况自然还可以把数据直接导出到临时表,更加方便。
SQL> select count(1) from t_part;
select count(1) from t_part
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 1217)
ORA-01110: data file 5: '/u02/oradata/jingyu/dbs_d_jingyu01.dbf'
SQL> alter system set events='10231 trace name context forever,level 10';
System altered.
SQL> select count(1) from t_part;
COUNT(1)
----------
29823
SQL> create table temp_t_part_20150103 as select * from t_part partition(P20150103);
Table created.
SQL> alter system set events='10231 trace name context off';
System altered.
SQL> select count(1) from t_part partition(P20150103);
select count(1) from t_part partition(P20150103)
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 1217)
ORA-01110: data file 5: '/u02/oradata/jingyu/dbs_d_jingyu01.dbf'
SQL> select count(1) from temp_t_part_20150103;
COUNT(1)
----------
19823
Reference
- http://blog.csdn.net/tianlesoftware/article/details/5024966
- http://blog.csdn.net/seertan/article/details/8507045
- http://blog.csdn.net/coolyl/article/details/195919
Oracle数据块损坏篇之10231内部事件的更多相关文章
- Oracle数据块损坏的恢复实例
测试环境:11.2.0.4 1.构建数据块损坏的测试环境 2.有备份:常规恢复坏块 3.无备份:跳过坏块 1.构建数据块损坏的测试环境 1.1 创建测试表 --Create Table t_test ...
- java.sql.SQLException: ORA-01578: ORACLE 数据块损坏问题解决办法
错误信息: java.sql.SQLException: ORA-01578: ORACLE 数据块损坏 (文件号 17, 块号 315703) ORA-01110: 数据文件 17: 'D:\ORA ...
- Oracle 数据块损坏与恢复具体解释
1.什么是块损坏: 所谓损坏的数据块,是指块没有採用可识别的 Oracle 格式,或者其内容在内部不一致. 通常情况下,损坏是由硬件故障或操作系统问题引起的.Oracle 数据库将损坏的块标识为&qu ...
- ORA-01578: ORACLE 数据块损坏 (文件号 13, 块号 2415081) ORA-01110: 数据文件XXXXXX
1.使用DBV检查数据文件,在cmd执行:dbv file='E:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01.DBF' blocksize=8192:然后等待检测结 ...
- ORA-01578: ORACLE 数据块损坏 (文件号 10, 块号 57896)ORA-01110: 数据文件 10: '/data/oradata/prod35.dbf'
https://community.oracle.com/thread/3540795 概述 ------------- 数据库坏块(corruption) 的类型可以按照坏块所属对象的不同,分为用户 ...
- [转]Oracle数据块体系的详细介绍
数据块概述Oracle对数据库数据文件(datafile)中的存储空间进行管理的单位是数据块(data block).数据块是数据库中最小的(逻辑)数据单位.与数据块对应的,所有数据在操作系统级的最小 ...
- oracle数据块核心剖析
详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp57 数据块(Oracle Data Blocks),本文简称为" ...
- 数据块损坏(block corruption)
分为物理损坏和逻辑损坏-物理损坏一般指数据块头部不可以访问.数据块校验值不合法,数据块格式不再是oracle承认的格式-逻辑损坏一般是在物理性结构完整的情况下,数据的内容在含义上不正确,比如保存了不允 ...
- Oracle数据块深入分析总结
http: 最近在研究块的内部结构,把文档简单整理了一下,和大家分享一下.该篇文章借助dump和BBED对数据 库内部结构进行了分析,最后附加了一个用BBED解决ORA-1200错误的小例子.在总结的 ...
随机推荐
- 选择列表中除了第一个li的其他元素
//选择div中除了第一个li的其他所以li元素 div li:not(:first-child){ }
- Allegro之无法保存(提示和用户有关或者和lock有关)
使用中无意出现此情况 无奈重新打开文件时发现brd文件下面有个.brd.lck文件,顺手删掉,回复正常~ 此为bug解bug,具体方法下次遇到再仔细研究是为什么~ 养成隔几分钟手动保存的好习惯,防止b ...
- Java环境设置
win7/win8下JDK环境变量设置方法 首先需要到官网上下载JDK这款软件,本人下载的是jdk-7u40-windows-i586版本,安装完成显示jdk1.7.0_67. 其次选择安装路径.本人 ...
- Intellij IDEA 常用快捷键
[常规] Ctrl+Shift + Enter,语句完成 "!",否定完成,输入表达式时按 "!"键 Ctrl+E,最近的文件 Ctrl+Shift+E,最近更 ...
- @Transient注解----Hiberbate
@Transient表示该属性并非一个到数据库表的字段的映射,将会忽略该属性.如果一个属性并非数据库表的字段映射,就务必将其标示为@Transient,否则,ORM框架默认其注解为@Basic Exa ...
- JSP实现在项目在网页上查询
<table> <caption>user</caption> <tr> <td>编号</td> <td>姓名< ...
- BSBuDeJie_04
一 段子的下拉 建立模型 数字类型的用assign /* 当前页码 */ @property (nonatomic, assign) NSInteger page; 二 下拉上拉细节处理 三 细节处理 ...
- Silverlight 使用DataContractJsonSerializer序列化与反序列化 Json
环境说明:Silverlight 5.1,.Net Framework 4.0 1.添加引用System.ServiceModel.Web.dll. 因为 System.Runtime.Seria ...
- FizzBuzzWhizz游戏的高效解法
最近比较火的一道题(传送门),看见园友们的谈论(传送门1 传送门2),都是从1到100的扫描,我想说说的另一种想法. 可以把这道题转换成给100个人发纸牌的游戏,每人所报的就是纸牌上写的东西. 纸牌发 ...
- C语言中的插入排序(2016-12-30)
直接插入排序: 算法思想:假设待排序的记录存放在数组R[1--n]中,初始时,i=1,R[1]自成一个有序区,无序区为R[2--n].然后从i=2起直到i=n,依次将R[i]插入当前的有序区R[1.. ...