How to Run Reorg,Reorgcheck,Runstats & Granting privileges on all tables in a database

Reorg Command on all Tables in a Database

 

db2 -x "select 'reorg table',rtrim(tabschema)||'.'|| rtrim(tabname)from syscat.tables where type = 'T' and TABSCHEMA = 'ABC'" > reorg_out.sql

 

db2 -tvf reorg_out.sql

 

Runstats Command on all tables in a database

 

db2 -x "select 'runstats on table',rtrim(tabschema)||'.'|| rtrim(tabname)from syscat.tables where type = 'T' and TABSCHEMA = 'ABC'" > runstat_out.sql

 

db2 -tvf runstat_out.sql

 

Granting Select Privileges on all Tables in a Database

 

db2 -x  "select 'Grant select on table ' || trim(tabschema) || '.' || trim(tabname)|| ' to user test_usr' from syscat.tables where tabschema = 'ABC'" >  grants.sql

 

Granting Execute Privileges on all Tables in a Database

 

db2 -x  "select 'Grant Execute on procedure ' || trim(procschema) || '.' || trim(procname)|| ' to user test_usr' from syscat.procedures where procschema = 'ABC'" >  grants_execute.sql

 

To Execute Reorg,Runstats on all tables for a particular Tablespace

 

db2 -x "select 'reorg table',rtrim(tabschema)||'.'|| rtrim(tabname)from syscat.tables where type = 'T' and TABSCHEMA = 'ABC' and tbspace = '<tablespace_name>'" > reorg_out.sql

 db2 -tvf reorg_out.sql

 

db2 -x "select 'runstats on table',rtrim(tabschema)||'.'|| rtrim(tabname)from syscat.tables where type = 'T' and TABSCHEMA = 'ABC' and tbspace = '<tablespace_name>'" > runstat_out.sql

 db2 -tvf runstat_out.sql

 

Comments

Popular posts from this blog

Db2 export command example using file format (del , ixf)

How to fix DB2 Tablespace OFFLINE state issue?

Phases of a load operation