[20180814]慎用查看表压缩率脚本.txt

--//最近看exadata方面书籍,书中提供1个脚本,查看某些表采用那些压缩模式压缩比能达到多少.
--//通过调用DBMS_COMPRESSION.get_compression_ratio确定压缩比.例子如下:

--//测试版本11.2.0.4.
declare
        blockct_comp    number;
        blockct_uncomp  number;
        rows_comp       number;
        rows_uncomp     number;
        comp_rat        number;
        comp_type       varchar2(40);
begin
          dbms_compression.get_compression_ratio('&&tblspc','&&ownr','&&tblname',null,  dbms_compression.comp_for_oltp,        blockct_comp, blockct_uncomp,rows_comp,rows_uncomp, comp_rat, comp_type);
          dbms_output.put_line('Compression type: '||comp_type||'     Compression ratio (est):'||comp_rat);
          dbms_compression.get_compression_ratio('&&tblspc','&&ownr','&&tblname',null,  dbms_compression.comp_for_query_low,   blockct_comp, blockct_uncomp,rows_comp,rows_uncomp, comp_rat, comp_type);
          dbms_output.put_line('Compression type: '||comp_type||'     Compression ratio (est):'||comp_rat);
          dbms_compression.get_compression_ratio('&&tblspc','&&ownr','&&tblname',null,  dbms_compression.comp_for_query_high,  blockct_comp, blockct_uncomp,rows_comp,rows_uncomp, comp_rat, comp_type);
          dbms_output.put_line('Compression type: '||comp_type||'     Compression ratio (est):'||comp_rat);
          dbms_compression.get_compression_ratio('&&tblspc','&&ownr','&&tblname',null,  dbms_compression.comp_for_archive_low, blockct_comp, blockct_uncomp,rows_comp,rows_uncomp, comp_rat, comp_type);
          dbms_output.put_line('Compression type: '||comp_type||'     Compression ratio (est):'||comp_rat);
          dbms_compression.get_compression_ratio('&&tblspc','&&ownr','&&tblname',null,  dbms_compression.comp_for_archive_high,blockct_comp, blockct_uncomp,rows_comp,rows_uncomp, comp_rat, comp_type);
          dbms_output.put_line('Compression type: '||comp_type||'     Compression ratio (est):'||comp_rat);
end;
/

--//好奇心我想看看生产系统一张大表能达到多少.我执行上面的脚本,结果等大约2-3分钟没有结果出来,我马上中断处理.
--//我当时想既然大表可能分析数据量大,换1个点的表看看.
--//结果执行后包如下错误:

ERROR at line 1:
ORA-20000: YOU CAN NOT TRUNCATE or DROP CMP3$97116 TABLE!
ORA-06512: at line 6
ORA-06512: at "SYS.PRVT_COMPRESSION", line 1136
ORA-06512: at "SYS.PRVT_COMPRESSION", line 1114
ORA-20000: YOU CAN NOT TRUNCATE or DROP CMP1$97116 TABLE!
ORA-06512: at "SYS.DBMS_COMPRESSION", line 214
ORA-06512: at line 9

--//BTW:我们生产系统有系统触发器,禁止用户drop和truncate表.这样导致脚本运行报错.
--//我看了一下CMP3$97116,CMP1$97116表结果,和分析表结构一致.

CREATE TABLE xxxxxx_yyy.CMP4$97116
(
  ZYH        NUMBER(18)                         NOT NULL,
  ....
  YB_DBZ     VARCHAR2(4 BYTE)
)
TABLESPACE xxxxxx_yyy
RESULT_CACHE (MODE DEFAULT)
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            NEXT             1M
            MAXSIZE          UNLIMITED
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
            FLASH_CACHE      DEFAULT
            CELL_FLASH_CACHE DEFAULT
           )
NOLOGGING
COMPRESS FOR OLTP
~~~~~~~~~~~~~~~
NOCACHE
NOPARALLEL
MONITORING;

