oracle压缩表空间

本文介绍了如何在Oracle数据库中创建和管理压缩表空间,包括创建压缩表空间、将普通表空间转换为压缩表空间,以及在压缩表空间中创建不同压缩类型的表和索引。压缩表空间适用于存放历史数据或不频繁更新删除的表,可以节省存储空间但会增加CPU消耗。

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

压缩表空间的优点:节省时间,缺点:消耗CPU。一般用于存放历史数据,或者不经常update delete的表。

1.创建压缩表空间:

SYS@orcl> create tablespace compress_01 datafile '/u01/app/oracle/oradata/orcl/compress_01.dbf' size 10m default compress for oltp;

Tablespace created.

--查询表空间信息

SYS@orcl> selecttablespace_name,compress_for from dba_tablespaces;

TABLESPACE_NAME                COMPRESS_FOR

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

SYSTEM

SYSAUX

UNDOTBS1

TEMP

USERS

EXAMPLE

TEST

COMPRESS_01                    OLTP

2.创建一个普通表空间,修改普通表空间为压缩表空间

SYS@orcl> create tablespace tbs1datafile '/u01/app/oracle/oradata/orcl/tbs1.dbf' size 10m;

Tablespace created.

 

SYS@orcl> alter tablespace tbs1 default compress for oltp;

Tablespace altered.


SYS@orcl> alter tablespace tbs1 default nocompress; 

Tablespace altered.

3.在压缩表空间中创建表

a.在压缩表空间里创建oltp压缩表

SYS@orcl> create table t compress foroltp tablespace compress_01 as select * from all_objects;

Table created.

b.在压缩表空间里创建非压缩表

SYS@orcl> create table t1 tablespacecompress_01 as select * from all_objects;

Table created.

对压缩表和非压缩表进行分析:

SYS@orcl> execdbms_stats.gather_table_stats(user,'T');

PL/SQL procedure successfully completed.

 

SYS@orcl> execdbms_stats.gather_table_stats(user,'T1');

PL/SQL procedure successfully completed.


SYS@orcl> select table_name,compress_forfrom user_tables where table_name in('T','T1');

TABLE_NAME                     COMPRESS_FOR

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

T                              OLTP

T1                             OLTP

结论:在oltp压缩表空间里创建压缩表,如果不指定默认的压缩方式,默认是按照表空间的压缩方式

oltp来进行压缩。

c.在压缩表空间里创建指定压缩方式的表

SYS@orcl> create table t2 compresstablespace compress_01 as select * from v$tablespace;

Table created.

 

SYS@orcl> select table_name,compress_forfrom user_tables where table_name='T2';

TABLE_NAME                     COMPRESS_FOR

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

T2                             BASIC

结论:在oltp压缩表空间内创建表的时候,指定压缩方式为basic compress,那么创建的表是按照basic compression压缩,

说明表级别的压缩方式会覆盖表空间级别的压缩方式。

d.索引的压缩

SYS@orcl> create index idx_1 ont(object_id) tablespace compress_01; 

Index created.


SYS@orcl> select index_name,compression from user_indexes whereindex_name='IDX_1';

INDEX_NAME                     COMPRESS

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

IDX_1                          DISABLED

 

SYS@orcl> create index idx_2 ont1(object_id) compress tablespace compress_01;

Index created.


SYS@orcl> select index_name,compressionfrom user_indexes where index_name='IDX_2';

INDEX_NAME                     COMPRESS

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

IDX_2                          ENABLED

结论:在压缩表空间里创建索引,索引仍然是diabled,没有压缩,如果要压缩索引,必须手动致命compress





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值