We have a DB2-table in a datawarehouse. It contains history for 24 months. Every month contains between 10 and 12 million rows. Monthly the oldest month in the table is cleaned. So , november 2008 the data from november 2006 is cleaned, deleted.
The table is partitoned, but we are not allowed to use rotating partitions in prodcutions.
How do we clean the table?
First we unload the whole table and then we reload the table with all the data without the month that must be deleted. This takes a long time.
Does anyone have a better solution, for instance just enptying the oldest partition? How do I do that?
Joined: 22 Apr 2006 Posts: 6258 Location: Mumbai, India
You can consider REORG as well.
REORG utility reorganizes a table space or index to improve access performance and reclaim fragmented space. In addition, the utility can reorganize a single partition of either a partitioned index or a partitioned table space. You can specify the degree of access to your data during reorganization. If you specify REORG UNLOAD ONLY, the data is unloaded in a format that is acceptable to the LOAD utility of the same DB2 subsystem.
The table is partitioned on month-key. When I load an empty file to the oldest partition, how do I get to know the partition number of the oldest partition? And we als wanno know how many rows have been deleted in that oldest partition. The data of the oldest partition can be thrown away, it doesn't have to be archived on another medium
First check it out. whether it is a table-partioned or index partitioned.
how do I get to know the partition number of the oldest partition?
If its table partitioned, check the ddl of table.
If it is index partioned, check the ddl of the index for that table.
By this this method you will know the which partition is for which month, since you know for which month needs to be deleted. or otherwise you have to see it in the catalog table.
And we als wanno know how many rows have been deleted in that oldest partition.
Just put a query with count(*) and in the where clause MONTH & YEAR. Before removing data from the partition.
The data of the oldest partition can be thrown away, it doesn't have to be archived on another medium
Since the data is not required. You don't have to UNLOAD or take IC, but its good to have a back-up of the partition when deleting from production.
Since you know the partition number now from DDL of the table or index. You can just load that particular partition with an empty file.