WEB开发网
开发学院数据库Oracle Oracle9i中监视索引的使用 阅读

Oracle9i中监视索引的使用

 2006-08-05 11:58:32 来源:WEB开发网   
核心提示: 这个脚本将会停止监控全部的索引:### stop_index_monitoring.sh !/bin/ksh# input parameter: 1: password# 2: SIDif (($#<1))thenecho "Please enter 'system

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

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

上一页  1 2 3 4 

Tags:Oraclei 监视 索引

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接