DB2 Miscellania

We (the current project I am working on) are in the process of migrating an existing ITIM database from Oracle 10g to DB2 9.1. This is still a work in progress, and something I want to write about simply because it hasn't been done (to the best of my knowledge). Not even the ITIM engineers I checked with have ever heard of a customer converting their database after the fact.

In any case, I have had to learn a little more about DB2 and one of the more useful tasks that I've had to learn is how to clear all of the records out of a table. My first attempt was to simply call  'DELETE FROM TABLE'. This may work for small tables, but does not work for larger tables, simply because DB2 has to keep a transaction log in case of a rollback. If the size of the table is larger than the size of your transaction logs this simply does not work.

As an alternative, you can use an import statement such as: 'IMPORT FROM /dev/null OF DEL REPLACE INTO TABLE'. This does an import of a comma delimiated (of del) file (in this case a non-existent empty file nul) and replaces the existing values in the named table. This is much faster than an unconditional delete because the transaction log is not involved.

Unfortunately, this technique did not work for me and resulted in SQL3201N errors. This was because DB2 does not allow values to be replaced during import if the table has referential integrity (foreign key) constraints. To bypass this you can do a load instead of an import: 'LOAD FROM /dev/null OF DEL REPLACE INTO TABLE'. This technique is equivalent to import without checking constraints, which puts the tables into a pending state if other tables have foreign key constraints against the table. To re-enable the integrity constraints and put the table back into normal state simply call: 'SET INTEGRITY FOR TABLE IMMEDIATE CHECKED'. This has to be done for the table loaded, and any table which has foreign key constraints against the table.

I felt this might be useful for non-DBAs since all of the related forum posts I could find related to this were from DBAs telling people to go read the DB2 manual. I read the manual...some of it!

Comments

Popular posts from this blog

Load Balancing Web Services with WebSEAL

Leveraging Azure MFA with CyberArk

Role-based Identity Management Best Practices