--//可以看出DBMS_COMPRESSION.get_compression_ratio操作很简单,先建立与分析表一样的表结构以及对应压缩模式的表,然后
--//导入数据后比较分析压缩比.
--//这样要耗费大量表空间与资源做这个工作,在生产系统要小心谨慎.

--//我事后认真看了<深入理解ORACLE Exadata> P98页.而是讲样本数据插入一个临时表中.同时压缩版本的临时表也被创建,比较压缩
--//版本和非压缩版本的大小就可以得到压缩率.
--//(注:我看到的不是临时表,而是真实的表,看上面的表定义.或许作者理解的临时表非我理解的临时表)
--//我不知道取样比例是多少,总之在生产系统执行该脚本还是要小心.
--//另外书P101提到 压缩助手的一大亮点是能够在非exadata平台上运行,在真正迁移数据到exadata平台之前,它能够提供足够的信息
--//帮助你做出合理的选择.这么讲非exadata平台还是能够建立hcc压缩模式的相关数据,只不过你不能查看.

--//我曾经在dg上查看压缩表信息,链接[20150727]exadata压缩HCC与dataguard.txt=>http://blog.itpub.net/267265/viewspace-1753362/
XXXX@zzzzdg2> select * from t where rownum<=1;
select * from t where rownum<=1
              *
ERROR at line 1:
ORA-64307:  Exadata Hybrid Columnar Compression is not supported for tablespaces on this storage type

--//在家里测试的结果.
SCOTT@test01p> @ ver1

PORT_STRING                    VERSION        BANNER                                                                               CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0           12.1.0.1.0     Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

create table t as select * from all_objects ;
--//反复插入,提示要大于1000000rows才可以.

SCOTT@test01p> select count(*) from t;

COUNT(*)
----------
   1437952
--//占用192M.

Compression type: "Compress Advanced"     Compression ratio (est):3.5
Compression Advisor self-check validation successful. select count(*) on both Uncompressed and EHCC Compressed format = 1000001 rows
Compression type: "Compress Query Low"     Compression ratio (est):8.6
Compression Advisor self-check validation successful. select count(*) on both Uncompressed and EHCC Compressed format = 1000001 rows
Compression type: "Compress Query High"     Compression ratio (est):16.3
Compression Advisor self-check validation successful. select count(*) on both Uncompressed and EHCC Compressed format = 1000001 rows
Compression type: "Compress Archive Low"     Compression ratio (est):16.6
Compression Advisor self-check validation successful. select count(*) on both Uncompressed and EHCC Compressed format = 1000001 rows
Compression type: "Compress Archive High"     Compression ratio (est):21.7
PL/SQL procedure successfully completed.

--//如果单独执行如下:
--//在sys用户下建立触发器禁止drop表.

CREATE OR REPLACE TRIGGER SYS.TRI_PREVENT_DROP_TRUNCATE
   BEFORE TRUNCATE OR DROP ON DATABASE
BEGIN
   IF ora_dict_obj_type = 'TABLE' AND ora_dict_obj_owner = 'SCOTT' and ORA_DICT_OBJ_NAME not like 'SYS\_JOURNAL\_%' escape '\'
   THEN
      raise_application_error (-20000, 'YOU CAN NOT TRUNCATE or DROP ' || ora_dict_obj_name || ' TABLE!');
   END IF;
END;
/

--//如果单独执行如下:
/* Formatted on 2018/8/14 8:49:08 (QP5 v5.269.14213.34769) */
set serveroutput on
DECLARE
   blockct_comp     NUMBER;
   blockct_uncomp   NUMBER;
   rows_comp        NUMBER;
   rows_uncomp      NUMBER;
   comp_rat         NUMBER;
   comp_type        VARCHAR2 (40);
