0% found this document useful (0 votes)
206 views2 pages

DB2 How To Run Reorg

This document provides scripts to execute REORG, REORGCHK, and RUNSTAT utilities on all tables in a database or on all tables within a specific tablespace. The scripts query the SYSCAT.TABLES catalog view to generate statements to reorganize, check reorganization, and collect statistics on all user tables. The statements are written to output files which are then executed using the db2 command with the -tvf option to run the statements in each file.

Uploaded by

Charli Arry
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
206 views2 pages

DB2 How To Run Reorg

This document provides scripts to execute REORG, REORGCHK, and RUNSTAT utilities on all tables in a database or on all tables within a specific tablespace. The scripts query the SYSCAT.TABLES catalog view to generate statements to reorganize, check reorganization, and collect statistics on all user tables. The statements are written to output files which are then executed using the db2 command with the -tvf option to run the statements in each file.

Uploaded by

Charli Arry
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

How to run REORG, REORGCHK and RUNSTAT on all tables in a database

Queries to execute REORG, REORGCHK and RUNSTAT on all tables in a database

Write the following scripts in a .out file, then execute it by issuing the db2 command with option -tvf.

Reorg for all tables

db2 -x "select 'reorg table',substr(rtrim(tabschema)||'.'||rtrim(tabname),1,50),';'from syscat.tables where type = 'T' " > reorg.out db2 -tvf reorg.out

Reorgchk for all tables

db2 -x "select 'reorgchk update statistics on table',substr(rtrim(tabschema)||'.'||rtrim(tabname),1,50),';' from \ syscat.tables where type = 'T' " > reorgchk.out db2 -tvf reorgchk.ou

Runstats for all tables

db2 -x "select 'runstats on table',substr(rtrim(tabschema)||'.'||rtrim(tabname),1,50),' and indexes all;'from \ syscat.tables where type = 'T' " > runstats.out db2 -tvf runstats.out

Executing reorg, reorgcheck and runstats for all tables from one specific tablespace.

Reorg for all tables from one specifc tablespace

db2 -x "select 'reorg table',substr(rtrim(tabschema)||'.'||rtrim(tabname),1,50),';' \ from syscat.tables where type = 'T' and tbspace='<tablespace_name>'" > reorg.out db2 -tvf reorg.out

Reorgchk for all tables from one specifc tablespace

db2 -x "select 'reorgchk update statistics on table',substr(rtrim(tabschema)||'.'||rtrim(tabname),1,50),';' from \ syscat.tables where type = 'T' and tbspace='<tablespace_name>'" > reorgchk.out db2 -tvf reorgchk.ou

Runstats for all tables from one specifc tablespace

db2 -x "select 'runstats on table',substr(rtrim(tabschema)||'.'||rtrim(tabname),1,50),' and indexes all;'from \ syscat.tables where type = 'T' " > runstas.out db2 -tvf runstats.out

You might also like