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 > delete performance

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-27-12, 04:54
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
delete performance

db2 ese 9.5 fp8 on P/linux
we have a large table that needs to be cleaned all the time
this tables keeps requests for executions and needs to be cleaned if exec is finished
we use delete from batch.message where id in (select id from batch.message where work_id=? fetch first 10000 rows only)
we added the fetch otherwise we get -964 (logfull) and we already have many logfiles for this db
the delete takes about 200 sec
the table has been declared as volatile as the size is changing in size all the time and stats would never be up-to-date

any good idea to speed-up this process ?
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #2 (permalink)  
Old 01-27-12, 07:03
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Write a stored procedure to do the deletes. A cursor WITH HOLD option should be created, but using UR islolation level. Then delete rows that match your criteria (separate delete and not "where current of cursor"). Do commits often to minimize lock contention on the delete (original cursor will stay open if WITH HOLD is used).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 01-27-12, 07:13
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
Thanks Marcus
just a small remark : we have noticed when doing delete from store proc, although using intermediate commit the logfiles are not released - we could see more and more logfiles allocated and finally out of logfiles..
it seems the call .. is seen as 1 uow..
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #4 (permalink)  
Old 01-27-12, 07:28
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
I do not see a point in declaring a cursor.
The delete can be made simpler like

delete from (select * from batch.message where work_id=? fetch first 10000 rows only)

and repeat till SQLCODE is 100.

Interesting observation about logs not being released!

Cheers
Sathy
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #5 (permalink)  
Old 01-27-12, 07:31
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Purpose of declaring cursor is:
  • to minimize lock contention by doing frequent intermediate commits
  • reduce active log size by doing frequent intermediate commits
There should not be a problem with active log size if the stored proc is used with frequent commits, although you will have to prune the archive logs frequently.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #6 (permalink)  
Old 01-27-12, 08:42
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by przytula_guy View Post
we have a large table that needs to be cleaned all the time
...
any good idea to speed-up this process ?
Consider using an MDC, organized by work_id. It would be especially efficient in DB2 9.7 though, where you'd have asynchronous block roll-out and index maintenance.
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