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 > Big (for me) row deletion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-28-11, 10:41
hazy_dba hazy_dba is offline
Registered User
 
Join Date: Dec 2009
Posts: 40
Big (for me) row deletion

DB2 version
DB2 v8.1.16.429 - FixPak 16
Windows server.

I have got a table that has got well over 300 million rows in it.

We are not sure yet why all the records got added, I suspect poorly written code somewhere. They were added over a few days and we didn't think it was going to keep happening so the archive logs got pruned a few times before we realised we were in trouble.

I now have to delete most of those three hundred million records and I would like some advice please. I have put letters against the various bits as I know I am asking a lot and it will make it easier to match answers.

(A) I believe I will have to write a stored procedure to do the work for me and delete a thousand records at a time, commit that and repeat until finished. Does this sound reasonable?

(B) The database is going to generate a lot of archive logs while this is happening. I'm not sure we are going to have the space for them all, so my plan was to schedule something in the background to delete them to keep within the disk resource I have available. As long as I do an offline backup first, is this going to be an issue? Perhaps I should just delete as many as archive logs I can afford to have without pruning, do another offline backup, rinse and repeat.

(C) Once the deletion has completed I need to consider how I am going shrink the database back down to it's usual size. My boss suggested copying everything I want to keep from the table into a new table, truncate the original table then copy everything back into it. What do you think? Is there a better way that you think I should use?

(D) I also need to consider the indexes for that table as well don't I? Would a truncate and re-import rebuild them ok, or should I do something else as well?

(E) What have I missed out? What else would you do please?

Thank you for looking!

Edit:
Forgot to say. I don't believe what caused the issue it still happening, and any plan I use to fix live will be run on a test copy first.

Last edited by hazy_dba; 03-28-11 at 10:42. Reason: Forgot something
Reply With Quote
  #2 (permalink)  
Old 03-28-11, 11:00
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Probably the simplest way to do what you want without having to go through all of the archive log watching is this:

1) Create a "New" table just like the old one
2) LOAD the data you want to keep from the old table into the new one
3) Drop the old table (this will drop the indexes and FKs to and from the old table)
4) rename the new table to the old name
5) create the indexes for the new table, and any FK that were dropped when the old table was dropped.
6) do runstats on the new table.

Andy
Reply With Quote
  #3 (permalink)  
Old 03-29-11, 05:06
hazy_dba hazy_dba is offline
Registered User
 
Join Date: Dec 2009
Posts: 40
Thanks Andy. I appreciate the clear instructions.
Reply With Quote
  #4 (permalink)  
Old 03-29-11, 06:39
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Quote:
Originally Posted by hazy_dba View Post
(B) The database is going to generate a lot of archive logs while this is happening. I'm not sure we are going to have the space for them all, so my plan was to schedule something in the background to delete them to keep within the disk resource I have available. As long as I do an offline backup first, is this going to be an issue? Perhaps I should just delete as many as archive logs I can afford to have without pruning, do another offline backup, rinse and repeat.
Whatever you do, do not delete archive log files by hand. EVER! archive log files are objects managed by DB2 and DB2 should always be able to reach them.
Obviously you've got the space to let a table grow that big so I'd (temporary) redirect my logs to another disk or some USB attached device, as long as you do not delete.
When all this is over you can restore all the original locations for your archive logs.
Reply With Quote
  #5 (permalink)  
Old 03-29-11, 09:06
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
There is a missing step.

7) Rebind any packages that use the table.

Andy
Reply With Quote
  #6 (permalink)  
Old 04-05-11, 05:37
hazy_dba hazy_dba is offline
Registered User
 
Join Date: Dec 2009
Posts: 40
I have run through the seven step plan (there are no packages for the table, I checked by querying SYSCAT.PACKAGEDEP) and everything has worked on my duplicate TEST database.

Thank you all again for the support.


Quote:
Originally Posted by dr_te_z View Post
Whatever you do, do not delete archive log files by hand. EVER! archive log files are objects managed by DB2 and DB2 should always be able to reach them.
Obviously you've got the space to let a table grow that big so I'd (temporary) redirect my logs to another disk or some USB attached device, as long as you do not delete.
When all this is over you can restore all the original locations for your archive logs.
I appreciate my original post may have sounded a bit cavalier regarding archive logs.

Could you provide me a bit more info on your archive logs quote please.

Ignoring my original plan as a dumb idea. You say not to delete them by hand - I take it you mean don't select a load of them from within Windows explorer and hit the delete button?

It's ok to prune logs with "DB2 PRUNE LOGFILE PRIOR TO ..." ?

I thought archive logs were only used for rolling forward after a database restore? So if I have them backed up to tape, I can delete them from the server and restore them back before using them?

Would they be used in a crash as well?
Reply With Quote
  #7 (permalink)  
Old 04-05-11, 06:03
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Quote:
Originally Posted by hazy_dba View Post
It's ok to prune logs with "DB2 PRUNE LOGFILE PRIOR TO ..."
Yes, that is the way
Quote:
Originally Posted by hazy_dba View Post
I thought archive logs were only used for rolling forward after a database restore? So if I have them backed up to tape, I can delete them from the server and restore them back before using them?
Correct.
Quote:
Originally Posted by hazy_dba View Post
Would they be used in a crash as well?
No, crash recovery uses active logs only.
Reply With Quote
  #8 (permalink)  
Old 04-05-11, 07:25
nvk@vhv nvk@vhv is offline
Registered User
 
Join Date: Jan 2010
Posts: 294
Quote:
Originally Posted by dr_te_z View Post
No, crash recovery uses active logs only.
Unless you use Infinite logging.
Reply With Quote
  #9 (permalink)  
Old 04-05-11, 08:20
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Quote:
Originally Posted by dr_te_z View Post
No, crash recovery uses active logs only.
Quote:
Originally Posted by nvk@vhv
Unless you use Infinite logging.
I am missing something obvious here.

What if a older transaction (which is no more in active logs) is in the bufferpool but has not been written to the disk?

Are there other assumptions (softmax, etc) ?
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #10 (permalink)  
Old 04-05-11, 08:31
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
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