As you work with the DB2 extenders, obsolete entries can eventually accumulate in the administrative support tables. Someone might delete a media file but not the references to it in the database. Deleting the obsolete metadata can improve performance and reclaim storage space.
Using the API: The sample code in the following example cleans up the image metadata for all user tables that are owned by ANITAS. It includes some error-checking code. The complete sample program is in the API.C file in the SAMPLES subdirectory.
Figure 16. Sample code that cleans up administrative support tables
/*---- query database using DBiAdminReorgMetadata API ----*/ step="DBiAdminReorgMetadata API"; rc = DBiAdminReorgMetadata("anitas"); if (rc < 0) { printf("%s: %s FAILED!\n", argv[0], step); printMsg(rc); DBiGetError(&sqlcode, errorMsgText); printf("sqlcode=%i, errorMsgText=%s\n", sqlcode, errorMsgText); fail = TRUE; } else if (rc > 0) { printf("%s: %s, warning detected.\n", argv[0], step); printMsg(rc); DBiGetError(&sqlcode, errorMsgText); printf("sqlcode=%i, errorMsgText=%s\n", sqlcode, errorMsgText); } else printf("%s: %s PASSED\n\n", argv[0], step); /*---- end of query using DBiAdminReorgMetadata API ----*/ |
Using the db2ext command line:
reorg database user anitas for db2image
If you are not a DBA but have CONTROL authority, you can use the DBxReorgMetadata APIs or the REORG command to clean up metadata for the tables you own.