12c新特性:信息生命周期管理

为了实现数据库中数据移动的信息生命周期管理,可以采用12c中引入的Heat MapAutomatic Data Optimization (ADO)特性。这两个特性是从12cR1中第一次引入,不过之前只能适用于NO-CDB环境,到了release 2版本中则可以适用多租户环境。

使用Heat Map

Heat Map是Oracle Database 12c 中的一个特性,它可以在行级和段级自动跟踪表/分区的使用信息。在行级跟踪数据修改时间并聚合到块级,在段级跟踪修改时间、全表扫描时间和索引查询时间。热图可让你详细了解数据访问方式,以及访问模式随时间变化的情况。

下面这个图为描述热图数据的一种方法,每个方块代表表的一个分区。方块的大小是分区的相对大小,方块的颜色代表根据近期对分区中任意行的访问得出的分区”热”度(即访问的频繁程度)。

通过HEAT_MAP参数来开启这个功能。

1
2
3
4
5
6
7
8
9
sys@ORA122> alter session set container =pdb1;

Session altered.

sys@ORA122> show parameter heat_map;

PARAMETER_NAME TYPE VALUE
------------------------------------------------------------ --------------------------------- -------------------------
heat_map string OFF

开启heat_map,在pdb和cdb级别都可以做修改。都需要修改的话则需要分别在不同的级别下做修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ALTER SYSTEM SET HEAT_MAP = ON;

sys@ORA122> show parameter heat_map;

PARAMETER_NAME TYPE VALUE
------------------------------------------------------------ --------------------------------- --------------------
heat_map string ON

sys@ORA122> conn sys/oracle as sysdba
Connected.

sys@ORA122> show parameter heat_map

PARAMETER_NAME TYPE VALUE
------------------------------------------------------------ --------------------------------- --------------------
heat_map string OFF >>>>====CDB级别仍然是OFF状态

当heat map特性启用以后,所有的访问都会被内存中的tracking模块所跟踪。但是SYSTEM和SYSAUX表空间里的对象不会被跟踪。

这个参数会影响Automatic Data Optimization(ADO)的使用,如果要开启ADO特性,则heat map必须要在系统级别启用。

开启了以后可以通过下列视图来查看热图信息:

  • V$HEAT_MAP_SEGMENT
  • {USER|ALL|DBA}_HEAT_MAP_SEG_HISTOGRAM
  • {USER|ALL|DBA}_HEAT_MAP_SEGMENT
  • {USER|ALL|DBA}_HEATMAP_TOP_OBJECTS
  • {USER|ALL|DBA}_HEATMAP_TOP_TABLESPACES
  • DBMS_HEAT_MAP.BLOCK_HEAT_MAP
  • DBMS_HEAT_MAP.EXTENT_HEAT_MAP
  • DBMS_HEAT_MAP.OBJECT_HEAT_MAP
  • DBMS_HEAT_MAP.SEGMENT_HEAT_MAP
  • DBMS_HEAT_MAP.TABLESPACE_HEAT_MAP
1
2
3
4
5
6
7
8
9
10
11
sys@ORA122> alter session set container=pdb1;

Session altered.

sys@ORA122> create user xb identified by xb;

User created.

sys@ORA122> grant dba to xb;

Grant succeeded.

然后创建一些测试数据,执行几个语句

1
2
3
4
5
6
7
8
9
10
11
12
13
14
drop table t1 purge;
create table t1 (id number,name varchar2(40));

insert into t1
select level ,'name: '||level
from dual
connect by level>=20;

commit;

alter table t1 add constraint pk_t1 primary key (id);

select * from t1;
select * from t1 where id=1;

接下来查询heat map视图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
col OBJECT_NAME for a30
col SUBOBJECT_NAME for a40
SELECT SUBSTR(OBJECT_NAME,1,20) OBJECT_NAME, SUBSTR(SUBOBJECT_NAME,1,20) SUBOBJECT_NAME, TRACK_TIME, SEGMENT_WRITE,
FULL_SCAN, LOOKUP_SCAN FROM V$HEAT_MAP_SEGMENT;

OBJECT_NAME SUBOBJECT_NAME TRACK_TIME SEGMENT_W FULL_SCAN LOOKUP_SC
------------------------------ ---------------------------------------- ------------------- --------- --------- ---------
PK_T1 2019-03-06 13:23:18 NO NO YES
T1 2019-03-06 13:23:18 YES YES NO

SELECT SUBSTR(OBJECT_NAME,1,20) OBJECT_NAME, SUBSTR(SUBOBJECT_NAME,1,20) SUBOBJECT_NAME, SEGMENT_WRITE_TIME,
SEGMENT_READ_TIME, FULL_SCAN, LOOKUP_SCAN FROM USER_HEAT_MAP_SEGMENT;

