ORACLE 10g和11g压缩分区表操作脚本
ORACLE 10g和11g压缩分区表操作脚本对于OLAP系统,数据量特别大,而且不能随便扩空间,所以压缩也是比较好的方法,压缩比基本是:1:2下面是压缩脚本,需要先创建log,记录压缩到哪张表的日志。下面的例子是 ORACLE 11g的-- Create tablecreate table TL_COMPRESS_LOG(OWNNAME VARCHAR2(30),TABNAME VARCHAR2(30),SUBPARNAME VARCHAR2(30),TSNAME VARCHAR2(30),BEGTIME DATE,ENDTIME DATE,OLD_MB NUMBER,NEW_MB NUMBER,OLD_ROWS NUMBER,NEW_ROWS NUMBER)tablespace USERS;-- Add comments to the tablecomment on table TL_COMPRESS_LOGis '压缩日志表';-- Add comments to the columnscomment on column TL_COMPRESS_LOG.OWNNAMEis '属主';comment on column TL_COMPRESS_LOG.TABNAMEis '表';comment on column TL_COMPRESS_LOG.SUBPARNAMEis '子分区';comment on column TL_COMPRESS_LOG.TSNAMEis '表空间';comment on column TL_COMPRESS_LOG.BEGTIMEis '压缩开始时间';comment on column TL_COMPRESS_LOG.ENDTIMEis '压缩结束时间';comment on column TL_COMPRESS_LOG.OLD_MBis '压缩前大小(MB)';comment on column TL_COMPRESS_LOG.NEW_MBis '压缩后大小(MB)';comment on column TL_COMPRESS_LOG.OLD_ROWSis '压缩前记录数';comment on column TL_COMPRESS_LOG.NEW_ROWSis '压缩后记录数';DECLAREVT1 DATE;VT2 DATE;VM1 NUMBER;VM2 NUMBER;VR1 NUMBER;VR2 NUMBER;BEGINFOR C IN (SELECT '用户名' OWNNAME,TABLE_NAME TABNAME,PARTITION_NAME PARNAME,SUBPARTITION_NAME SUBPARNAME,TABLESPACE_NAME TSNAMEFROM USER_TAB_SUBPARTITIONSWHERE TABLE_NAME LIKE 'TM_%201208'AND COMPRESSION != 'ENABLED'ORDER BY TABLE_NAME, PARTITION_NAME ,SUBPARTITION_NAME) LOOPVT1 := SYSDATE;SELECT MAX(BYTES) / 1024 / 1024INTO VM1FROM DBA_SEGMENTSWHERE OWNER = C.OWNNAMEAND SEGMENT_NAME = C.TABNAMEAND PARTITION_NAME = C.SUBPARNAME;EXECUTE IMMEDIATE 'select /*+ parallel(t,4) */ count(*) from' || C.TABNAME || ' subpartition (' || C.SUBPARNAME || ') t'INTO VR1;INSERT INTO TL_COMPRESS_LOGVALUES(C.OWNNAME,C.TABNAME,C.PARNAME,C.TSNAME,VT1,NULL,VM1,NULL,VR1,NULL);--EXECUTE IMMEDIATE 'alter table ' || C.TABNAME || ' move subpartition' || C.SUBPARNAME || ' compress tablespace ' || C.TSNAME;--VT2 := SYSDATE;SELECT MAX(BYTES) / 1024 / 1024INTO VM2FROM DBA_SEGMENTSWHERE OWNER = C.OWNNAMEAND SEGMENT_NAME = C.TABNAMEAND PARTITION_NAME = C.SUBPARNAME;EXECUTE IMMEDIATE 'select /*+ parallel(t,4) */ count(*) from' || C.TABNAME || ' subpartition (' || C.SUBPARNAME || ') t'INTO VR2;UPDATE TL_COMPRESS_LOGSET ENDTIME = VT2, NEW_MB = VM2, NEW_ROWS = VR2WHERE OWNNAME = C.OWNNAMEAND TABNAME = C.TABNAMEAND SUBPARNAME= C.PARNAME;END LOOP;END;--由于ORACLE 10g不支持直接对子分区进行压缩,所以需要对主分区进行压缩如下:--ORACLE 10gDECLAREVT1 DATE;VT2 DATE;VM1 NUMBER;VM2 NUMBER;VR1 NUMBER;VR2 NUMBER;BEGINFOR C IN (SELECT 'CTMX' OWNNAME,table_name TABNAME,partition_name PARNAME,TABLESPACE_NAME TSNAME FROMuser_tab_partitions WHERE table_name LIKE '%201303'AND compression='DISABLED') LOOPVT1 := SYSDATE;SELECT MAX(BYTES) / 1024 / 1024INTO VM1FROM DBA_SEGMENTSWHERE OWNER = C.OWNNAMEAND SEGMENT_NAME = C.TABNAMEAND PARTITION_NAME = C.PARNAME;EXECUTE IMMEDIATE 'select /*+ parallel(t,4) */ count(*) from' || C.TABNAME || ' partition (' || C.PARNAME || ') t'INTO VR1;INSERT INTO TL_COMPRESS_LOGVALUES(C.OWNNAME,C.TABNAME,C.PARNAME,C.TSNAME,VT1,NULL,VM1,NULL,VR1,NULL);--EXECUTE IMMEDIATE 'alter table ' || C.TABNAME || ' move partition' || C.PARNAME ||' compress' ;--VT2 := SYSDATE;SELECT MAX(BYTES) / 1024 / 1024INTO VM2FROM DBA_SEGMENTSWHERE OWNER = C.OWNNAMEAND SEGMENT_NAME = C.TABNAMEAND PARTITION_NAME = C.PARNAME;EXECUTE IMMEDIATE 'select /*+ parallel(t,4上一个:AIX+裸设备,ORACLE表空间扩充
下一个:Oracle设置主键自增
- 更多Oracle疑问解答:
- 运行exp备份oracle数据库提示oracle-12154错误
- 有没有,生产Oracle Rman 备份脚本的工具啊!
- 初学orcle,希望有大大帮忙解说一下详细步骤,从登录oracle到创建表的过程
- oracle语句问题:一张user表,三个字段,id,name,time,插入记录比如:张三2007,李四2008,张三2011
- 如何写一个ORACLE触发器同步两个表中的数据?
- oracle 如何查看一个服务器上有多少个数据库.
- oracle 创建包的时候错误 求解
- oracle 重复列的问题
- oracle 中如何查处2星期前的数据
- 请教oracle数据库安装中的问题
- 请问谁能提供给我标准的oracle ERP的数据库表结构并详细说明各表主要的作用?
- 安装oracle遇到的问题 invalid entry CRC (expected 0x3e12e795 but got 0x9db0e9fd)
- 我的是ORACLE 10G,在RMAN中如何按指定的时间恢复数据文件啊?
- oracle为什么没有自动增长列
- oracle快捷键都有哪些啊?