BEGIN
DBMS_COMPRESSION.get_compression_ratio
   (
      '&&tblspc'
     ,'&&ownr'
     ,'&&tblname'
     ,NULL
     ,DBMS_COMPRESSION.comp_archive_high
     ,blockct_comp
     ,blockct_uncomp
     ,rows_comp
     ,rows_uncomp
     ,comp_rat
     ,comp_type
   );
   DBMS_OUTPUT.put_line
   (
         'Compression type: '
      || comp_type
      || '     Compression ratio (est):'
      || comp_rat
   );
END;
/
--//注:12c参数DBMS_COMPRESSION.comp_archive_high与11g不同.11g写成DBMS_COMPRESSION.comp_for_archive_high
--//由于触发器建立,报错如下:
SCOTT@test01p> @ exadata/comp_radio12x.sql
old  11:       '&&tblspc'
new  11:       'USERS'
old  12:      ,'&&ownr'
new  12:      ,'SCOTT'
old  13:      ,'&&tblname'
new  13:      ,'T'
Compression Advisor self-check validation successful. select count(*) on both Uncompressed and EHCC Compressed format = 1000001 rows
DECLARE
*
ERROR at line 1:
ORA-20000: YOU CAN NOT TRUNCATE or DROP CMP1$107873 TABLE!
ORA-06512: at line 4
ORA-06512: at "SYS.PRVT_COMPRESSION", line 2134
ORA-06512: at "SYS.PRVT_COMPRESSION", line 1108
ORA-20000: YOU CAN NOT TRUNCATE or DROP CMP1$107873 TABLE!
ORA-06512: at "SYS.PRVT_COMPRESSION", line 237
ORA-06512: at "SYS.DBMS_COMPRESSION", line 215
ORA-06512: at line 9

SCOTT@test01p> select owner,object_name,CREATED from dba_objects where owner=user and object_name like 'CMP%';
OWNER                OBJECT_NAME          CREATED
-------------------- -------------------- -------------------
SCOTT                CMP4$107873          2018-08-14 20:58:05
SCOTT                CMP3$107873          2018-08-14 20:57:57
SCOTT                CMP2$107873          2018-08-14 20:57:51
SCOTT                CMP1$107873          2018-08-14 20:57:48

--//这次测试建立4张表.
SCOTT@test01p> select * from CMP4$107873;
select * from CMP4$107873
              *
ERROR at line 1:
ORA-64307:  Exadata Hybrid Columnar Compression is not supported for tablespaces on this storage type

--//可以发现oracle建立hcc表在非exadata是可行的,但是里面的数据不能看.

[20180814]慎用查看表压缩率脚本.txt的更多相关文章

  1. [转] 使用SQL脚本查看表空间使用率和使用dba_tablespace_usage_metrics视图的差别

    传统的SQL脚本查看表空间使用率,使用的关键视DBA_DATA_FILE和DBA_FREE_SPACE. Oracle 11g引入了DBA_TABLESPACE_USAGE_METRICS视图.其实, ...

  2. ORACLE查看表空间对象

    ORACLE如何查看表空间存储了那些数据库对象呢?可以使用下面脚本简单的查询表空间存储了那些对象: SELECT TABLESPACE_NAME       AS TABLESPACE_NAME    ...

  3. Oracle 查看表空间大小及其扩展

    在ORACLE数据库中,所有数据从逻辑结构上看都是存放在表空间当中,当然表空间下还有段.区.块等逻辑结构.从物理结构上看是放在数据文件中.一个表空间可由多个数据文件组成.系统中默认创建的几个表空间:S ...

  4. MySQL分库分表备份脚本

    MySQL分库备份脚本 #脚本详细内容 [root@db02 scripts]# cat /server/scripts/Store_backup.sh #!/bin/sh MYUSER=root M ...

  5. [20190423]oradebug peek测试脚本.txt

    [20190423]oradebug peek测试脚本.txt --//工作测试需要写一个oradebug peek测试脚本,不断看某个区域内存地址的值. 1.环境: SCOTT@book> @ ...

  6. hive表信息查询:查看表结构、表操作等--转

    原文地址:http://www.aboutyun.com/forum.PHP?mod=viewthread&tid=8590&highlight=Hive 问题导读:1.如何查看hiv ...

  7. (转)企业Shell实战-MySQL分库分表备份脚本

    本文来自http://www.xuliangwei.com/xubusi/252.html 免费视频讲解见 http://edu.51cto.com/course/course_id-5064.htm ...

  8. hive表信息查询:查看表结构、表操作等

    转自网友的,主要是自己备份下 有时候不记得! 问题导读:1.如何查看hive表结构?2.如何查看表结构信息?3.如何查看分区信息?4.哪个命令可以模糊搜索表 1.hive模糊搜索表 show tabl ...

  9. [20190510]快速建立执行脚本.txt

    [20190510]快速建立执行脚本.txt --//上午在测试建立表空间备份时,浪费一点点时间.脚本如下:$ cat d10.sqldrop tablespace t01 including con ...

