寫在前面 Oracle 12c 可以通過熱圖和自動數據優化(ADO)實現信息生命周期的管理(ILM),上篇介紹了熱圖,本篇將對自動數據優化進行展開,通過熱圖和自動數據優化,最終實現信息生命周期管理。 1 自動數據優化工作流程 使用自動數據優化,必須先在系統級別啟用熱圖,通過修改初始化參數heat_m ...
寫在前面
Oracle 12c 可以通過熱圖和自動數據優化(ADO)實現信息生命周期的管理(ILM),上篇介紹了熱圖,本篇將對自動數據優化進行展開,通過熱圖和自動數據優化,最終實現信息生命周期管理。
1 自動數據優化工作流程
使用自動數據優化,必須先在系統級別啟用熱圖,通過修改初始化參數heat_map即可,啟用熱圖後,資料庫會自動在段上進行熱圖統計信息的收集,可通過數據字典視圖查看熱圖相關的信息,具體可參考:Oracle 12c Heat Map 熱圖 。
2 創建策略
策略可以在執行create table或alter table時在行、段、表空間級別進行創建,在滿足指定的策略時可以進行數據的自動壓縮和移動,從而完成數據的歸檔。
2.1 策略創建語法
通過下麵的語法結構我們可以知道以下內容。
1)ADO主要在兩個層面實現數據的優化,分別為
- 壓縮
- 存儲分層
2)壓縮的類型
- ROW STORE COMPRESS BASIC(Bisic壓縮)
- ROW STORE COMPRESS ADVCANCED(Advanced壓縮)
- COLUMN STORE COMPRESS FOR QUERY LOW/HIGH(HCC Query壓縮)
- COLUMN STORE COMPRESS FOR ArCHIVE LOW/HIGH(HCC Archive壓縮)
3)壓縮作用域
- Tablespace 表空間:預設設置存儲對象
- Group 組:目標對象的索引和LOB
- Segment 段:表、分區和子分區
- Row 行:數據行
4)訪問模式
- NO ACESS:無INSERT、DELETE、UPDATE、SELECT
- NO MODIFICATION:無INSERT、DELETE、UPDATE
- CREATION:創建段
5)啟動時機
- DAY
- MONTH
- YEAR
ilm_clause::=
ilm_policy_clause::=
ilm_compression_policy::=
table_compression::=
ilm_tiering_policy::=
ilm_time_period::=
2.2 示例:演示壓縮
0)查看heat_map初始化參數配置
ALEN@PROD2> show parameter heat_map
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
heat_map string ON
1)創建測試表,可以看出,數據行為259418,表沒有被壓縮,表占用空間為11534336 BYTES
ALEN@PROD2> create table sales_ado as select * from sales;
Table created.
ALEN@PROD2> select count(1) from sales_ado;
COUNT(1)
----------
259418
ALEN@PROD2> select t.compression,t.compress_for from user_tables t where t.table_name='SALES_ADO';
COMPRESS COMPRESS_FOR
-------- ------------------------------
DISABLED
ALEN@PROD2> select t.bytes from user_segments t where t.segment_name='SALES_ADO';
BYTES
----------
11534336
2)創建策略
ALEN@PROD2> alter table sales_ado ilm add policy row store compress advanced segment after 30 days of no modification;
Table altered.
3)查看創建的策略
ALEN@PROD2> col policy_name for a10
ALEN@PROD2> col policy_type for a30
ALEN@PROD2> select policy_name,policy_type,enabled,deleted from user_ilmpolicies;
POLICY_NAM POLICY_TYPE ENABLED DELETED
---------- ------------------------------ ------- -------
P102 DATA MOVEMENT YES NO
4)查看策略對象
ALEN@PROD2> col object_owner for a10
ALEN@PROD2> col object_name for a20
ALEN@PROD2> set linesize 200
ALEN@PROD2> select policy_name,object_owner,object_name,object_type,inherited_from,enabled,deleted from user_ilmobjects;
POLICY_NAM OBJECT_OWN OBJECT_NAME OBJECT_TYPE INHERITED_FROM ENA DEL
---------- ---------- -------------------- ------------------ -------------------- --- ---
P102 ALEN SALES_ADO TABLE POLICY NOT INHERITED YES NO
5)查看熱圖信息
ALEN@PROD2> select object_name,track_time,segment_write,full_scan,lookup_scan from user_heat_map_seg_histogram where object_name='SALES_ADO';
OBJECT_NAME TRACK_TIME SEG FUL LOO
-------------------- ------------------- --- --- ---
SALES_ADO 2020-05-26 18:59:53 NO YES NO
ALEN@PROD2> select object_name,segment_write_time,segment_read_time,full_scan,lookup_scan from user_heat_map_segment where object_name='SALES_ADO';
OBJECT_NAME SEGMENT_WRITE_TIME SEGMENT_READ_TIME FULL_SCAN LOOKUP_SCAN
-------------------- ------------------- ------------------- ------------------- -------------------
SALES_ADO 2020-05-26 19:01:14
6)因為策略是30天內沒有修改的話,就啟用高級壓縮,下麵進行模擬,將時間向前推33天
SYS@PROD2> exec dbms_ilm_admin.set_heat_map_table('ALEN','SALES_ADO','',sysdate-33,2);
PL/SQL procedure successfully completed.
7)再次查看熱圖信息,可以看出 2020-04-23之後沒有對錶做修改
ALEN@PROD2> select object_name,track_time,segment_write,full_scan,lookup_scan from user_heat_map_seg_histogram where object_name='SALES_ADO';
OBJECT_NAME TRACK_TIME SEG FUL LOO
-------------------- ------------------- --- --- ---
SALES_ADO 2020-05-26 19:06:38 NO YES NO
SALES_ADO 2020-04-23 19:06:03 NO NO NO
ALEN@PROD2> select object_name,segment_write_time,segment_read_time,full_scan,lookup_scan from user_heat_map_segment where object_name='SALES_ADO';
OBJECT_NAME SEGMENT_WRITE_TIME SEGMENT_READ_TIME FULL_SCAN LOOKUP_SCAN
-------------------- ------------------- ------------------- ------------------- -------------------
SALES_ADO 2020-04-23 19:06:03 2020-05-26 19:06:55
8)通過第7步可知,30天內對錶沒有進行修改操作,那麼按照策略,會啟用壓縮,但策略的執行,需要對應的視窗,或時間間隔,下麵進行手工觸發策略
ALEN@PROD2> set serveroutput on
ALEN@PROD2> declare
v_taskid number;
begin
dbms_ilm.execute_ilm(v_taskid,dbms_ilm.scope_schema,dbms_ilm.ilm_execution_offline);
dbms_output.put_line('Task ID is '||v_taskid);
end;
/
Task ID is 63
PL/SQL procedure successfully completed.
9)查看任務的執行情況,可以看出任務執行完成
ALEN@PROD2> select task_id,state,creation_time +0 ct,start_time+0 st,completion_time+0 dt from user_ilmtasks where task_id=63;
TASK_ID STATE CT ST DT
---------- --------- ------------------- ------------------- -------------------
63 COMPLETED 2020-05-26 19:12:44 2020-05-26 19:12:44 2020-05-26 19:12:46
ALEN@PROD2> select task_id,policy_name,object_name,object_type,SELECTED_FOR_EXECUTION,job_name from user_ilmevaluationdetails;
TASK_ID POLICY_NAM OBJECT_NAME OBJECT_TYPE SELECTED_FOR_EXECUTION JOB_NAME
---------- ---------- -------------------- ------------------ ---------------------------------------- ----------
63 P102 SALES_ADO TABLE SELECTED FOR EXECUTION ILMJOB608
10)檢查策略執行後,表是否壓縮,以及壓縮比率
ALEN@PROD2> select t.compression,t.compress_for from user_tables t where t.table_name='SALES_ADO';
COMPRESS COMPRESS_FOR
-------- ------------------------------
ENABLED ADVANCED
ALEN@PROD2> select t.bytes from user_segments t where t.segment_name='SALES_ADO';
BYTES
----------
4194304
可以看出,執行策略後,表進行了高級壓縮,4194304/11534336 = 0.36 差不多壓縮到原來的三分之一。
2.3 示例:演示存儲分層
1)創建表空間,分別用於存放數據以及歸檔數據
SYS@PROD2> create tablespace ts_data datafile '/u01/app/oracle/oradata/PROD2/ts_data01.dbf' size 13M;
Tablespace created.
SYS@PROD2> create tablespace ts_low_store datafile '/u01/app/oracle/oradata/PROD2/ts_low01.dbf' size 50M;
Tablespace created.
2)創建測試表,表段占用空間為11M,占用ts_data表空間的85%
ALEN@PROD2> create table sales_ts_ado tablespace ts_data as select * from sales;
Table created.
ALEN@PROD2> select t.compression,t.compress_for,t.tablespace_name from user_tables t where t.table_name='SALES_TS_ADO';
COMPRESS COMPRESS_FOR TABLESPACE_NAME
-------- ------------------------------ ------------------------------
DISABLED TS_DATA
ALEN@PROD2> select sum(t.bytes)/1024/1024 from user_segments t where t.segment_name='SALES_TS_ADO';
SUM(T.BYTES)/1024/1024
----------------------
11
3)策略預設參數是表空間使用百分比TBS PERCENT USED達到85時,會進行數據移動,這裡為了實驗的目的,修改該值為80
SYS@PROD2> exec dbms_ilm_admin.customize_ilm(8,80);
PL/SQL procedure successfully completed.
4)創建存儲分層策略,當表空間使用達到80%時,即會進行數據的移動
ALEN@PROD2> alter table sales_ts_ado ilm add policy tier to ts_low_store;
Table altered.
5)查看策略
ALEN@PROD2> select policy_name,object_owner,object_name,object_type,inherited_from,enabled,deleted from user_ilmobjects;
POLICY_NAM OBJECT_OWN OBJECT_NAME OBJECT_TYPE INHERITED_FROM ENA DEL
---------- ---------- -------------------- ------------------ -------------------- --- ---
P102 ALEN SALES_ADO TABLE POLICY NOT INHERITED NO NO
P142 ALEN SALES_TS_ADO TABLE POLICY NOT INHERITED YES NO
6)手工觸發策略
ALEN@PROD2> declare
v_taskid number;
begin
dbms_ilm.execute_ilm(v_taskid,dbms_ilm.scope_schema,dbms_ilm.ilm_execution_offline);
dbms_output.put_line('Task ID is '||v_taskid);
end;
/
Task ID is 84
PL/SQL procedure successfully completed.
7)查看任務執行情況,驗證策略執行結果
ALEN@PROD2> select task_id,state,creation_time +0 ct,start_time+0 st,completion_time+0 dt from user_ilmtasks where task_id=84;
TASK_ID STATE CT ST DT
---------- --------- ------------------- ------------------- -------------------
84 COMPLETED 2020-05-26 20:25:19 2020-05-26 20:25:19 2020-05-26 20:25:21
ALEN@PROD2> select t.compression,t.compress_for,t.tablespace_name from user_tables t where t.table_name='SALES_TS_ADO';
COMPRESS COMPRESS_FOR TABLESPACE_NAME
-------- ------------------------------ ------------------------------
DISABLED TS_LOW_STORE
可以看到,執行策略後,表段對應的表空間由TS_DATA移到了TS_LOW_STORE,從而自動完成了數據的存儲分層移動。
3 管理策略
3.1 禁用/啟用策略
ALEN@PROD2> alter table sales_ado ilm disable policy P102;
Table altered.
ALEN@PROD2> alter table sales_ado ilm enable policy P102;
Table altered.
3.2 刪除策略
ALEN@PROD2> alter table sales_ado ilm delete policy P102;
Table altered.
3.3 管理ADO參數
1)查看ADO參數
ALEN@PROD2> select * from dba_ilmparameters;
NAME VALUE
------------------------------ ----------
ENABLED 1
RETENTION TIME 30
JOB LIMIT 2
EXECUTION MODE 2
EXECUTION INTERVAL 15
TBS PERCENT USED 80
TBS PERCENT FREE 25
POLICY TIME 1
8 rows selected.
2)修改參數,使用dbms_ilm_admin.customize_ilm
ALEN@PROD2> conn / as sysdba
Connected.
SYS@PROD2> exec dbms_ilm_admin.customize_ilm(parameter =>11 , value => 0);
PL/SQL procedure successfully completed.
4 監控策略
策略的監控主要通過數據字典視圖,分別如下:
1)dba / user_ilmdatamovementpolicies
展示和ILM策略相關的數據移動信息。
2)dba / user_ilmtasks
展示ILM執行的任務信息。
3)dba / user_ilmevaluationdetails
展示ILM任務的評估信息。
4)dba / user_ilmobjects
展示策略和對象信息。
5)dba / user_ilmpolicies
展示策略信息。
6)dba / user_ilmresults
展示數據移動相關的作業信息。
7)dba_ilmparameters
展示ADO相關的參數信息。
以上就是自動數據優化相關的介紹和演示。