Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

Generating reorg statements for all tables

Generate reorg statements for all tables at once with this DB2 command.

Our production tables often need to be reorganized because they have been modified so many times that the data...

is fragmented and access performance is slow. We reorganize in off-peak hours since all database operations should be closed and we have to release all locks before invoking the reorg. In order to generate the reorg statements for all the tables at once -- as a batch process that will execute at night -- this command is very useful. It has been tested on version 7.1, fixpack 5.

For a database with, for example, 500 tables for a particular user we can generate the reorg statements using the command:

export to C:reorg.sql of del 
select 'REORG TABLE CDSWEB.' || tabname || ' USE ' || TBSPACE  || ' & '
from syscat.tables
where tabschema = 'OWNER_NAME' and type = 'T';

For More Information

  • Feedback: E-mail the editor with your thoughts about this tip.
  • More tips: Hundreds of free DB2 tips and scripts.
  • Tip contest: Have a DB2 tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
  • Ask the Experts: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
  • Forums: Ask your technical DB2 questions--or help out your peers by answering them--in our active forums.
  • Best Web Links: DB2 tips, tutorials, and scripts from around the Web.

Just replace the quotes with a blank and "&" with a semicolon and run the file by connecting to the required database.

Dig Deeper on DB2 UDB (universal databases)

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close