问题描述:如何在oltp环境中为所有dml语句压缩数据
解决方案:使用oracle oltp压缩
创建表时使用compress for oltp
create table regs(id number,name varchar2(1000)) compress for oltp;
在11.2之前,compress for oltp使用compress for all operation;
compress basic使用compress for direct_load operation代替;
select table_name,compression,compress_for from user_tables where table_name='REGS';
TABLE_NAME COMPRESS COMPRESS_FOR
------------------------------ -------- ------------
REGS ENABLED OLTP
修改已存在的表为oltp压缩表
alter table regs compress for oltp;
并不影响现有的数据,使用move对已有的数据压缩,同样索引会失效
alter table regs move compress for oltp;
禁用压缩
alter table regs nocompress;
alter table regs move nocompress;
工作原理:
oltp为所有dml语句启用压缩,但并不会马上压缩,而是会在数据块的修改达到一定阀值,成批次压缩,使用内部算法压缩
也可以在表空间级别指定压缩
create tablespace comp_data datafile 'xxx' size 500m extent management local segment space management auto default compress for oltp;
修改一个表空间压缩属性
alter tablespace users default compress for oltp;
select tablespace_name,def_tab_compression,compress_for from dba_tablespaces where tablespace_name='USERS';
解决方案:使用oracle oltp压缩
创建表时使用compress for oltp
create table regs(id number,name varchar2(1000)) compress for oltp;
在11.2之前,compress for oltp使用compress for all operation;
compress basic使用compress for direct_load operation代替;
select table_name,compression,compress_for from user_tables where table_name='REGS';
TABLE_NAME COMPRESS COMPRESS_FOR
------------------------------ -------- ------------
REGS ENABLED OLTP
修改已存在的表为oltp压缩表
alter table regs compress for oltp;
并不影响现有的数据,使用move对已有的数据压缩,同样索引会失效
alter table regs move compress for oltp;
禁用压缩
alter table regs nocompress;
alter table regs move nocompress;
工作原理:
oltp为所有dml语句启用压缩,但并不会马上压缩,而是会在数据块的修改达到一定阀值,成批次压缩,使用内部算法压缩
也可以在表空间级别指定压缩
create tablespace comp_data datafile 'xxx' size 500m extent management local segment space management auto default compress for oltp;
修改一个表空间压缩属性
alter tablespace users default compress for oltp;
select tablespace_name,def_tab_compression,compress_for from dba_tablespaces where tablespace_name='USERS';