Truncating table in DB2



Surprised!! How come DB2 blog in Oracle Arena?

Well just a command I want to introduce which has helped a lot to my DB2 DBA’s
How to truncate a table in DB2?

This was the question on everyone’s mind in crisis time

Table was sizing almost over 10GB growing continuously; generating transaction logs (same as our archive-log in our oracle) 

Rows Deletion in turn added fire in the storm, causing huge number of transaction logs with mount point nearing to panic level threshold

Just a thought came in the mind to ask DB2 DBA to truncate the table, being core DBA support no table level operations were known


After some Google Tour & IBM official website surfing we found this …

db2 "load from /dev/null of del replace into <owner>.<table_name> nonrecoverable"

Quite long command to remember!!

Here is what we have done...

#db2 connect to QAMSDB
   Database Connection Information
 Database server        = DB2/AIX64 9.7.4
 SQL authorization ID   = LDAP
 Local database alias   = QAMSDB

#db2 "load from /dev/null of del replace into QAMS.QAMS_PM_ERR_LOG nonrecoverable"

SQL3501W  The table space(s) in which the table resides will not be placed in
backup pending state since forward recovery is disabled for the database.

SQL3109N  The utility is beginning to load data from file "/dev/null".

SQL3500W  The utility is beginning the "LOAD" phase at time "01/11/2013
16:53:59.639695".

SQL3519W  Begin Load Consistency Point. Input record count = "0".

SQL3520W  Load Consistency Point was successful.

SQL3110N  The utility has completed processing.  "0" rows were read from the
input file.

SQL3519W  Begin Load Consistency Point. Input record count = "0".

SQL3520W  Load Consistency Point was successful.

SQL3515W  The utility has finished the "LOAD" phase at time "01/11/2013
16:54:06.734245".

SQL3500W  The utility is beginning the "BUILD" phase at time "01/11/2013
16:54:06.734591".

SQL3213I  The indexing mode is "REBUILD".

SQL3515W  The utility has finished the "BUILD" phase at time "01/11/2013
16:54:07.253702".


Number of rows read         = 0
Number of rows skipped      = 0
Number of rows loaded       = 0
Number of rows rejected     = 0
Number of rows deleted      = 0
Number of rows committed    = 0

#db2 "select count(*) from QAMS.QAMS_PM_ERR_LOG"

1
-----------
        0

  1 record(s) selected.


It took not more than 2 min for table of 15GB, without a single transaction log generation
Also brought down the tablespace usage
Be Careful & have table export backup before executing such carrier turner command who itself says “nonrecoverable”, however taking backup would be another project of such a huge table in crunch time

2 comments: