扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
ALTER INDEX index_name MONITORING USAGE; |
ALTER INDEX index_name NOMONITORING USAGE; |
CREATE OR REPLACE VIEW SYS.V$OBJECT_USAGE ( INDEX_NAME, TABLE_NAME, MONITORING, USED, START_MONITORING, END_MONITORING ) AS select io.name, t.name, decode(bitand(i.flags, 65536), 0, 'NO', 'YES'), decode(bitand(ou.flags, 1), 0, 'NO', 'YES'), ou.start_monitoring, ou.end_monitoring from sys.obj$ io, sys.obj$ t, sys.ind$ i, sys.object_usage ou where io.owner# = userenv('SCHEMAID') and i.obj# = ou.obj# and io.obj# = ou.obj# and t.obj# = i.bo# / COMMENT ON TABLE SYS.V$OBJECT_USAGE IS 'Record of index usage' / GRANT SELECT ON SYS.V$OBJECT_USAGE TO "PUBLIC" / |
$ cat all_object_usage.sql CREATE OR REPLACE VIEW SYS.V$ALL_OBJECT_USAGE ( OWNER, INDEX_NAME, TABLE_NAME, MONITORING, USED, START_MONITORING, END_MONITORING ) AS select u.name, io.name, t.name, decode(bitand(i.flags, 65536), 0, 'NO', 'YES'), decode(bitand(ou.flags, 1), 0, 'NO', 'YES'), ou.start_monitoring, ou.end_monitoring from sys.obj$ io, sys.obj$ t, sys.ind$ i, sys.object_usage ou, sys.user$ u where i.obj# = ou.obj# and io.obj# = ou.obj# and t.obj# = i.bo# and io.owner# = u.user# / COMMENT ON TABLE SYS.V$ALL_OBJECT_USAGE IS 'Record of all index usage - developed by Daniel Liu' / GRANT SELECT ON SYS.V$ALL_OBJECT_USAGE TO "PUBLIC" / CREATE PUBLIC SYNONYM V$ALL_OBJECT_USAGE FOR SYS.V$ALL_OBJECT_USAGE / |
##################################################################### ## 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 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者