随机推荐

  1. SpringBoot2.0源码分析(四):spring-data-jpa分析

    SpringBoot具体整合rabbitMQ可参考:SpringBoot2.0应用(四):SpringBoot2.0之spring-data-jpa JpaRepositories自动注入 当项目中存 ...

  2. 【原创】为什么浮点数1e38f + 1 - 1e38f等于0

    1. 问题 为什么1e38f + 1 - 1e38f为0? 2. 分析 ; //00 00 00 02 int *pii = &ii; float i = 1e38f; //7e 96 76 ...

  3. 消息中间件RabbitMQ(一)

    1.消息中间件 消息队列中间件是指利用高效可靠地消息传递机制传递消息.有两种传递模式:点对点模式.发布/订阅模式.流行的消息中间件有RabblitMQ.Kafka.RockerMQ.它们都提供了基于存 ...

  4. vue开发中,build时css打包报错

    vue在打包的时候css报错,首先声明的这个并没有解决webpack本身的问题,本来这个也是一个警示,不会影响代码正常运行 这个是因为我在多个页面引入了同一个css文件,webpack打包时候对css ...

  5. 分布式系统监视zabbix讲解九之使用snmp监控windows--技术流ken

    前言 使用zabbix监控windows主要有两种方法,一种是在windows端安装zabbix-agent客户端工具,安装麻烦.另外一种是使用snmp协议,配置简单快捷.两种配置都可以实现同样的效果 ...

  6. jquery发起get/post请求_或_获取html页面数据

    备注:我们经常会遇到使用jquery获取某个地址下的部分页面内容,然后替换当前页面对应内容,也就是:局部刷新功能. 当然也可以使用get/post请求获取数据,修改数据,可以参考以下JS代码: 走过的 ...

  7. Linux-cut命令(22)

    cut剪切命令cut命令通常用来对某个文本文件进行解析,擅长处理以一个字符间隔的文本内容 -b :以字节(bytes)为单位进行分割.这些字节位置将忽略多字节字符边界,除非也指定了 -n 标志. -c ...

  8. MySQL8.0设置远程访问权限

    mysql 8.0.11 用Navicat远程无法连接 症状: 安装了mysql 8.0.11 之后本地可以登录,但是远程第三方工具无法连接,防火墙已经放通的, 解决之道: 首先登陆到mysql命令行 ...

  9. MySQL事务(学习笔记)

    MySQL事务主要用于处理操作量大,复杂度高的数据.比如说,在人员管理系统中,你删除一个人员,你即需要人员的基本资料,也要删除和该人员相关的信息,如信箱,文章等等,这样,这些数据库操作语句就构成一个事 ...

  10. could not read Username for 'https://github.com': No error

    用idea往github上push代码的时候,突然的不能用了. 报could not read Username for 'https://github.com': No error错误. 原因不明. ...