Oracle 表压缩(Table Compression)技术介绍

Oracle 表压缩(Table Compression)介绍

1、官方文档说法:

As your database grows in size, consider using table compression. Compression saves disk space, reduces memory use in the database buffer cache, and can significantly speed query execution during reads. Compression has a cost in CPU overhead for data loading and DML. However, this cost might be offset by reduced I/O requirements

随着数据库不断增长,可以考虑使用表压缩。压缩可以节省磁盘空间,减少数据库buffer cache内存使用,并且可以加速查询。

压缩对于数据装载和DML操作有一定的CPU消耗。然而,这些消耗可以为I/O的减少而抵消。

Table compression is completely transparent to applications. It is useful in decision support systems (DSS), online transaction processing (OLTP) systems, and archival systems.

表压缩对于应用程序完全透明。对于DSS系统、在线事务处理和归档系统都很有用处。

You can specify compression for a tablespace, a table, or a partition. If specified at the tablespace level, then all tables created in that tablespace are compressed by default.

你可以为表空间,表或者一个分区指定压缩。如果指定为表空间基本,那么该表空间所有表创建后默认都启用压缩。

Compression can occur while data is being inserted, updated, or bulk loaded into a table. Operations that permit compression include:

压缩可以再数据插入,更新或者批量装载入表中时发生。压缩表允许以下操作:

Single-row or array inserts and updates 单行或多行插入和更新

The following direct-path INSERT methods: 直接路径插入方法:

Direct path SQL*Loader

1)CREATE TABLE AS SELECT statements

2)Parallel INSERT statements

3)INSERT statements with an APPEND or APPEND_VALUES hint

截止目前,Oracle数据库共有4种表压缩技术:

1)Basic compression

2)OLTP compression

3)Warehouse compression (Hybrid Columnar Compression)

4)Archive compression (Hybrid Columnar Compression)

这里我主要介绍基本压缩:

2、基本压缩特点:

1)使用基本压缩,只有当数据是直接路径插入或更新记录(direct-path insert and updated )时才会发生压缩。

并且支持有线的数据类型和SQL操作。

3、如何启用基本压缩?

1)通过create table语句中指定compress条件。

2)通过alter table .. compress; 来给现有表启用压缩;

3)通过alter table .. nocompress; 来禁用表压缩

4、关于基本压缩的一些例子

4.1 创建压缩表

CREATE TABLE emp_comp compress
AS
SELECT * FROM emp
WHERE 1=2;

4.2 通过数据字典查看压缩表状态

[email protected]> SELECT table_name, compression, compress_for
  2  FROM user_tables
  3  WHERE table_name=‘EMP_COMP‘;

TABLE_NAME                     COMPRESS COMPRESS_FOR
------------------------------ -------- ------------
EMP_COMP                       ENABLED  BASIC

4.3 通过非直接路径插入数据

[email protected]> INSERT INTO emp_comp
  2  SELECT * FROM emp;

已创建16行。

[email protected]> commit;

--查看表占用
[email protected]> exec show_space(‘EMP_COMP‘,‘SCOTT‘);
Unformatted Blocks  ....................               0
FS1 Blocks (0-25)   ....................               0
FS2 Blocks (25-50)  ....................               0
FS3 Blocks (50-75)  ....................               0
FS4 Blocks (75-100) ....................               5
Full Blocks         ....................               0
Total Blocks ...........................               8
Total Bytes  ...........................          65,536
Total MBytes ...........................               0
Unused Blocks...........................               0
Unused Bytes ...........................               0
Last Used Ext FileId....................               4
Last Used Ext BlockId...................          14,304
Last Used Block.........................               8

--看下emp的占用
[email protected]> exec show_space(‘EMP‘,‘SCOTT‘);
Unformatted Blocks  ....................               0
FS1 Blocks (0-25)   ....................               0
FS2 Blocks (25-50)  ....................               0
FS3 Blocks (50-75)  ....................               0
FS4 Blocks (75-100) ....................               5
Full Blocks         ....................               0
Total Blocks ...........................               8
Total Bytes  ...........................          65,536
Total MBytes ...........................               0
Unused Blocks...........................               0
Unused Bytes ...........................               0
Last Used Ext FileId....................               4
Last Used Ext BlockId...................             144
Last Used Block.........................               8

--对比与原EMP表的占用情况,emp_comp表并未压缩。

注:关于show_space过程的用法,请参考【http://blog.csdn.net/indexman/article/details/47207987

4.4 通过直接路径插入数据

drop table emp_comp purge;

CREATE TABLE emp_comp compress
AS
SELECT * FROM emp
WHERE 1=2;

insert /*+ append */ into emp_comp
select *
from emp;

--查看表占用
[email protected]> exec show_space(‘EMP_COMP‘,‘SCOTT‘);
Unformatted Blocks  ....................               0
FS1 Blocks (0-25)   ....................               0
FS2 Blocks (25-50)  ....................               0
FS3 Blocks (50-75)  ....................               0
FS4 Blocks (75-100) ....................               0
Full Blocks         ....................               1
Total Blocks ...........................               8
Total Bytes  ...........................          65,536
Total MBytes ...........................               0
Unused Blocks...........................               4
Unused Bytes ...........................          32,768
Last Used Ext FileId....................               4
Last Used Ext BlockId...................          14,304
Last Used Block.........................               4

--很明显少占用4个数据块

