[20180814]慎用查看表壓縮率腳本.txt

来源:https://www.cnblogs.com/lfree/archive/2018/08/14/9477939.html
-Advertisement-
Play Games

[20180814]慎用查看表壓縮率腳本.txt--//最近看exadata方面書籍,書中提供1個腳本,查看某些表採用那些壓縮模式壓縮比能達到多少.--//通過調用DBMS_COMPRESSION.get_compression_ratio確定壓縮比.例子如下:--//測試版本11.2.0.4.de ...


[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是可行的,但是裡面的數據不能看.


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 電腦反應慢,軟體運行卡頓,關鍵時刻無響應!!!心情瞬間不好了,重裝大法好,扔掉臃腫的舊系統!安裝好系統裝機助手,體驗一個不一樣的系統!今天我們就帶大家瞭解一下如何使用好系統重裝助手安裝windows系統 首先呢,先去好系統官網下載好系統重裝助手。 然後安裝,雙擊下載好的好系統重裝助手.EXE文件,點 ...
  • #!/bin/bash#Auth:Darius#自動化安裝dhcp服務#"$1"為測試IP,用來查看IP段是否能通eno=`ifconfig|awk '{print $1}'|head -1|awk -F ":" '{print $1}'`file=/etc/sysconfig/network-sc ...
  • 按網上版本,沒能運行成功,主要是環境變數里路徑設置錯誤,紅字為更改的部分 blatSrc35.zip下載地址:http://users.soe.ucsc.edu/~kent/src/ 對於下載好的源代碼安裝包blatSrc35.zip,需進行編譯,安裝過程如下: 1.用unzip blatSrc35 ...
  • 在有些需求當中我們需要抓取欄位並且填充到excel表格裡面,最後將excel表格轉換成pdf格式進行輸出,我第一次接觸這個需求時,碰到幾個比較棘手的問題,現在一一列出並且提供解決方案。 1:excel轉pdf出現亂碼: 第一次excel轉pdf是成功的,第二次開始後面皆是亂碼,是因為我的pdf轉ex ...
  • #!/bin/bash#Auth:Darius#CentOS_7配置實驗環境eno=`ifconfig|awk '{print $1}'|head -1|awk -F ":" '{print $1}'`file=/etc/sysconfig/network-scripts/ifcfg-$enodir ...
  • 問題: Windows Storage Server 2012 R2 發佈NAS服務,客戶創建用戶和組時報錯,事件查看器系統日誌下報錯Event ID 12288,內容如下: SAM failed to write changes to the database. This is most like ...
  • 1、數據備份:a、mdf是數據文件,資料庫系統的可實時操作/讀取的數據文件,也可作為物理備份文件使用。分離--附加;b、ldf 是日誌文件,用於存儲資料庫的邏輯日誌信息。c、bak是備份文件,是資料庫邏輯備份和增量備份的輸出格式。BAK文件還原的數據更加全面 備份--還原 2、資料庫自動定時備份;刪 ...
  • 占座 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...