Oracle OLTP表压缩

Oracle 11g引入的OLTP表压缩能在事务处理环境中减少存储空间并提升性能。该压缩算法通过消除数据库块内的重复值实现压缩,并在块内存储元数据,无需额外I/O开销即可读取。压缩对读取数据无影响,写操作会有轻微性能开销,可通过批处理模式和阈值控制。启用OLTP表压缩可通过创建表时指定、ALTER TABLE或在线重定义等方式实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址,转载请注明出处:http://blog.youkuaiyun.com/anzelin_ruc/article/details/8202847 ©安泽林

表数据的压缩

Oracle 9i对于批量导入操作的数据提供了基本表压缩。

Oracle 11g引入了一个新的特性—OLTP表压缩,所谓OLTP表压缩就是允许在任何类型的数据操作过程中对数据进行压缩,例如通常的数据操作语言,插入、更新等。除此之外,表压缩减少了写操作的相关压缩开销,使之适用于事务型或OLTP环境,因此对于所有的应用程序工作负载来说OLTP表压缩都更好的扩展了压缩所带来的益处。

OLTP 表压缩

Oracle的OLTP表压缩专门设计了一个“唯一”(unique)压缩算法来处理OLTP应用程序。该算法通过消除同一个数据库块内重复的值(这些值可以是跨越不同列的)来达到压缩的目的。压缩过后的块包含一个称为符号表的结构来保持压缩的元数据。当数据库块被压缩的时候,首先在符号表中为重复值添加一个副本,然后将这个重复值删除,这样每一个重复的值都可以被一个指向符号表中对应条目的一个更短的引用所替代。


图1 压缩前与压缩后的数据块

该算法的革新性在于,压缩后的数据在数据库块内是独立的,那些用于将压缩后的数据恢复到其原始状态的元数据也存储在对应数据库块中。与那些在全局数据库上维护一个符号表的压缩算法比较,Oracle的这个独特的设计因为在访问压缩数据的时候不用引进额外的I/O开销而显著提升了性能。

OLTP表压缩的益处

在给定环境下获得的压缩比率取决于给定的数据的自身性质,特别是数据自身的基数(例如某数据的基数只有0~9这十个数字,显然在同样情况下相对于基数为0~100的数据,其占用空间少,压缩效果好)。

OLTP表压数,不仅仅在于节省磁盘存储空间,一个显著的优势是,Oracle有能力在不事先对数据块进行解压缩就可以直接读取压缩数据块的内容。因此,也就不会因为访问压缩数据而使性能大幅降低。而相反的,由于Oracle要访问的数据块数目更少了,从而降低了I/O开销,这样反而可能会提高性能。进一步的,同样大小的缓冲区因可存储更多的数据,而变得更大高效。

最小化性能开销

OLTP表压缩对读取数据没有产生任何影响,而在写数据(即压缩数据)的时候必须做额外的工作,所以写操作的性能开销是不可避免的。因此Oracle在最小化表压缩开销上投入了大量的工作。Oracle采用批处理模式压缩块而不是每有一个写操作就进行数据的压缩。刚被初始化的数据块在达到数据块内部控制的阈值(比如80%)之前并不压缩。当一个事务导致数据块内部达到设定的阈值之后,数据块内部所有的内容都被压缩(这时数据块内数据量低于阈值),如果之后的某一个事务再次导致数据块内部达到设定的阈值之后就再次对整个数据块进行压缩。重复执行这个过程,直到Oracle认为进一步压缩不会获得合适的收益为止。在整个过程中,只有触发块压缩的事务会有轻微的压缩开销。因此大多数的OLTP事务的性能在压缩后与未压缩的数据块上都基本相同。


图2  OLTP 表压缩处理过程

Migration and Best Practices

For new tables andpartitions,enabling OLTP Table Compression is as easy as simply CREATEing thetable orpartition and specifying “COMPRESS FOR OLTP”. See the example below:CREATETABLE emp (emp_id NUMBER, first_name VARCHAR2(128), last_nameVARCHAR2(128))COMPRESS FOR OLTP; For existing tables and partitions, there arethreerecommended approaches to enabling OLTP Table Compression:


1. ALTERTABLE …COMPRESS FOR OLTP

 

This approach willenable OLTPTable Compression for all future DML -- however,the existing datain the table will remain uncompressed.

 

2.OnlineRedefinition (DBMS_REDEFINITION)

 

This approach willenable OLTPTable Compression for future DML andalso compress existing data.Using DBMS_REDEFINITION keeps the table onlinefor both read/write activityduring the migration. Run DBMS_REDEFINITION inparallel for best performance.

 

Online redefinitionwill clonethe indexes to the interim table during the operation. All the clonedindexesare incrementally maintained during the sync (refresh) operation sothere is no interrupt in the use of theindexes during, or after, the onlineredefinition. The only exception iswhen online redefinition is used forredefining a partition --the global index is invalidated and needsto be rebuilt after the online redefinition.

 

3. ALTERTABLE …MOVE COMPRESS FOR OLTP

 

This approach willenable OLTP TableCompression for future DML andalso compress existing data. Whilethe table is being moved it is online for read activity but has an exclusive(X) lock – soall DML will be blocked until the move commandcompletes. Run ALTER TABLE MOVEin parallel for best performance.

 

The ALTERTABLE...MOVEstatement allows you to relocate data of a non-partitioned table,or of apartition of a partitioned table, into a new segment,and optionally intoadifferent tablespace. ALTER TABLE MOVE COMPRESS compresses the data bycreatingnew extents for the compressed data in the tablespace being moved to --it isimportant to note that the positioning of the new segment can beanywherewithin the datafile, not necessarily at the tail of the file or head ofthefile. When the original segment is released, depending on the location oftheextents, it may or may not be possible to shrink the datafile.

 

ALTER TABLE MOVEwill invalidate any indexes on the partitionor table; thoseindexes will need to be rebuilt after the ALTER TABLE MOVE.Alternatively, theuse of ALTER TABLE MOVE with the UPDATE INDEXES clause willmaintain indexes (itplaces an exclusive (X) lock so all DML will be blockeduntil the move commandcompletes).

几点说明

1.             对每一个高级压缩功能来说,与复制生产环境最紧密的环境(where you can most closely duplicate theproduction environment)是最好的测试环境,因为这样可以提供更加真实的性能比较。

2.             有很多的副本数据存储的时候,OLTP表压缩的使用,可以最好的节省存储空间,例如在备份的时候,好的压缩会导致更少的数据备份,从而缩短恢复时间。在有最多重复值的列上先进行排序,然后再批量导入可能会更好的提高压缩比。

3.             虽然说CPU开销已经最小化了,但是在拥有足够的CPU周期的系统上更好。

4.             OracleAdvanced CompressionAdvisor一个PL / SQL包,通过分析数据样本来估计OLTP表压缩可能的节省的存储空间。

5.             OLTP表压缩不支持多与255列的表及LONG类型数据。

 

AdvancedCompression with OracleDatabase 11g:

http://www.oracle.com/technetwork/database/storage/advanced-compression-whitepaper-130502.pdf

David Dai -- Focuson Oracle:

http://blog.youkuaiyun.com/tianlesoftware/article/details/8170488


本文博客园地址:http://www.cnblogs.com/anzelin/archive/2012/11/20/2778764.html

个人博客地址: http://sunny614.sinaapp.com/?p=68


 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值