4.5 禁用表压缩

SCOTT@orcl> alter table emp_comp NOCOMPRESS;

表已更改。

SCOTT@orcl> SELECT table_name, compression, compress_for
  2  FROM user_tables
  3  WHERE table_name=‘EMP_COMP‘
  4  ;

TABLE_NAME                     COMPRESS COMPRESS_FOR
------------------------------ -------- ------------
EMP_COMP                       DISABLED

4.6 启用表压缩

SCOTT@orcl> alter table emp_comp COMPRESS;

表已更改。

SCOTT@orcl> SELECT table_name, compression, compress_for
  2  FROM user_tables
  3  WHERE table_name=‘EMP_COMP‘;

TABLE_NAME                     COMPRESS COMPRESS_FOR
------------------------------ -------- ------------
EMP_COMP                       ENABLED  BASIC

5、最后来看下表压缩的几个使用限制:

1)对于基本压缩,你无法在压缩表上增加一个带默认值的列:

[email protected]> alter table emp_comp add remark varchar2(200) default ‘null‘;
alter table emp_comp add remark varchar2(200) default ‘null‘
                         *
第 1 行出现错误:
ORA-39726: 不支持对压缩表执行添加/删除列操作

2)无法删除压缩表上的列:

[email protected]> alter table emp_comp drop column ename;
alter table emp_comp drop column ename
                                 *
第 1 行出现错误:
ORA-39726: 不支持对压缩表执行添加/删除列操作

3)表压缩不支持在线段收缩(Online segment shrink)

4)不支持SecureFiles large objects

5)压缩表创建时默认设置PCT_FREE 为 0; 除非你手工指定。

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-10 13:34:06

Oracle 表压缩(Table Compression)技术介绍的相关文章

oracle 表压缩技术

压缩表是我们维护管理中常常会用到的.以下我们看都oracle给我们提供了哪些压缩方式. 文章摘自"Oracle? Database Administrator's Guide11g Release 2 (11.2)".由于Hybrid Columnar Compression压缩仅仅有在Exadata上才支持,眼下用的比較少,我们会重点说一下basic和oltp两种压缩方式. Consider Using Table Compression As your database grows

Oracle的表压缩

1.官方文档说法: Oracle支持在表空间(tablespace).数据表(table)和分区(Partition)级别的压缩,如果设置为表空间级别,那么默认将该表空间中的全部的表都进行压缩.压缩操作可以在数据单条插入.数据修改和数据批量导入时发生. As your database grows in size, consider using table compression. Compression saves disk space, reduces memory use in the d

oracle 11G表压缩

最近一套生产库表空间一直告警在90%以上,但的磁盘硬件资源又不足,整个库已经达到26T.库里存储了近4年的数据,与业务沟通说历史数据基本上不会做操作,但是又不能归档,所以想到了压缩表来节省表空间. 随着数据库的增长,我们可以考虑使用oracle的表压缩技术.表压缩可以节省磁盘空间.减少data buffer cache的内存使用量.并可以显著的提升读取和查询的速度.当使用压缩时,在数据导入和DML操作时,将导致更多的CPU开销,然而,由于启用压缩而减少的I/O需求将抵消CPU的开销而产生的成本.

Oracle压缩功能小结2—预估表压缩的效果

在使用压缩之前,我们可以估算一下使用压缩能够拥有多大的效果. 11gr2以前可以使用dbms_comp_advisor,具体代码已经在附件中给出.只需要执行两个文件dbmscomp.sql和prvtcomp.plb,然后使用DBMS_COMP_ADVISOR.getratio存储过程即可.不再详细描述. SQL> set serveroutput on SQL> execdbms_comp_advisor.getratio('SH','SALES',10) Sampling table: SH

Oracle Schema Objects——Tables——Table Compression

Table Compression 表压缩 The database can use table compression to reduce the amount of storage required for the table. 数据库可以使用表压缩来消除数据块中的重复值. Compression saves disk space, reduces memory use in the database buffer cache, and in some cases speeds query

【翻译自mos文章】oracle数据库中 基本的表压缩和高级压缩之间的区别

基本的表压缩和高级压缩之间的区别, 摘录自mos文章Difference Between Basic Table Compression And Advanced Compression (Doc ID 1548187.1) 适用于: Oracle Database - Enterprise Edition - Version 10.2.0.5 and later Information in this document applies to any platform. 目标: What is

Oracle使用Sql把XML解析成表(Table)的方法

SELECT * FROM XMLTABLE('$B/DEAL_BASIC/USER_DEAL_INFO' PASSING XMLTYPE('<?xml version="1.0" encoding="gb2312" ?> <DEAL_BASIC> <USER_DEAL_INFO> <USER_DEAL_ID>1000100001</USER_DEAL_ID> <DEAL_INURE_TIME>

SQL Tuning 基础概述04 - Oracle 表的类型及介绍

Tables A table describes an entity such as employees. You define a table with a table name, such as employees, and set of columns. In general, you give each column a name, a data type, and a width when you create the table. 1.普通堆表(Heap-Organized Tabl

14.7 InnoDB Table Compression

pdf:http://download.csdn.net/detail/paololiu/9576929 14.7 InnoDB Table Compression 14.7.1 Overview of Table Compression 14.7.2 Enabling Compression for a Table 14.7.3 Tuning Compression for InnoDB Tables 14.7.4 Monitoring Compression at Runtime 14.7.