码迷,mamicode.com
首页 > 数据库 > 详细

oracle 数据块介绍 1

时间:2016-03-09 19:23:08      阅读:358      评论:0      收藏:0      [点我收藏+]

标签:数据库管理   oracle   system   操作系统   file   

ORACLE DATA BLOCK

 oracle data block是数据库管理数据文件的最小单元。

 在物理层面,oracle data file保存在操作系统上,最小i/o单元是操作系统块,oracle data block是oracle db逻辑最小i/o单元,其结构和系统块不同,大小是系统块的整数倍,如图:

技术分享技术分享

DATA BLOCK SIZE

 oracle db都会配置db_block_size参数,在建库时确定oracle db的默认data block size的大小。建库后数据库默认数据块大小无法更改,除非重建数据库。

 如果在建库时不指定db_block_size参数,则system会制定默认的data block size,4k or 8k。oracle db data block size指整数倍system block size。

  

DATA block format

  无论是存放table、 index、cluster table的data block,其数据块的给事都是相近的,如图:

技术分享


Data block overhead

 oracle db通过管理data block overhaed来管理数据块。数据块头不用来存放数据,其存放的内容如下:

   1.block header 数据块头保存数据块的基本信息及磁盘上的位置和块的类型。同时被用于事务的管理,其头部还记录活动及历史事务的信息。

   A transaction entry is required for every transaction that updates the block. Oracle Database initially reserves space in the block header for transaction entries. In data blocks allocated to segments that support transactional changes, free space can also hold transaction entries when the header space is depleted. The space required for transaction entries is operating system dependent. However, transaction entries in most operating systems require approximately 23 bytes.

   2.table directory

    For a heap-organized table, this directory contains metadata about tables whose rows are stored in this block. Multiple tables can store rows in the same block.

   3.row directory

    For a heap-organized table, this directory describes the location of rows in the data portion of the block.

After space has been allocated in the row directory, the database does not reclaim this space after row deletion. Thus, a block that is currently empty but formerly had up to 50 rows continues to have 100 bytes allocated for the row directory. The database reuses this space only when new rows are inserted in the block.



oracle数据块保存可变长数据,一个数据条目包括一个或多个条目片,每一个数据片包括row header 和 row column data 两部分。

技术分享

Row header

Oracle Database uses the row header to manage the row piece stored in the block. The row header contains information such as the following:

  • Columns in the row piece

  • Pieces of the row located in other data blocks

    If an entire row can be inserted into a single data block, then Oracle Database stores the row as one row piece. However, if all of the row data cannot be inserted into a single block or an update causes an existing row to outgrow its block, then the database stores the row in multiple row pieces. A data block usually contains only one row piece per row.

  • Cluster keys for table clusters

A row fully contained in one block has at least 3 bytes of row header.

Column Data

After the row header, the column data section stores the actual data in the row. The row piece usually stores columns in the order listed in the CREATE TABLE statement, but this order is not guaranteed. For example, columns of type LONG are created last.

Rowid format

Oracle database uses a rowid to uniquely identified a row. Internally, the rowid is a structure that hold the information that the database needs to acceces a row. A rowid is not a physically sotred in database, but is inferred from the file and block on which the data is stored.

KEVIN@SQL>SELECT rowid FROM test1 WHERE rownum < 2;

ROWID

------------------

AAAWEyAAEAAAAlPAAA

A rowid includes a data object number. This rowid type uses a base 64 encoding of the physical address for each row. This encoding character are A-Z,a-z,0-9,+ and /.

AAAWEy     data object number    The data object number identifies a segment number.

AAE        relate file number    The tablespace relative file, which stores the row

AAAAlP     the data bolck number The data block number, stores the row          

AAA        row number            The block nunmber identifies the row in block.

oracle database 数据块的格式在一些特定因素下回损坏,被称为坏块。

导致数据库坏块的原因

Oracle数据库坏块分类物理坏块和逻辑坏块。所谓物理坏块是由于硬件I/O故障或操作系统故障而引起的数据块写入错误,而逻辑坏块通常是Oracle软件问题导致,具体为数据块头信息被写坏,导致头信息与数据块内容不匹配。可见,导致数据库坏块的原因很多,例如主机硬件故障、存储硬件和软件故障、操作系统故障、Oracle软件故障等,甚至应用软件压力过大都可能导致数据库出现坏块。

