在Informix 12.1版本中如何通过滚动窗口表实线历史数据迁移

1、滚动窗口表rolling window tables介绍

(按时间/大小自动清除表,rolling purge)

Informix12.1版本在间隔分片的基础上增加了滚动窗口表,在实际的应用中,可以用于历史数据清除,不需要人工干预。


通过DDL实现自动摘除分片

基于间隔分片策略

可以指定表上激活的分片个数,当超过分片个数时,最小值的分片将被移走或删除

也可以指定表的大小,当查过指定空间时,最小值的分片将被删除

被摘除的片可用于挂载或者删除掉

分片移动到归档表

非常适合于OEM的应用或者历史数据清除,不需要人工干涉

索引上有相同的操作 (detach or drop),但必须使用本地索引

2、语法

FRAGMENT BY RANGE (<column list>)

    INTERVAL (<value>)

    [ [ROLLING(<integervalue>FRAGMENTS)]

      [LIMIT TO <integervalue>  <SIZEUNIT>] DETACH|DISCARD]

   STORE IN (<dbspacelist> |<function_to_return_dbspacename()>)  ;   

    SIZEUNIT:    [ KB | KiB | MB | MiB | GB| GiB | TB|TiB ]

§通过limit to语句,设置表的最大容量以kb |mb|gb |tb为单位

§通过discard语句,分片将被删除,它的空间将被返回到chunk/dbspace free list

§通过detach语句,分片将被摘除,创建一个新的独立的表

新表的名称将继承原表和表所包含的数据范围的属性

新表名称是source_table_LowVal_HighVal

例如, orders表按月分片,老的分片被摘除之后,将创建以下面的表名命名的表:

• orders_1_2  包含1月份的数据

• orders_2_3  包含2月份的数据

§真正清除不是自动的,必须调用syspurge()

扫描系统表,去查找超过限制的滚动窗口表

不带任何参数

返回删除的分片个数

可以手工调用或者使用系统自带调度器中的purge_tables任务

每天凌晨0:45运行,但可以修改为不同的时间

3、举例:

create table orders

(order_num serial(1001),

order_date date,

customer_num integer not null )

partition by range(order_date) interval(1 units month)

rolling (6 fragments) limit to 20 gb detach

store in (mydbs,rootdbsdbs)

partition prv_partition values < date(’01-01-2010’) inmydbs;

插入数据,分布在7个不同的月份,会自动生成7个分片:

truncate table orders;

insert into orders(order_date,customer_num) values('01-01-2017',1);

insert into orders(order_date,customer_num) values('02-02-2017',2);

insert into orders(order_date,customer_num) values('03-03-2017',3);

insert into orders(order_date,customer_num) values('04-04-2017',4);

insert into orders(order_date,customer_num) values('05-05-2017',5);

insert into orders(order_date,customer_num) values('06-06-2017',6);

insert into orders(order_date,customer_num) values('07-07-2017',7);

4、确认分片数量和每个片上的记录数:

update statistics for table orders;

unload to frag.out selectexprtext,nrows fromsysfragments

where tabid in (select tabid from systables wheretabname='orders’);

catfrag.out

|20.0|

order_date|0.0|

interval(         1) month(9) to month|0.0|

mydbs,rootdbsdbs|0.0|

VALUES< DATE ('01/01/2010' )|0.0|

VALUES>= DATE ('01/01/2017' ) AND VALUES < DATE ('02/01/2017' )|1.0|

VALUES>= DATE ('02/01/2017' ) AND VALUES < DATE ('03/01/2017' )|1.0|

VALUES>= DATE ('03/01/2017' ) AND VALUES < DATE ('04/01/2017' )|1.0|

VALUES>= DATE ('04/01/2017' ) AND VALUES < DATE ('05/01/2017' )|1.0|

VALUES>= DATE ('05/01/2017' ) AND VALUES < DATE ('06/01/2017' )|1.0|

VALUES>= DATE ('06/01/2017' ) AND VALUES < DATE ('07/01/2017' )|1.0|

VALUES >= DATE ('07/01/2017' )AND VALUES < DATE ('08/01/2017' )|1.0|

5、查看任务的缺省定义,保存在sysadmin的ph_task表中

tk_id                37

tk_name              purge_tables 

tk_description       Dailytask to ensure that rolling window tables stay within limits

tk_type              TASK

tk_sequence          5

tk_result_table

tk_create 

tk_dbs               sysadmin

tk_execute           rwt_purge_tables

tk_delete

tk_start_time         00:45:00

tk_stop_time

tk_frequency           100:00:00

tk_next_execution    2018-01-10 00:45:00             #下次的执行时间距离现在的时间太远

tk_total_execution  +  5

tk_total_time        1.502911129527

tk_monday            t

tk_tuesday           t

tk_wednesday         t

tk_thursday          t

tk_friday            t

tk_saturday          t

tk_sunday            t 

tk_attributes        412

tk_group             TABLES

tk_enable            t

tk_priority           0

6、当前的系统时间是130左右,为了看到清除的效果,因此将定时任务的执行时间修改为133

updateph_task settk_start_time='01:33:00' wheretk_id=37

select* from  ph_task  wheretk_id=37

tk_id                37

tk_name              purge_tables

tk_description       Dailytask to ensure that rolling window tables stay within limits

tk_type              TASK

tk_sequence          7

tk_result_table

tk_create

tk_dbs               sysadmin

tk_execute           rwt_purge_tables

tk_delete

tk_start_time        01:33:00

tk_stop_time

tk_frequency           100:00:00

tk_next_execution    2018-01-10 01:33:00

tk_total_executio  6                                #执行次数由5增加到6

7、orders_01_01_2017_02_01_2017是detach之后新生成的

摘除的表:

INFO FOR TABLE >>

Choose a table with the Arrow Keys, orenter a name, then press Return.

----------------------- mydb@demo_on----------- Press CTRL-W for Help --------

orders

orders_01_01_2017+ 

'root'.t1

orders_01_01_2017_02_01_2017



作者:陆川





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章