AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > Oracle

Oracle9i中监视索引的使用

51自学网 http://www.wanshiok.com

  辨别数据库中所有未被使用的索引

  这个脚本将会启动监控所有的索引:

##################################################################### ## start_index_monitoring.sh ##
#####################################################################
#!/bin/ksh
# input parameter: 1: password
# 2: SID
if (($#<1))
then
echo "Please enter 'system' user password as the first parameter !"
exit 0
fi
if (($#<2))
then
echo "Please enter instance name as the second parameter!"
exit 0
fi
sqlplus -s < system/$1@$2
set heading off
set feed off
set pagesize 200
set linesize 100
spool start_index_monitoring.sql
select 'ALTER INDEX '||OWNER||'.'||INDEX_NAME||' MONITORING USAGE;'
from dba_indexes
where owner not in ('SYS','SYSTEM','OUTLN','AURORA/$JIS/$UTILITY/$');
spool off
exit
!
sqlplus -s < oracle/$1@$2
@./start_index_monitoring.sql
exit
!


  这个脚本将会停止监控全部的索引:

#####################################################################
## stop_index_monitoring.sh ##
#####################################################################
#!/bin/ksh
# input parameter: 1: password
# 2: SID
if (($#<1))
then
echo "Please enter 'system' user password as the first parameter !"
exit 0
fi
if (($#<2))
then
echo "Please enter instance name as the second parameter!"
exit 0
fi
sqlplus -s < system/$1@$2
set heading off
set feed off
set pagesize 200
set linesize 100
spool stop_index_monitoring.sql
select 'ALTER INDEX '||OWNER||'.'||INDEX_NAME||' NOMONITORING USAGE;'
from dba_indexes
where owner not in ('SYS','SYSTEM','OUTLN','AURORA/$JIS/$UTILITY/$');
spool off
exit
!
exit
sqlplus -s < oracle/$1@$2
@./stop_index_monitoring.sql
exit
!

  这个脚本将会为所有未被使用的索引产生一个报表:

#####################################################################
## identify_unused_index.sh ##
#####################################################################
#!/bin/ksh
# input parameter: 1: password
# 2: SID
if (($#<1))
then
echo "Please enter 'system' user password as the first parameter !"
exit 0
fi
if (($#<2))
then
echo "Please enter instance name as the second parameter!"
exit 0
fi
sqlplus -s < system/$1@$2
set feed off
set pagesize 200
set linesize 100
ttitle center "Unused Indexes Report" skip 2
spool unused_index.rpt
select owner,index_name,table_name,used
from v/$all_object_usage
where used = 'NO';
spool off
exit
!

  以下就是一个未被使用索引报表的例子:

Unused Indexes Report

OWNER INDEX_NAME TABLE_NAME USE
------------------------------ ------------------------------ ----------------- --- HR DEPT_ID_PK DEPARTMENTS NO
HR DEPT_LOCATION_IX DEPARTMENTS NO
HR EMP_DEPARTMENT_IX EMPLOYEES NO
HR EMP_EMAIL_UK EMPLOYEES NO
HR EMP_EMP_ID_PK EMPLOYEES NO
HR EMP_JOB_IX EMPLOYEES NO
HR EMP_MANAGER_IX EMPLOYEES NO
HR EMP_NAME_IX EMPLOYEES NO
HR JHIST_DEPARTMENT_IX JOB_HISTORY NO
HR JHIST_EMPLOYEE_IX JOB_HISTORY NO
HR JHIST_EMP_ID_ST_DATE_PK JOB_HISTORY NO
HR JHIST_JOB_IX JOB_HISTORY NO
HR JOB_ID_PK JOBS NO
HR LOC_CITY_IX LOCATIONS NO
HR LOC_COUNTRY_IX LOCATIONS NO
HR LOC_ID_PK LOCATIONS NO
HR LOC_STATE_PROVINCE_IX LOCATIONS NO
HR REG_ID_PK REGIONS NO
OE INVENTORY_PK INVENTORIES NO
OE INV_PRODUCT_IX INVENTORIES NO
OE INV_WAREHOUSE_IX INVENTORIES NO
OE ITEM_ORDER_IX ORDER_ITEMS NO
OE ITEM_PRODUCT_IX ORDER_ITEMS NO
OE ORDER_ITEMS_PK ORDER_ITEMS NO
OE ORDER_ITEMS_UK ORDER_ITEMS NO
OE ORDER_PK ORDERS NO

  结论

  Oracle9i为监控索引的使用提供了一个新的方法,并且帮助我们辨别未被使用的索引。这个查找和删除未被使用索引的能力不但对插入和删除操作的性能有帮助,而且还节省了存储空间。在使用索引监控的时候不会看到性能的下降。

 
 

上一篇:Oracle数据库游标使用大全  下一篇:监控Oracle数据库的常用shell脚本