但有一种坏块现象则是正常现象。即当对某个数据对象以nologging方式实施了操作,例如“alter index <索引名> rebuild nologging”,而事后又对包含该对象的数据文件通过日志进行了recover操作。这样,该对象所对应的数据块将被Oracle标识为corrupt,当访问这些坏块时, Oracle将报ORA-1578错误。这种情况下,虽然可以通过下述方法查询出哪些数据对象出现坏块,但不仅无法通过recover恢复数据,也无法通过其它手段有效地从坏块中抢救数据。客户唯一能做的就是小心、小心,再小心,不要对nologging操作的数据对象进行recover操作!

坏块处理主要流程

区区几个数据库坏块,带来的影响可能是致命的。如何提高坏块处理效率,降低坏块影响范围?就象世界处理所有紧急突发事件一样,一定要事先有预案和处理流程。以下就是Oracle公司提供的坏块处理主要流程图:

技术分享

下面我们就按此流程图展开更详细的描述:

确定问题范围

首先,一旦发现出现数据库坏块,应该记录下有关坏块的所有信息,包括alert.log文件和trace文件记录的信息,确定坏块涉及的范围。例如应该评估是单个数据坏块,还是因为对nologging操作的数据对象进行recover操作之后引起的大量坏块。

此时,Oracle建议最好能通过DBVERIFY工具对坏块所在的数据文件和其它文件进行扫描,分析是否有更多坏块的存在,从而更准确地确定问题范围。如果我们获取了详细的数据文件/坏块清单,我们就可有的放矢,显著提高坏块处理效率。

Oracle建议的一些最佳实践经验如下:

    - 完整记录原始的坏块出错信息,以及遇到坏块的应用模块信息。

    - 将首次遇到坏块的几小时至当前时间的log信息抽取出来,单独保存为一个文件进行重点分析。

    - 将log文件中涉及的trace 文件进行保存。

    - 了解硬件和操作系统级是否存在报错信息。

    - 查询硬件和存储是否采用异步I/O(ASYNC I/O),磁盘快速写(Fast Write Disk)等技术。

    - 查询当前Oracle备份信息,备份时间、备份类型、备份地点等。

    - 查询数据库是否是归档或非归档模式。

检查和替换有问题的硬件

通常而言,大部分坏块是由于硬件故障而导致的。因此,在在进行坏块数据修复之前,最好对硬件进行充分检查,特别是当出现大量数据坏块或者错误是偶发性的时候。而且,根据Oracle经验,操作系统报错可能会滞后,甚至即便操作系统检查正常,也不代表硬件就一切正常。

因此,在坏块数据修复之前,最好能将有故障或疑似有故障的硬件进行替换或修复。如有可能,最好将故障存储设备的数据文件移到正常的存储设备。



坏块处理八卦图

所谓“选择合适的方法进行数据恢复和抢救”,就是根据坏块所处数据对象的不同类型,例如:CACHE、CLUSTER、INDEX PARTITION、INDEX、LOBINDE、LOBSEGMENT、ROLLBACK、TABLE PARTITION、TABLE、TEMPORARY、TYPE2 UNDO、其它数据对象等,合理制定策略和具体方法进行数据恢复和抢救。

以下就是本人根据Oracle若干篇坏块处理文档总结的数据坏块处理八卦图:

技术分享


下面将详细描述上述八卦图:

    - 首先判断坏块影响的数据库对象是否是已经不使用的数据对象了,如果是,则啥也不用做了。

    - 其次,判断坏块影响的数据库对象是否处于临时表空间,如果是,则参照上述内容:创建一个新的临时表空间,并将受到影响的用户的临时表空间设置为新的临时表空间。

    - 第三,如果坏块影响的数据库对象是索引,则进一步判断索引所在的表是否也有坏块。如果有,则先解决表的坏块问题。如果没有,则可以通过索引重建方式进行恢复。


备注:

 部分内容引用maclean blog

本文出自 “DBA的天空” 博客,请务必保留此出处http://kevinora.blog.51cto.com/9406404/1749117

oracle 数据块介绍 1

标签:数据库管理   oracle   system   操作系统   file   

原文地址:http://kevinora.blog.51cto.com/9406404/1749117

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!