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 > deleting large number of rows in a table that has 20 child tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-23-11, 14:13
jagdis_vishnu jagdis_vishnu is offline
Registered User
 
Join Date: Aug 2011
Posts: 9
deleting large number of rows in a table that has 20 child tables

Hi there,

Thanks to forum for everything.
I have a problem here for ur valuable response,


I have a table with almost one million rows, the table has 21 child tables. I need to delete two lac rows from the master table. Is there any solution, so that I dont face any transaction log full error???

thank you.
Reply With Quote
  #2 (permalink)  
Old 08-23-11, 14:17
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Write a stored procedure with a cursor on the main parent table, and then commit after each logical unit of work (which includes deleting all the child tables for a parent). You will need to define the cursor WITH HOLD so it will not close when you do a commit.
__________________
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 08-24-11, 14:02
jagdis_vishnu jagdis_vishnu is offline
Registered User
 
Join Date: Aug 2011
Posts: 9
Quote:
Originally Posted by Marcus_A View Post
Write a stored procedure with a cursor on the main parent table, and then commit after each logical unit of work (which includes deleting all the child tables for a parent). You will need to define the cursor WITH HOLD so it will not close when you do a commit.
thank you, but can u plz elaborate it?
Reply With Quote
  #4 (permalink)  
Old 08-24-11, 21:38
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by jagdis_vishnu View Post
thank you, but can u plz elaborate it?
Actaully writing such a stored procedure is a fee-based activity IMO. If you or your company are interested, then send me a private message.
__________________
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
  #5 (permalink)  
Old 08-25-11, 01:46
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Try using the search button. This question has been asked and answered dozens of times. If you search hard enough you will find an example.

If you have difficulties when creating stored procedure, come back to the forum.

Or, of course you have the option to PM Marcus.
Reply With Quote
  #6 (permalink)  
Old 08-25-11, 02:07
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
that is really a good idea ..
...is a fee-based activity IMO. If you or your company are interested, then send me a private message..
I will use it a lot in the future.. in this forum anyhow..
__________________
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
  #7 (permalink)  
Old 08-25-11, 02:10
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Quote:
Originally Posted by sathyaram_s View Post
Or, of course you have the option to PM Marcus.
..... or Guy
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #8 (permalink)  
Old 08-25-11, 06:56
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
I will also provide forum searches for people (on a fee basis) for those who don't have time to do it themselves.
__________________
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
  #9 (permalink)  
Old 08-25-11, 07:05
Naval29 Naval29 is offline
Registered User
 
Join Date: Apr 2008
Posts: 9
If it is a one time job .. then this could be a idea. Select rows in chunks
and delete them again and again.

delete form (select * from table name fetch first 15000 rows only).

you can right a small shell script also.

Thanks
Naval K
Reply With Quote
  #10 (permalink)  
Old 08-25-11, 08:06
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by Naval29 View Post
If it is a one time job .. then this could be a idea. Select rows in chunks
and delete them again and again.

delete form (select * from table name fetch first 15000 rows only).

you can right a small shell script also.

Thanks
Naval K
The reason why I recommended a stored procedure is that the OP said there was one parent table with 21 child tables, and I assume that the logical UOW integrety needs to be maintained. A properly written SP will also have the following additional advantages:
  • not filling up the transaction log since there would be intermediate commits at the logical UOW level
  • doing intermediate commits reduces lock contention during the deletes, since only those rows deleted since the last commit point will be locked
__________________
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
  #11 (permalink)  
Old 08-28-11, 11:20
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
Quote:
Originally Posted by Naval29 View Post
If it is a one time job .. then this could be a idea. Select rows in chunks
and delete them again and again.

delete form (select * from table name fetch first 15000 rows only).

you can right a small shell script also.

Thanks
Naval K

This is second best option to SP. I had used it for all one time jobs. Some daily jobs run via SP.

Make sure the chunk is small enough to let the database keep going easy.

One of my prune job using shell script took 11 hours on a very busy gaming database.

A template SP can be provided if needed !!


Regards

DBFinder
Reply With Quote
Reply

Tags
db2

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