DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: Table and Index Rebuild

  1. #1
    Join Date
    Feb 2002
    Posts
    25
    Hello,

    I have to rebuild about 500 indexes that were created more then 6 months ago.
    I have a query:
    select *
    from all_objects
    where trunc(created) < trunc(sysdate - 180)
    and object_type like'%INDEX%'
    order by owner

    How would I automate this?

    Thanks in advance,

    Boris

  2. #2
    Join Date
    Jan 2001
    Posts
    642
    hi,
    creat a script something like this and set up the cron job
    #!/bin/sh
    #user=${1}
    #pass=${2}
    #sid=${3}
    user="cognos"
    pass="focus"
    sid=gdmprd
    ORACLE_HOME=/app/oracle/product/8.1.7

    ${ORACLE_HOME}/bin/sqlplus -s ${user}@${sid}/${pass}<<__eof__ > /tmp/am.log 2>&1
    spool /tmp/ind.sql
    select 'Alter index' || object_name || 'rebuild'
    from all_objects
    where trunc(created) < trunc(sysdate - 180)
    and object_type like'%INDEX%'
    order by owner;
    spool off
    @/tmp/ind.sql
    __eof__

    There is always a better way to do the things.

  3. #3
    Join Date
    Oct 2000
    Posts
    467
    Hope this helps.

    select 'alter index '||object_name||' rebuild online;'
    from all_objects
    where trunc(created) < trunc(sysdate - 180)
    and object_type like'%INDEX%'
    order by owner

    Make sure u give the correct tablespace name, sizing parameters.
    Vinit

  4. #4
    Join Date
    Jan 2001
    Posts
    3,134
    You may want to set a larger sort area size as well...

    SQL> ALTER SESSION SET SORT_AREA_SIZE=4000000

    This can speed up the sorts dramatically in some cases.

    MH
    I remember when this place was cool.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width