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.