DB2 runstats, reorgchk, reorg commands


    
runstats, reorgchk, reorg

 

1, runstats

runats can collect table information and index information. As runstats itself does not have an optimization function, but after it updates the statistics, the DB2 optimizer can use the latest statistics to optimize, so that the optimization effect is better.

 

runstats on table <tbschema>.<tbname> Collects statistics for table <tbname>. Table names must be fully qualified with <dbschema>.

 

 

  2. reorg

 

 A. reorg table <tbschema>.<tablename> Reorganizes the table by reconstructing rows to eliminate "fragmented" data and compress information. Table names must be fully qualified with <dbschema>.

  B.

Another function of reorg is that the data in the table can be arranged in the order of a certain index key, thereby reducing the number of certain query I/Os.

 

 

  Execution of REORG can be divided into two cases: there is an index on the table and there is no index:

     a. For example, the table name is DB2INST1.STAFF, and the index name is DB2INST1.ISTAFF

      reorg table db2inst1.staff index db2inst1.istaff use tempspace1

    b. It is recommended to use REORG The USE parameter specifies the temporary tablespace used for data rearrangement. Otherwise, REORG work will

       be executed in place in the tablespace where the table is located. If there are multiple indexes on the table, please use the most important

       index .

    c.

       reorg table db2inst1.staff use tempspace1

      reorg table sysibm.systables use tempspace1

 

http://weiruan85.javaeye.com/blog/317520

 

3.

 

Let db2 system runstats regularly, reorg

Q: regular runstats, reorg

A: above db2 v8.2 You can use CALL SYSPROC.ADMIN_CMD to achieve this.

Here we mainly talk about using shell or batch processing to achieve the same function in versions before v8.2

because DDL operation statements cannot be used in stored procedures in previous versions! (This point It's very depressing for people who have just turned from oracle)

and then you can use the configuration that comes with db2 to automatically maintain it, but what java does is more of a headache! Especially the speed and inexplicable errors!

This code uses the operation The script of the system can realize this part of the function!

1. The

following is under windows: the content

of the next cmd file s.cmd

is as follows:

db2 connect to ccp_dm

db2 -x "select 'runstats on table '||rtrim(tabschema)||'.' ||tabname||' on all columns' from sysstat.tables where card=-1">tab.sql

db2 -f tab.sql --The

conditions after where can be modified

Then there is the custom task: custom task with windos! It runs weekly or monthly, not to mention this!

This part has been tested and passed!

But yes, only runstats is mentioned here, and the same can be achieved for reorg!

 

http://myfriend2010.itpub.net/post/29012/386779

 

 

4. reorgchk

 

C:\Documents and Settings\Administrator >db2 reorgchk update statistics on table all

 

is executing RUNSTATS ....

 

  reorgchk on table all to determine whether the table needs to be reorganized. This is useful for automating runstats for all tables.   1) REORGCHK db2 reorgchk update statistics on table system

 

 

for system tables. Use the UPDATE STATISTICS parameter to specify that the database first execute the RUNSTATS command. 2) Perform REORGCHK db2 reorgchk update statistics on table user for the user table The following is the partial result of the execution db2 reorgchk update statistics on table user executes RUNSTATS ....





 





 







 

 

The db2 reorgchk command is one of the most important and often overlooked DB2 tuning commands. The db2 reorgchk command is ignored because it is not a one-time adjustment. Since the update is performed on the DB2 database, statistics about the table will not be up to date. The db2 reorgchk command updates important statistics used by the DB2 optimizer. It is recommended to repeat the db2 reorgchk command after approximately every 10,000 updates.

 

Before running the db2 reorgchk command, you should stop the IBM Directory Server to prevent any DB2 queries or updates from taking place while the command is executing. Although this is optional, database queries and updates can be very slow and may time out.

 

 

 

Note that the performance benefit of running the db2 reorgchk command is immediate. It is not necessary to restart DB2 after the db2 reorgchk command.

 

In addition to improving performance, the db2 reorgchk command also reports statistics about all tables and indexes in the database. The db2 reorgchk command also reports statistics about the organization of DB2 tables.

 

http://publib.boulder.ibm.com/tividd/td/ITAME/SC32-1351-00/en_US/HTML/am51_perftune66.htm

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326614091&siteId=291194637
db2
db2