監控Index是否被使用過的方法
索引可以加快查詢的速度,但索引會佔用許多儲存空間,在插入和刪除行的時候,索引還會引入額外的開銷,因此確保索引得到有效利用是我們很關注的一個問題。在Oracle9i之前,要知道一個索引是否被使用是困難的,而Oracle 9i中提供了一個有效的監控方法:ALTER INDEX MONITORING USAGE。
這裡我以一個已有的索引,來演示怎樣監控其使用情況,演示之前,我們可以查詢一下檢視v$object_usage,看看有什麼結果,如果以前沒啟用過該功能,則查詢不到任何資訊。
首先,針對已有的index,啟用其監視功能:
alter index INDEX_DEPLOYEE_IS_SNZY monitoring usage;
alter index INDEX_DEPLOYEE_IS_UPDATE monitoring usage;
alter index INDEX_DEPLOYEE_IDCARD monitoring usage;
alter index INDEX_DEPLOYEE_SCHOOLID monitoring usage;
alter index INDEX_DEPLOYEE_BY_HAND monitoring usage;
alter index INDEX_DEPLOYEE_COUNTY monitoring usage;
alter index INDEX_DEPLOYEE_HJXZ monitoring usage;
alter index INDEX_DEPLOYEE_IS_FEE monitoring usage;
alter index INDEX_DEPLOYEE_LOWER monitoring usage;
alter index INDEX_DEPLOYEE_PROVINCE monitoring usage;
alter index INDEX_DEPLOYEE_SPE monitoring usage;
alter index INDEX_DEPLOYEE_STATUS monitoring usage;
alter index INDEX_DEPLOYEE_IS_UPDATE monitoring usage;
alter index INDEX_DEPLOYEE_IDCARD monitoring usage;
alter index INDEX_DEPLOYEE_SCHOOLID monitoring usage;
alter index INDEX_DEPLOYEE_BY_HAND monitoring usage;
alter index INDEX_DEPLOYEE_COUNTY monitoring usage;
alter index INDEX_DEPLOYEE_HJXZ monitoring usage;
alter index INDEX_DEPLOYEE_IS_FEE monitoring usage;
alter index INDEX_DEPLOYEE_LOWER monitoring usage;
alter index INDEX_DEPLOYEE_PROVINCE monitoring usage;
alter index INDEX_DEPLOYEE_SPE monitoring usage;
alter index INDEX_DEPLOYEE_STATUS monitoring usage;
然後檢視檢視v$object_usage,結果如下:
SQL> select * from v$object_usage;
INDEX_NAME TABLE_NAME MONITORING USED START_MONITORING END_MONITORING
------------------------------ ----------- ---------- ---- ------------------- -------------------
INDEX_DEPLOYEE_IS_SNZY T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IS_UPDATE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IDCARD T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_SCHOOLID T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_BY_HAND T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_COUNTY T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_HJXZ T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IS_FEE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_LOWER T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_PROVINCE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_SPE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_STATUS T_DEPLOYEE YES NO 12/10/2010 17:08:26
------------------------------ ----------- ---------- ---- ------------------- -------------------
INDEX_DEPLOYEE_IS_SNZY T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IS_UPDATE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IDCARD T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_SCHOOLID T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_BY_HAND T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_COUNTY T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_HJXZ T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IS_FEE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_LOWER T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_PROVINCE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_SPE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_STATUS T_DEPLOYEE YES NO 12/10/2010 17:08:26
14 rows selected
然後透過查詢SQL語句,使部分索引起作用,再檢視該檢視,結果如:
SQL> select * from v$object_usage;
INDEX_NAME TABLE_NAME MONITORING USED START_MONITORING END_MONITORING
------------------------------ ----------- ---------- ---- ------------------- -------------------
INDEX_DEPLOYEE_IS_SNZY T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IS_UPDATE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IDCARD T_DEPLOYEE YES YES 12/10/2010 17:08:26
INDEX_DEPLOYEE_SCHOOLID T_DEPLOYEE YES YES 12/10/2010 17:08:26
INDEX_DEPLOYEE_BY_HAND T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_COUNTY T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_HJXZ T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IS_FEE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_LOWER T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_PROVINCE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_SPE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_STATUS T_DEPLOYEE YES NO 12/10/2010 17:08:26
------------------------------ ----------- ---------- ---- ------------------- -------------------
INDEX_DEPLOYEE_IS_SNZY T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IS_UPDATE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IDCARD T_DEPLOYEE YES YES 12/10/2010 17:08:26
INDEX_DEPLOYEE_SCHOOLID T_DEPLOYEE YES YES 12/10/2010 17:08:26
INDEX_DEPLOYEE_BY_HAND T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_COUNTY T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_HJXZ T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_IS_FEE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_LOWER T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_PROVINCE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_SPE T_DEPLOYEE YES NO 12/10/2010 17:08:26
INDEX_DEPLOYEE_STATUS T_DEPLOYEE YES NO 12/10/2010 17:08:26
14 rows selected
若不再需要監控索引使用情況時,只需要執行如下語句取消監控即可:
alter index INDEX_DEPLOYEE_IS_SNZY nomonitoring usage;
alter index INDEX_DEPLOYEE_IS_UPDATE nomonitoring usage;
alter index INDEX_DEPLOYEE_IDCARD nomonitoring usage;
alter index INDEX_DEPLOYEE_SCHOOLID nomonitoring usage;
alter index INDEX_DEPLOYEE_BY_HAND nomonitoring usage;
alter index INDEX_DEPLOYEE_COUNTY nomonitoring usage;
alter index INDEX_DEPLOYEE_HJXZ nomonitoring usage;
alter index INDEX_DEPLOYEE_IS_FEE nomonitoring usage;
alter index INDEX_DEPLOYEE_LOWER nomonitoring usage;
alter index INDEX_DEPLOYEE_PROVINCE nomonitoring usage;
alter index INDEX_DEPLOYEE_SPE nomonitoring usage;
alter index INDEX_DEPLOYEE_STATUS nomonitoring usage;
alter index INDEX_DEPLOYEE_IS_UPDATE nomonitoring usage;
alter index INDEX_DEPLOYEE_IDCARD nomonitoring usage;
alter index INDEX_DEPLOYEE_SCHOOLID nomonitoring usage;
alter index INDEX_DEPLOYEE_BY_HAND nomonitoring usage;
alter index INDEX_DEPLOYEE_COUNTY nomonitoring usage;
alter index INDEX_DEPLOYEE_HJXZ nomonitoring usage;
alter index INDEX_DEPLOYEE_IS_FEE nomonitoring usage;
alter index INDEX_DEPLOYEE_LOWER nomonitoring usage;
alter index INDEX_DEPLOYEE_PROVINCE nomonitoring usage;
alter index INDEX_DEPLOYEE_SPE nomonitoring usage;
alter index INDEX_DEPLOYEE_STATUS nomonitoring usage;
v$object_usage檢視解釋
從上面的例子中我們可以看出,索引的監視資訊都是存在在v$objec_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#
(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#
下面是該檢視列的描述:
INDEX_NAME: sys.obj$.name 中的索引名字
TABLE_NAME: sys.obj$obj$name 中的表名
MONITORING: YES (索引正在被監控), NO (索引沒有被監控)
USED: YES (索引已經被使用過), NO (索引沒有被使用過)
START_MONITORING: 開始監控的時間
END_MONITORING: 結束監控的時間
所有被使用過至少一次的索引都可以被監控並顯示到這個檢視中。
INDEX_NAME: sys.obj$.name 中的索引名字
TABLE_NAME: sys.obj$obj$name 中的表名
MONITORING: YES (索引正在被監控), NO (索引沒有被監控)
USED: YES (索引已經被使用過), NO (索引沒有被使用過)
START_MONITORING: 開始監控的時間
END_MONITORING: 結束監控的時間
所有被使用過至少一次的索引都可以被監控並顯示到這個檢視中。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9399028/viewspace-680409/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 監控index是否被使用Index
- 監控Oracle索引是否被使用?Oracle索引
- 監控index 的使用情況Index
- index 監控Index
- 監視index的使用看看是否需要重建!Index
- 如何監控oracle的索引是否使用Oracle索引
- Oracle資料庫監控Index的使用情況Oracle資料庫Index
- 【INDEX】使用“alter index ××× monitoring usage;”語句監控索引使用與否Index索引
- linux下監控某個目錄是否被更改Linux
- nagios的配置(監控端和被監控端)iOS
- 通過ActionTrail監控AccessKey的使用AI
- 使用Shell指令碼程式監控網站URL是否正常指令碼網站
- 監視index的使用情況Index
- 索引監控-查詢從未被使用過的索引索引
- win10系統如何檢視自己電腦有沒有被監控_win10怎麼檢視自己電腦是否被監控Win10
- sessions,processes的監控方法Session
- Linux 監控程式是否存在的指令碼Linux指令碼
- shell監控服務程式是否啟動
- 教你如何監控網站URL是否正常網站
- 分享實用監控指令碼:使用Shell檢查程式是否存在指令碼
- 使用Metrics方法級遠端監控Java程式Java
- 一種對雲主機進行效能監控的監控系統及其監控方法
- ORACLE 監控索引的使用Oracle索引
- 分散式監控系統之Zabbix主動、被動及web監控分散式Web
- Process Monitor監控目錄 - 監控檔案被哪個程式操作了
- 惠普監控元件被爆LPE,可使用系統許可權元件
- shell指令碼:監控MySQL服務是否正常指令碼MySql
- centos 監控web站點是否500 指令碼CentOSWeb指令碼
- Oracle使用審計監控使用者執行過的SQL語句OracleSQL
- upptime:使用GitHub Actions監控你的網站健康監控Github網站
- MongoDB監控方法總結MongoDB
- 網站安全監控的方法講解,網站安全監控技術網站
- Mysql 建立心跳錶來監控Replication的Slave是否延遲MySql
- 怎麼查網站是否被K過網站
- 被動式監控oracle的rman備份情況Oracle
- 使用Admin監控
- 使用monit監控stormORM
- 使用Ganglia監控SparkSpark