The DB2 Admin 002
The DB2 Admin 002
minimizing downtime. These utilities allow you to perform tasks like reorganizing tables,
updating statistics, and more, without taking the database offline. Here’s a breakdown of
what they are, how they work, and how you might use them in real-world scenarios:
1. REORG (Reorganization):
o Purpose: Reorganize tables and indexes to improve performance. It’s
particularly useful for reclaiming space and optimizing data access paths.
o How It Works: Reorganizes data while the database remains online. You can
reorganize an entire table or specific partitions. It uses a shadow copy
mechanism where the database remains operational and users can continue
accessing the data.
o Scenario: Suppose you have a large table where data is heavily fragmented
due to frequent updates and deletes. You would use REORG to defragment the
table and improve query performance.
2. RUNSTATS (Run Statistics):
o Purpose: Collect and update statistics about the data in tables and indexes.
These statistics help the Db2 optimizer make better decisions about how to
execute queries.
o How It Works: Gathers statistical information while the database is in use,
ensuring that the query optimizer has the latest data distribution statistics to
make efficient query plans.
o Scenario: After a bulk load of data into a table, you would run RUNSTATS to
update the statistics, which helps in maintaining optimal query performance.
3. REBUILD (Index Rebuild):
o Purpose: Rebuilds indexes to improve performance or to recover from
corruption. It can be performed online to avoid downtime.
o How It Works: Rebuilds indexes on a table while the database is operational.
This process involves creating a new index and then swapping it with the old
one.
o Scenario: If an index has become fragmented or corrupted, you would use
REBUILD to restore its performance without impacting the availability of the
database.
4. RECOVER (Database Recovery):
o Purpose: Recover a database or table to a point in time. This utility helps in
restoring data after an accidental deletion or corruption.
o How It Works: While traditionally associated with offline recovery, Db2’s
features for online recovery involve creating and applying logs and backups in
a way that minimizes downtime.
o Scenario: A critical application has corrupted a table, and you need to recover
it to its state before the corruption occurred. You would use RECOVER to
restore the table with minimal impact on the database's availability.
Imagine you are a database administrator for a large e-commerce platform. Here’s how you
might use these utilities:
1. Performance Optimization:
o Scenario: The sales reports are running slower than usual.
o Action: You would use REORG on the tables involved in the reports to
reorganize fragmented data. You might also run RUNSTATS to ensure the
query optimizer has current statistics for the best performance.
2. Index Maintenance:
o Scenario: Users report slow queries on a frequently accessed table.
o Action: You would check the indexes on the table and use REBUILD if the
indexes are fragmented. This will enhance query performance by ensuring the
indexes are in optimal condition.
3. Post-Maintenance Verification:
o Scenario: After a major data load or change, the query performance needs
verification.
o Action: You would run RUNSTATS to update the statistics and ensure the
database optimizer has the latest data distribution information.
4. Database Recovery:
o Scenario: A recent data corruption incident needs to be addressed.
o Action: You would use RECOVER to restore the affected data to a state
before the corruption occurred, ensuring minimal disruption to ongoing
operations.
1. REORG Example:
2. RUNSTATS Example:
3. REBUILD Example:
4. RECOVER Example:
Each utility has specific options and parameters that can be tailored to your needs, so it's
crucial to consult the Db2 documentation for details on usage and best practices.