OBJECT_NAME SUBOBJECT_NAME SEGMENT_WRITE_TIME SEGMENT_READ_TIME FULL_SCAN LOOKUP_SCAN
------------------------------ ---------------------------------------- ------------------- ------------------- ------------------- -------------------
PK_T1 2019-03-06 13:24:47
T1 2019-03-06 13:24:47 2019-03-06 13:24:47

SELECT SUBSTR(OBJECT_NAME,1,20) OBJECT_NAME, SUBSTR(SUBOBJECT_NAME,1,20) SUBOBJECT_NAME, TRACK_TIME, SEGMENT_WRITE, FULL_SCAN,
LOOKUP_SCAN FROM USER_HEAT_MAP_SEG_HISTOGRAM;

OBJECT_NAME SUBOBJECT_NAME TRACK_TIME SEGMENT_W FULL_SCAN LOOKUP_SC
------------------------------ ---------------------------------------- ------------------- --------- --------- ---------
T1 2019-03-06 13:26:22 YES YES NO
PK_T1 2019-03-06 13:26:22 NO NO YES

除了上面这些视图以外, 通过DBMS_HEAT_MAP包可以获得相关信息

1
2
3
4
5
6
7
8
9
10
11
12
xb@PDB1> 
SELECT owner,
segment_name,
segment_type,
tablespace_name,
segment_size
FROM TABLE(DBMS_HEAT_MAP.object_heat_map('XB','T1'));

OWNER SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME SEGMENT_SIZE
---------- -------------------- ------------------------------------------------------------ -------------------- ------------
XB T1 TABLE USERS 65536
XB PK_T1 INDEX USERS 65536

通过这些信息能很方便的查到哪些对象被访问的最频繁,最近访问的是哪些。

自动数据优化 (ADO)

开启heat map之后,根据各个数据段的不同使用情况,你可以通过ADO来实现对数据的移动、压缩。

ADO策略管理

当使用CREATE/ALTER TABLE时可以从行、段以及表空间级别制定ADO策略。

制定了ADO策略以后,能自动化实现不同数据层的数据移动,这些策略能让你针对不同的数据层制定不同的压缩方式,也能配置何时去自动做这些操作。

段级别的策略只会自动执行一次,在成功执行完毕以后就会变成disable状态,你可以手动重新启用。而行级别的策略则不会变成disable。

ADO策略的作用域可以使用关键字group、row或segment为一组相关对象或在段或行级别指定,压缩与组策略默认的对应关系如下

  • COMPRESS ADVANCED对应索引的标准压缩和LOB段的低级别压缩
  • COMPRESS FOR QUERY LOW/QUERY HIGH对应索引的标准压缩和LOB段的中等压缩
  • COMPRESS FOR ARCHIVE LOW/ARCHIVE HIGH对应索引的标准压缩和LOB段的高级压缩

创建ADO策略的表

新建三个表空间,分别代表三个不同的数据层

1
2
3
create tablespace tbs1 datafile size 1M autoexten on;
create tablespace tbs2 datafile size 1M autoexten on;
create tablespace tbs3 datafile size 1M autoexten on;

创建分区表,每个分区平均存储在不同的表空间,但是给部分分区设定ADO策略,满足条件后转移到别的表空间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
drop table t1 purge;

create table t1(
t1_id number,
t1_date date
)
partition by range(t1_date)
(
partition t1_date_p1 values less than (to_date('20180601', 'yyyymmdd')) tablespace tbs1,
partition t1_date_p2 values less than (to_date('20180701', 'yyyymmdd')) tablespace tbs1,
partition t1_date_p3 values less than (to_date('20180901', 'yyyymmdd')) tablespace tbs2,
partition t1_date_p4 values less than (to_date('20181201', 'yyyymmdd')) tablespace tbs2,
partition t1_date_p5 values less than (to_date('20190101', 'yyyymmdd')) tablespace tbs3,
partition t1_date_p6 values less than (to_date('20190301', 'yyyymmdd')) tablespace tbs3
);

alter table t1 modify partition t1_date_p3 ilm add policy tier to tbs1 read only segment after 6 months of no access;
alter table t1 modify partition t1_date_p4 ilm add policy tier to tbs1 read only segment after 6 months of no access;
alter table t1 modify partition t1_date_p5 ilm add policy tier to tbs2 read only segment after 3 months of no access;
alter table t1 modify partition t1_date_p6 ilm add policy tier to tbs2 read only segment after 3 months of no access;
alter table t1 ilm add policy row store compress basic segment after 3 months of no access;

查看已存在的策略

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
column policy_name format a20
column object_owner format a15
column object_name format a15
column subobject_name format a20
select policy_name,
object_owner,
object_name,
subobject_name,
object_type,
inherited_from,
enabled,
deleted
from user_ilmobjects;

