If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Stored procedure in DB2 UDB

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-26-08, 09:41
kveaswaran kveaswaran is offline
Registered User
 
Join Date: Jun 2008
Posts: 3
Stored procedure in DB2 UDB

Hi,

I'm working on db2 8.2 FP10 and OS is Linux 2.6.9-42.ELsmp.

We have written one stored procedure which will Archive the data from Transaction table to history table will work based on date criteria.
The procedure was written on dynamic sql.

We have a transaction table having 1.2 Million records perday. It has around 40 days of records.(50 Million Total)

History table is having 388 Million records. The Archival movement process is like the following.

First Step: Create Global temporary table similar to out transaction table; It is an one time activity per one day archival.

Second Step: Create an Unique Index for the GTT similar to the Primary key of Transaction table. It is one time activity per one day archival.

Third Step: Select data from Transaction table and insert the data into Global Temporary table.
(insert into GTT select * from trantable fetch first 50000 rows only; It is going to repeat until the records moved for that date)

Fourth Step:Based on Global temporary table it will insert into History table.
(Insert into HistTable select * from GTT).

Fifth Step: Based on Global temporary table it will deleted from Transaction table.(Delete from Trantable where keycolums in
(select keycolumns from GTT));

The main problem we have is, insert into History tables is taking longer time when compared to other steps.The total process for 50000 records
is taking 10 to 20 minutes.Among that insert into history table taking 90% time.Table statistics are upto date.

Instead of using the above process is there any other process to improve my archival process.

Ours is a OLTP and 24 X 7 support system.

Please give us your suggestions.

Thanks,
ekv
Reply With Quote
  #2 (permalink)  
Old 01-02-09, 08:51
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What is the DDL for the Transaction and History tables? Please include all indexes and FKs.

Andy
Reply With Quote
  #3 (permalink)  
Old 01-02-09, 10:37
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
how about instead of GTT use unload and load? You could do for entire day in one time through, instead of running 50,000 iteratively until finished. Would bring your costs down by quite a bit. Of course, your delete would have to be done in another manner.
Reply With Quote
  #4 (permalink)  
Old 01-02-09, 11:57
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
There is no "unload" in DB2 for LUW V8. You must mean "export".

The OP probable broke it up in 50000 chunks to make the deletes go faster.

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On