728x90
Problem(Abstract)
You have multiple tables in your database that have changed extensively and you are experiencing a performance degradation. Reorg and runstats are recommended on these tables. You can create reorg and runstats scripts to make DB2® performance tuning easy.
Resolving the problem
To generate and run reorg and runstats scripts:
- Log in as the DB2 administrator, and connect to the database.
- To create a script for reorg table, run the following command on one line:
db2 "list tables for all" | awk '{print $2"." $1}' | awk '/\w/ {print $0}' | sed '/^Schema.Table/d' | sed '/^record(s)./d' | sed 's/^/REORG TABLE /g' | sed 's/$/;/g' > /tmp/reorg_tbl.ddl - To create a script for reorg index, run the following command on one line:
db2 "list tables for all" | awk '{print $2"." $1}' | awk '/\w/ {print $0}' | sed '/^Schema.Table/d' | sed '/^record(s)./d' | sed 's/^/REORG INDEXES ALL FOR TABLE /g' | sed 's/$/;/g' > /tmp/reorg_idx.ddl - To create a script for runstats, run the following command on one line:
db2 "list tables for all" | awk '{print $2"." $1}' | awk '/\w/ {print $0}' | sed '/^Schema.Table/d' | sed '/^record(s)./d' | sed 's/^/RUNSTATS on TABLE /g' | sed 's/$/ WITH DISTRIBUTION AND DETAILED INDEXES ALL;/g' > /tmp/runstats_tbl.ddl - Run reorg against tables and indexes, then runstats by entering the following lines:
db2 -tvf /tmp/reorg_tbl.ddl
db2 -tvf /tmp/reorg_idx.ddl
db2 -tvf /tmp/runstats_tbl.ddl - Ignore the following message if you receive it:
SQL2212N The specified table is a view. The Reorganize Table utility cannot be run against a view. - To capture the message printed on screen, you can pipe the standard output into a file, such as with the following command:
db2 -tvf /tmp/runstats_tbl.ddl > filename.log 2>&1
NOTE: The commands in step 2, 3 and 4 will not run on windows system.
The following method can also be used to reorg all the tables in a database on Linux, Unix and Windows.
- Log in as the DB2 administrator, and connect to the database.
- To create a script for reorg table, run the following command on one line:
db2 -x "select 'REORG TABLE ' ||rtrim (tabschema)|| '.' || rtrim (tabname) || ' ;' from syscat.tables where tabschema not like 'SYS%' and type = 'T'" > reorg.out - Run reorg against tables entering the following line:
db2 -tvf reorg.out
- NOTE: The where clause in step 2 can be altered to include other tables in the reorg.out script.
It is recommended to runstats on any table that has been reorged.
Also, these commands may not work on all versions and levels of Unix and Linux.
http://www-01.ibm.com/support/docview.wss?uid=swg21444174&myns=swgimgmt&mynp=OCSSEPGG&mync=E
728x90
'Db2 > Db2 reference' 카테고리의 다른 글
Moving DB2 instances and database between filesystems (0) | 2014.10.31 |
---|---|
멀티바이트 문자에 대한 LENGTH 함수 작동 (0) | 2014.06.25 |
Preventing application database connections from automatically activating a database after db2start. (0) | 2014.05.19 |
How to determine if a table has been taken out of check pending state manually (0) | 2014.02.08 |
How to extract data from a corrupted table using db2dart (0) | 2014.02.06 |