Execute runstats in a stored procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sansaniwal12
    New Member
    • Sep 2007
    • 4

    Execute runstats in a stored procedure

    Hi,
    we want to execute runstats for all database tables in one go.In db2 v9, there is no such option to run runstats schema vise or for complete database.So,can we execute runstats from a stored procedure.
  • raimee
    New Member
    • Sep 2007
    • 3

    #2
    I use a shell script to accomplish what you want. You'll have to modify a bit
    for you environment.

    #!/usr/bin/ksh

    ############### ############### ############### #######

    DBNAME="DBNAME"
    TABSCHEMA="MYSC HEMA"

    db2 activate db $DBNAME
    export DB2DBDFT=$DBNAM E

    echo "Running... "

    db2 connect to $DBNAME user user using pass

    db2 -x "select tabname from syscat.tables where tabschema='MYSC HEMA' and TYPE='T'" |
    while read TABNAME
    do
    db2 -v -x "runstats on table $TABSCHEMA.\"$T ABNAME\" and indexes all"
    done

    db2 terminate

    Comment

    • dewa81
      New Member
      • Jul 2007
      • 14

      #3
      If you want to runstats on all the tables in the database we can accomplish this with just a single command

      Connect to the database and run the follwing command
      reorgchk update statistics

      Comment

      Working...