POLICY_NAME OBJECT_OWNER OBJECT_NAME SUBOBJECT_NAME OBJECT_TYPE INHERITED_FROM ENABLED DELETED
-------------------- --------------- --------------- -------------------- ------------------------------------------------------ ------------------------------------------------------------ ---------- ---------
P6 XB T1 T1_DATE_P3 TABLE PARTITION POLICY NOT INHERITED YES NO
P7 XB T1 T1_DATE_P4 TABLE PARTITION POLICY NOT INHERITED YES NO
P8 XB T1 T1_DATE_P5 TABLE PARTITION POLICY NOT INHERITED YES NO
P9 XB T1 T1_DATE_P6 TABLE PARTITION POLICY NOT INHERITED YES NO
P10 XB T1 TABLE POLICY NOT INHERITED YES NO
P10 XB T1 T1_DATE_P1 TABLE PARTITION TABLE YES NO
P10 XB T1 T1_DATE_P2 TABLE PARTITION TABLE YES NO
P10 XB T1 T1_DATE_P3 TABLE PARTITION TABLE YES NO
P10 XB T1 T1_DATE_P4 TABLE PARTITION TABLE YES NO
P10 XB T1 T1_DATE_P5 TABLE PARTITION TABLE YES NO
P10 XB T1 T1_DATE_P6 TABLE PARTITION TABLE YES NO

禁用和删除ADO策略

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* 禁用(删除)表中的某个ADO策略*/
ALTER TABLE t1 ILM DISABLE POLICY P10;
ALTER TABLE t1 ILM DELETE POLICY P10;

/* 禁用(删除)表中的全部ADO策略 */
ALTER TABLE t1 ILM DISABLE_ALL;
ALTER TABLE t1 ILM DELETE_ALL;

/* 禁用(删除)分区中的某个ADO策略 */
ALTER TABLE t1 MODIFY PARTITION t1_date_p3 ILM DISABLE POLICY P6;
ALTER TABLE t1 MODIFY PARTITION t1_date_p3 ILM DELETE POLICY P6;

/* 禁用(删除)分区中的全部ADO策略 */
ALTER TABLE t1 MODIFY PARTITION t1_date_p4 ILM DISABLE_all;
ALTER TABLE t1 MODIFY PARTITION t1_date_p4 ILM DELETE_ALL;

指定段级别压缩和存储层

1
2
3
4
5
6
7
8
9
10
11
12
13
段级别压缩目前只试用于EXADATA

ALTER TABLE t1 ILM ADD POLICY
COMPRESS FOR ARCHIVE HIGH SEGMENT
AFTER 6 MONTHS OF NO MODIFICATION;
ALTER TABLE t1 ILM ADD POLICY
*
ERROR at line 1:
ORA-64307: Exadata Hybrid Columnar Compression is not supported for tablespaces on this storage type

/* 增加存储层策略 */
ALTER TABLE sales_ado ILM ADD POLICY
TIER TO my_low_cost_tablespace;

指定行级别的压缩层

HCC只适用EXADATA

1
2
3
4
5
6
7
8
9
10
11
12
13
14
ALTER TABLE t1 
ILM ADD POLICY COLUMN STORE COMPRESS FOR QUERY ROW
AFTER 30 DAYS OF NO MODIFICATION;
ALTER TABLE t1
*
ERROR at line 1:
ORA-64307: Exadata Hybrid Columnar Compression is not supported for tablespaces on this storage type


ALTER TABLE t1
ILM ADD POLICY ROW STORE COMPRESS ADVANCED ROW
AFTER 60 DAYS OF NO MODIFICATION;

Table altered.

ADO参数

查询有哪些参数

1
2
3
4
5
6
7
8
9
10
11
12
SELECT NAME, VALUE FROM DBA_ILMPARAMETERS;

NAME VALUE
---------------------------------------------------------------------- ----------
ENABLED 1
RETENTION TIME 30
JOB LIMIT 2
EXECUTION MODE 2
EXECUTION INTERVAL 15
TBS PERCENT USED 85
TBS PERCENT FREE 25
POLICY TIME 0

可以通过CUSTOMIZE_ILM过程自定义ADO参数

1
2
3
4
5
6
7
8
9
10
BEGIN
DBMS_ILM_ADMIN.CUSTOMIZE_ILM(DBMS_ILM_ADMIN.TBS_PERCENT_USED, 85);
DBMS_ILM_ADMIN.CUSTOMIZE_ILM(DBMS_ILM_ADMIN.TBS_PERCENT_FREE, 25);
END;
/

SQL> BEGIN
DBMS_ILM_ADMIN.CUSTOMIZE_ILM(DBMS_ILM_ADMIN.ABS_JOBLIMIT, 10);
END;
/

12c新特性:信息生命周期管理
https://www.xbdba.com/2019/03/06/12c-information-lifecycle-management/
作者
xbdba
发布于
2019年3月6日
许可协议