当前位置: 首页 > news >正文

oracle 10g 索引监控

相关引用
http://www.eygle.com/archives/2004/12/monitor_index_usage.html


一 环境
Rhel5U4_x86_64 + 10.2.0.4


在网上找的如何使用索引 (原地址没记.不由感叹,天下文章一大抄.大家都copy而不去管到底能不能执行出结果.)

索引监控
select   'alter index '||owner||'.'||index_name||' monitoring usage;' from dba_indexes where owner in (select username from dba_users where account_status ='OPEN') and owner not in ('SYS','SYSTEM','PERFSTAT','MGMT_VIEW','MONITOR','SYSMAN','DBSNMP');


运行一段时间然后运行

select   'alter index '||owner||'.'||index_name||' nomonitoring usage;' from dba_indexes where owner in (select username from dba_users where account_status ='OPEN') and owner not in ('SYS','SYSTEM','PERFSTAT','MGMT_VIEW','MONITOR','SYSMAN','DBSNMP');

查询视图
V$OBJECT_USAGE


整合脚本
set pages 2000;
set heading off;
spool index_monitor.sql
select   'alter index '||owner||'.'||index_name||' monitoring usage;' from dba_indexes where owner in (select username from dba_users where account_status ='OPEN') and owner not in ('SYS','SYSTEM','PERFSTAT','MGMT_VIEW','MONITOR','SYSMAN','DBSNMP');
spool off;
@index_monitor


按照上面做的以后,以sys用户登录系统查询v$object_usage视图.无结果返回.不由怀疑这种方法的可行性.于是又一顿神goo. 找到了此文档最前面贴出的链接地址.

下面是 v$object_usage 创建命令(我不会从数据库里面找出ddl语句.是用pldeveloper搜出的)

create or replace view 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 column V$OBJECT_USAGE.INDEX_NAME is 'Name of the index';
comment on column V$OBJECT_USAGE.TABLE_NAME is 'Name of the table upon which the index was build';
comment on column V$OBJECT_USAGE.MONITORING is 'Whether the monitoring feature is on';
comment on column V$OBJECT_USAGE.USED is 'Whether the index has been accessed';
comment on column V$OBJECT_USAGE.START_MONITORING is 'When the monitoring feature is turned on';
comment on column V$OBJECT_USAGE.END_MONITORING is 'When the monitoring feature is turned off';


注意到v$object_usage关键信息来源于OBJECT_USAGE表.
另外我们可以注意一下,此处v$object_usage的查询基于userenv('SCHEMAID')建立.
所以以不同用户登录,是无法看到其他用户的索引监视信息的,即使这个用户是dba.

那如果我想以sys来查询其他用户的监控结果怎么办呢? 根据 v$object_usage创建命令知道 只要能够查询 object_usage并且知道 schemaid就可以了.

Schemaid就是 dba_users 表中的 user_id 列.

查询语句可以这样写: (仅做参考)
select io.name index_name
, t.name table_name
,decode(bitand(i.flags, 65536), 0, 'NO', 'YES') monitoring
,decode(bitand(ou.flags, 1), 0, 'NO', 'YES') used
,ou.start_monitoring start_monitoring
,ou.end_monitoring end_monitoring
from sys.obj$ io, sys.obj$ t, sys.ind$ i, sys.object_usage ou
where i.obj# = ou.obj#
  and io.obj# = ou.obj#
  and t.obj# = i.bo#
and io.owner#  in (select user_id from dba_users where username =’DRUG’);

这里写下,分享并自已留用.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11780477/viewspace-678094/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/11780477/viewspace-678094/

相关文章:

  • ASM kfed工具的部分说明
  • sqlplus uptime过久事件
  • RMAN-06207 rman恢复数据库后备份delete出错
  • RMAN异库恢复之EM(1)
  • RMAN异库恢复之EM(2)遭遇 2010/12/31 root认证过期 bug
  • 丢失redo log的恢复
  • RMAN异库恢复之EM(3)
  • LOCK_SGA=TRUE causes an ORA-27126 during database startup on AIX
  • exp/imp parfile 用到的参数
  • 日志挖掘
  • RMAN备份脚本
  • sqlldr 控制文件样例
  • 审计相关
  • RAC 修改IP (转)
  • oracle oem 启动不起来(半解决)
  • 【跃迁之路】【641天】程序员高效学习方法论探索系列(实验阶段398-2018.11.14)...
  • 2019年如何成为全栈工程师?
  • java中的hashCode
  • jQuery(一)
  • react 代码优化(一) ——事件处理
  • 案例分享〡三拾众筹持续交付开发流程支撑创新业务
  • 聊聊directory traversal attack
  • 聊聊springcloud的EurekaClientAutoConfiguration
  • 罗辑思维在全链路压测方面的实践和工作笔记
  • 前端路由实现-history
  • 前嗅ForeSpider教程:创建模板
  • 使用 Node.js 的 nodemailer 模块发送邮件(支持 QQ、163 等、支持附件)
  • 使用putty远程连接linux
  • NLPIR智能语义技术让大数据挖掘更简单
  • ​Spring Boot 分片上传文件
  • #宝哥教你#查看jquery绑定的事件函数
  • (4.10~4.16)
  • (vue)页面文件上传获取:action地址
  • (带教程)商业版SEO关键词按天计费系统:关键词排名优化、代理服务、手机自适应及搭建教程
  • (更新)A股上市公司华证ESG评级得分稳健性校验ESG得分年均值中位数(2009-2023年.12)
  • (简单有案例)前端实现主题切换、动态换肤的两种简单方式
  • (剑指Offer)面试题41:和为s的连续正数序列
  • (论文阅读26/100)Weakly-supervised learning with convolutional neural networks
  • (算法)求1到1亿间的质数或素数
  • (转)平衡树
  • .NET Core6.0 MVC+layui+SqlSugar 简单增删改查
  • .net core使用RPC方式进行高效的HTTP服务访问
  • .net专家(张羿专栏)
  • .php结尾的域名,【php】php正则截取url中域名后的内容
  • .sys文件乱码_python vscode输出乱码
  • /dev下添加设备节点的方法步骤(通过device_create)
  • @ModelAttribute注解使用
  • @property括号内属性讲解
  • @SentinelResource详解
  • [ C++ ] STL_stack(栈)queue(队列)使用及其重要接口模拟实现
  • [ 转载 ] SharePoint 资料
  • [AI]ChatGPT4 与 ChatGPT3.5 区别有多大
  • [Ariticle] 厚黑之道 一 小狐狸听故事
  • [BZOJ1178][Apio2009]CONVENTION会议中心
  • [C#C++]类CLASS