#!/usr/bin/ksh # program smenu_desc_idx.sh # Author : Bernard Polarski : 07/12/99 # rewritten 23 september 2005 # Bart Debersaques : Add size on index # bpa : Add count on unusable indexes # bpa : add -inv options for quick list all invalids # bpa : reviewed 15-december-2009 # : Added move tablespace and recognition of function based and domain index # set -x #--------------- comments section --------------------- # This script is part of the module 3 (DB utilities) in smenu # Purpose : List all about indexes #--------------- Environement section --------------------- HOST=`hostname` #--------------- Function variables section --------------------- function help { cat < : List all index for given table idx -u [owner] -i [index] -t [table] -h -cf -fb -p -s idx -u [owner] -i [index] -ntbs [-x] : Gen. statements move index to new tablespace -u : Schema owner of the index -i : index name to process -ntbs : Move index to new tablespace -cf : Show clustering factor in percentage. The lower is the best, 100% is the worst -fb : Add the text of the function based index -hg : Show system overal histograms distribution among indexes -inv : List invalid indexes, partitions and subpartitions, order by owner -ix : Alternate info on index from ixora -p : List index (sub)partitions info; Add '-s' -> Segment size from dba_segments instead of analysed date -sinv : Generate Rebuild statement for ll invalid indexes, partitions and subpartitions -tbs : Show tablespace instead of columns_names -x : Execute command Notes: Clustering factor : - if near the number of blocks, then the table is ordered : index entries in a single leaf block tend to point to rows in same data block - if near the number of rows, the table is randomly ordered : index entries in a single leaf block are unlikely to point to rows in same data block Global stats : For partitioned indexes, YES means statistics are collected for the INDEX as a whole NO means statistics are estimated from statistics on underlying index partitions or subpart. Pct_direct_access : For secondary indexes on IOTs, rows with VALID guess EOF } if [[ -z "$1" ]];then help ; exit fi VAR_FIELD="to_char(a.LAST_ANALYZED,'YYYY-DD-MM HH24:MI') la," VAR_FIELD2=" clustering_factor cf, " TIT_IDX_NAME_LEN=30 TIT_COL_NAME=22 TIT_TABLE_NAME=28 typeset -u fowner typeset -u findex typeset -u ftable choice=default while [[ -n "$1" ]] do case $1 in -cf ) CLUSTER_FACTOR=TRUE ;; -fb ) FB=TRUE ;; -h ) help ; exit ;; -i ) findex=$2 ; shift;; -inv ) choice=LIST_INVALID;; -ix ) choice=IX ;; -hg ) choice=HISTO;; -ntbs ) choice=MOVE_TBS ; typeset -u ftbs=$2 ; shift ;; -p ) choice=PART ;; -t ) ftable=$2 ; AND_TABLE=" and b.table_name ='$ftable' " ; shift;; -s ) VAR_FIELD="(select sum(bytes/1024/1024) bytes from dba_segments where segment_name = b.index_name and owner = b.index_owner group by owner,segment_name) tot_seg_mb," ;; -sinv ) choice=REBUILD_INVALID;; -tbs ) COL_OR_TBS=b.tablespace_name ;; -u ) fowner=$2 ; shift ;; -x ) EXECUTE=YES ;; -v ) VERBOSE=TRUE;; * ) help exit ; esac shift done #--------------- Process section --------------------- #--------------- Get system password section --------------------- . $SBIN/scripts/passwd.env . ${GET_PASSWD} if [ "x-$CONNECT_STRING" = "x-" ];then echo "could no get a the password of $S_USER" exit 0 fi #--------------- Process section --------------------- # a table name is given but no index and no owner: # we output all index for this table or the list of table owner if multiple occurence exists if [ -n "$ftable" -a -z "$findex" -a -z "$fowner" ];then ret=`sqlplus -s "$CONNECT_STRING" < to view all indexes for this table" echo sqlplus -s "$CONNECT_STRING" < " echo sqlplus -s "$CONNECT_STRING" <