1. 监控事例的等待

select event,sum(decode(wait_Time,0,0,1)) "Prev", 
sum(decode(wait_Time,0,1,0)) "Curr",count(*) "Tot" 
from v$session_Wait 
group by event order by 4;

2. 回滚段的争用情况

select name, waits, gets, waits/gets "Ratio" 
from v$rollstat a, v$rollname b 
where a.usn = b.usn;

3. 监控表空间的 I/O 比例

select df.tablespace_name name,df.file_name "file",f.phyrds pyr, 
f.phyblkrd pbr,f.phywrts pyw, f.phyblkwrt pbw 
from v$filestat f, dba_data_files df 
where f.file# = df.file_id 
order by df.tablespace_name;

4. 监控文件系统的 I/O 比例

select substr(a.file#,1,2) "#", substr(a.name,1,30) "Name", 
a.status, a.bytes, b.phyrds, b.phywrts 
from v$datafile a, v$filestat b 
where a.file# = b.file#;

5.在某个用户下找所有的索引

select user_indexes.table_name, user_indexes.index_name,uniqueness, column_name 
from user_ind_columns, user_indexes 
where user_ind_columns.index_name = user_indexes.index_name 
and user_ind_columns.table_name = user_indexes.table_name 
order by user_indexes.table_type, user_indexes.table_name, 
user_indexes.index_name, column_position;

6. 监控 SGA 的命中率

select a.value + b.value "logical_reads", c.value "phys_reads", 
round(100 * ((a.value+b.value)-c.value) / (a.value+b.value)) "BUFFER HIT RATIO" 
from v$sysstat a, v$sysstat b, v$sysstat c 
where a.statistic# = 38 and b.statistic# = 39 
and c.statistic# = 40;

7. 监控 SGA 中字典缓冲区的命中率

select parameter, gets,Getmisses , getmisses/(gets+getmisses)*100 "miss ratio", 
(1-(sum(getmisses)/ (sum(gets)+sum(getmisses))))*100 "Hit ratio" 
from v$rowcache 
where gets+getmisses <>0 
group by parameter, gets, getmisses;

8. 监控 SGA 中共享缓存区的命中率,应该小于1%

select sum(pins) "Total Pins", sum(reloads) "Total Reloads", 
sum(reloads)/sum(pins) *100 libcache 
from v$librarycache;

select sum(pinhits-reloads)/sum(pins) "hit radio",sum(reloads)/sum(pins) "reload percent" 
from v$librarycache;

9. 显示所有数据库对象的类别和大小

select count(name) num_instances ,type ,sum(source_size) source_size , 
sum(parsed_size) parsed_size ,sum(code_size) code_size ,sum(error_size) error_size, 
sum(source_size) +sum(parsed_size) +sum(code_size) +sum(error_size) size_required 
from dba_object_size 
group by type order by 2;

10. 监控 SGA 中重做日志缓存区的命中率,应该小于1%

SELECT name, gets, misses, immediate_gets, immediate_misses, 
Decode(gets,0,0,misses/gets*100) ratio1, 
Decode(immediate_gets+immediate_misses,0,0, 
immediate_misses/(immediate_gets+immediate_misses)*100) ratio2 
FROM v$latch WHERE name IN ('redo allocation', 'redo copy');

11. 监控内存和硬盘的排序比率,最好使它小于 .10,增加 sort_area_size

SELECT name, value FROM v$sysstat WHERE name IN ('sorts (memory)', 'sorts (disk)');

12. 监控当前数据库谁在运行什么SQL语句

SELECT osuser, username, sql_text from v$session a, v$sqltext b 
where a.sql_address =b.address order by address, piece;

13. 监控字典缓冲区

SELECT (SUM(PINS - RELOADS)) / SUM(PINS) "LIB CACHE" FROM V$LIBRARYCACHE; 
SELECT (SUM(GETS - GETMISSES - USAGE - FIXED)) / SUM(GETS) "ROW CACHE" FROM V$ROWCACHE; 
SELECT SUM(PINS) "EXECUTIONS", SUM(RELOADS) "CACHE MISSES WHILE EXECUTING" FROM V$LIBRARYCACHE;

后者除以前者,此比率小于1%,接近0%为好。

SELECT SUM(GETS) "DICTIONARY GETS",SUM(GETMISSES) "DICTIONARY CACHE GET MISSES" 
FROM V$ROWCACHE

14. 找ORACLE字符集

select * from sys.props$ where name='NLS_CHARACTERSET';

15. 监控 MTS

select busy/(busy+idle) "shared servers busy" from v$dispatcher;

此值大于0.5时,参数需加大

select sum(wait)/sum(totalq) "dispatcher waits" from v$queue where type='dispatcher'; 
select count(*) from v$dispatcher; 
select servers_highwater from v$mts;

servers_highwater接近mts_max_servers时,参数需加大

16. 碎片程度

select tablespace_name,count(tablespace_name) from dba_free_space group by tablespace_name 
having count(tablespace_name)>10;

alter tablespace name coalesce; 
alter table name deallocate unused;

create or replace view ts_blocks_v as 
select tablespace_name,block_id,bytes,blocks,'free space' segment_name from dba_free_space 
union all 
select tablespace_name,block_id,bytes,blocks,segment_name from dba_extents;

select * from ts_blocks_v;

select tablespace_name,sum(bytes),max(bytes),count(block_id) from dba_free_space 
group by tablespace_name;

查看碎片程度高的表

SELECT segment_name table_name , COUNT(*) extents 
FROM dba_segments WHERE owner NOT IN ('SYS', 'SYSTEM') GROUP BY segment_name 
HAVING COUNT(*) = (SELECT MAX( COUNT(*) ) FROM dba_segments GROUP BY segment_name);

17. 表、索引的存储情况检查

select segment_name,sum(bytes) space,count(*) ext_quan from dba_extents where 
tablespace_name='&tablespace_name' and segment_type='TABLE' group by tablespace_name,segment_name;

select segment_name,count(*) from dba_extents where segment_type='INDEX' and owner='&owner' 
group by segment_name;

转载:http://www.vcmy.com/article/2006-3-21/194-1.htm

1. 检测数据库中的事件和等待

SELECT event, total_waits, total_timeouts,time_waited, average_wait

FROM v$system_event

2. 查询会话中的事件和等待时间

select sid, event, total_waits,average_wait

from v$session_event where sid=10;

3. 查询等待进程

SELECT sid, seq#, event, wait_time, state

FROM v$session_wait;

4. 监控全局区的性能

select * from v$sgastat;

5. 查询命中率

select gethitratio

from v$librarycache

where namespace = 'SQL AREA';

6. 当前 sql 语句

select sql_text, users_executing,

executions, loads

from v$sqlarea;

7. 查询高速缓存中的命中率

select sum(pins) "Executions", sum(reloads) "Cache Misses",

sum(reloads)/sum(pins)

from v$librarycache;

8. 查询全局字典中的有效装载次数

select namespace,pins,reloads,invalidations

from v$librarycache;

9. 回滚段的争用情况

select name, waits, gets, waits/gets "Ratio"

from v$rollstat a, v$rollname b

where a.usn = b.usn;

10. 监控表空间的 I/O 比例

select df.tablespace_name name,df.file_name "file",f.phyrds pyr,

f.phyblkrd pbr,f.phywrts pyw, f.phyblkwrt pbw

from v$filestat f, dba_data_files df

where f.file# = df.file_id

order by df.tablespace_name;

11. 监控文件系统的 I/O 比例

select substr(a.file#,1,2) "#", substr(a.name,1,30) "Name",

a.status, a.bytes, b.phyrds, b.phywrts

from v$datafile a, v$filestat b

where a.file# = b.file#;

12. 在某个用户下找所有的索引

select user_indexes.table_name, user_indexes.index_name,uniqueness, column_name

from user_ind_columns, user_indexes

where user_ind_columns.index_name = user_indexes.index_name

and user_ind_columns.table_name = user_indexes.table_name

order by user_indexes.table_type, user_indexes.table_name,

user_indexes.index_name, column_position;

13. 监控 SGA 中字典缓冲区的命中率

select parameter, gets,Getmisses , getmisses/(gets+getmisses)*100 "miss ratio",

(1-(sum(getmisses)/ (sum(gets)+sum(getmisses))))*100 "Hit ratio"

from v$rowcache

where gets+getmisses <>0

group by parameter, gets, getmisses;

14. 监控 SGA 中共享缓存区的命中率,应该小于 1%

select sum(pins) "Total Pins", sum(reloads) "Total Reloads",

sum(reloads)/sum(pins) *100 libcache

from v$librarycache;

select sum(pinhits-reloads)/sum(pins) "hit radio",sum(reloads)/sum(pins) "reload percent"

from v$librarycache;

15. 显示所有数据库对象的类别和大小

select count(name) num_instances ,type ,sum(source_size) source_size ,

sum(parsed_size) parsed_size ,sum(code_size) code_size ,sum(error_size) error_size,

sum(source_size) +sum(parsed_size) +sum(code_size) +sum(error_size) size_required

from dba_object_size

group by type order by 2;

16. 监控 SGA 中重做日志缓存区的命中率,应该小于 1%

select name, gets, misses, immediate_gets, immediate_misses,

Decode(gets,0,0,misses/gets*100) ratio1,

Decode(immediate_gets+immediate_misses,0,0,

immediate_misses/(immediate_gets+immediate_misses)*100) ratio2

FROM v$latch WHERE name IN ('redo allocation', 'redo copy');

17. 监控内存和硬盘的排序比率,最好使它小于 .10 ,增加 sort_area_size

SELECT name, value FROM v$sysstat WHERE name IN ('sorts (memory)', 'sorts (disk)');

18. 监控字典缓冲区

select (sum(pins - reloads)) / sum(pins) "lib cache" from v$librarycache;

select (sum(gets - getmisses - usage - fixed)) / sum(gets) "row cache" from v$rowcache;

select sum(pins) "executions", sum(reloads) "cache misses while executing" from v$librarycache;

后者除以前者 , 此比率小于 1%, 接近 0% 为好

select sum(gets) "dictionary gets",sum(getmisses) "dictionary cache get misses"

from v$rowcache

19. 找 ORACLE 字符集

select * from sys.props$ where name='NLS_CHARACTERSET';

20. 监控 MTS

select busy/(busy+idle) "shared servers busy" from v$dispatcher;

此值大于 0.5 时,参数需加大

select sum(wait)/sum(totalq) "dispatcher waits" from v$queue where type='dispatcher';

select count(*) from v$dispatcher;

select servers_highwater from v$mts;

servers_highwater 接近 mts_max_servers 时,参数需加大

21. 碎片程度

select tablespace_name,count(tablespace_name) from dba_free_space group by tablespace_name

having count(tablespace_name)>10;

alter tablespace name coalesce;

alter table name deallocate unused;

create or replace view ts_blocks_v as

select tablespace_name,block_id,bytes,blocks,'free space' segment_name from dba_free_space

union all

select tablespace_name,block_id,bytes,blocks,segment_name from dba_extents;

select * from ts_blocks_v;

select tablespace_name,sum(bytes),max(bytes),count(block_id) from dba_free_space

group by tablespace_name;

查看碎片程度高的表

SELECT segment_name table_name , COUNT(*) extents

FROM dba_segments WHERE owner NOT IN ('SYS', 'SYSTEM') GROUP BY segment_name

HAVING COUNT(*) = (SELECT MAX( COUNT(*) ) FROM dba_segments GROUP BY segment_name);

22. 表、索引的存储情况检查

select segment_name,sum(bytes),count(*) ext_quan from dba_extents where

tablespace_name='&tablespace_name' and segment_type='TABLE' group by tablespace_name,segment_name;

select segment_name,count(*) from dba_extents where segment_type='INDEX' and owner='&owner'

group by segment_name;

23 、找使用 CPU 多的用户 session

12 是 cpu used by this session

select a.sid,spid,status,substr(a.program,1,40) prog,a.terminal,oSUSEr,value/60/100 value

from v$session a,v$process b,v$sesstat c

where c.statistic#=12 and c.sid=a.sid and a.paddr=b.addr order by value desc;

Oracle性能监控脚本(sql)的更多相关文章

  1. Oracle管理监控之sql developer配置与简单使用

    1. 前提:使用sqldeveloper的前提是你的机器上安装了Oracle. 2. 刚打开sql developer 找到所安装的jdk的目录,本人安装的路径为:C:\Java\jdk1.6.0\b ...

  2. 如何查询Oracle性能监控

    1.监控等待事件select event,sum(decode(wait_time,0,0,1)) prev, sum(decode(wait_time,0,1,0)) curr,count(*)fr ...

  3. 性能测试-ORACLE性能监控

    通过lr做性能测试的过程,通过监控Oracle数据库的性能 采用的监控工具:PeOny PeOny安装 1. 安装服务端 1) LINUX平台安装 解压缩peony3.x.0.x.tar.gz文件,b ...

  4. Oracle性能优化之SQL语句

    1.SQL语句执行过程 1.1 SQL语句的执行步骤 1)语法分析,分析语句的语法是否符合规范,衡量语句中各表达式的意义. 2)语义分析,检查语句中涉及的所有数据库对象是否存在,且用户有相应的权限. ...

  5. ORACLE性能优化之SQL语句优化

    版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[+]   操作环境:AIX +11g+PLSQL 包含以下内容: 1.  SQL语句执行过程 2.  优化器及执行计划 3.  合 ...

  6. [主机/oracle/msyql] 监控脚本

    为了方便自己测试和监控,写了三个监控的脚本. 分别监控: 主机[cpu,mem,disk,fs,net] oracle mysql 脚本如下: hmon.py: monitor Linux os sy ...

  7. oracle性能监控

    https://blog.csdn.net/yangshangwei/article/details/52449489#监控事例的等待 https://blog.csdn.net/yangshangw ...

  8. Oracle 性能相关常用脚本(SQL)

    在缺乏的可视化工具来监控数据库性能的情形下,常用的脚本就派上用场了,下面提供几个关于Oracle性能相关的脚本供大家参考.以下脚本均在Oracle 10g测试通过,Oracle 11g可能要做相应调整 ...

  9. Oracle性能问题sql调优脚本集

    ---------------------------------------------------------------------------------------------------- ...

随机推荐

  1. C、C++中如何成功嵌入python

    修改lib文件名称,拷贝修改C:\Python27\libs目录下原来的python27.lib为python27_d.lib 包含头文件在C:\Python27\include目录下 包含lib文件 ...

  2. android 从Activity 获取 rootView 根节点

    private static View getRootView(Activity context) { return ((ViewGroup)context.findViewById(android. ...

  3. 【Spring实战】—— 6 内部Bean

    本篇文章讲解了Spring的通过内部Bean设置Bean的属性. 类似内部类,内部Bean与普通的Bean关联不同的是: 1 普通的Bean,在其他的Bean实例引用时,都引用同一个实例. 2 内部B ...

  4. C#创建COM组件供VB,PB,Delphi调用

    1  COM组件概述 COM是微软公司为了计算机工业的软件生产更加符合人类的行为方式开发的一种新的软件开发技术.在COM构架下,人们可以开发出各种各样的功能专一的组件,然后将它们按照需要组合起来,构成 ...

  5. sharepoint admin svc must be running in order to create deployment timer job 若要创建计时器作业,必须执行SVC

    sharepoint admin svc must be running in order to create deployment timer job 若要创建计时器作业.必须执行SVC       ...

  6. Windows 环境下分布式跨域Session共享

    为什么还是那句话,在网上找了N篇Session共享,但真正可以直接解决问题的还是没有找到. 一.以下为本人亲测,为防止环境不一致,对本文产生歧义,限定环境如下: 1. IIS7.0 2. Asp.ne ...

  7. timedelta

    from datetime import datetime start="09:35:23" end="10:23:00" start_dt = datetim ...

  8. Ubuntu11.04中如何将pycharm添加到系统的“应用程序”菜单里 (pycharm已成功安装)

    默认排序 Stu.zhouyc   21 人赞同了该回答 tools---->create desktop entry...不是很方便吗? 发布于 2016-04-09 21添加评论 分享 收藏 ...

  9. WCF基础教程——vs2013创建wcf应用程序

    引言   近期在项目中见到了师哥们常常谈到的WCF这方面的知识.当时在写程序的时候也没有理解wcf究竟是个什么东西? 以及我们为什么在项目中会採用这种框架来实现,仅仅是依照师哥他们写好的代码编写同样格 ...

  10. Javascript实现真实字符串剩余字数提示

    //文本框剩余字数提示(字符大小) function textLimitCheckSj(thisArea, maxLength, SpanId) { var str = thisArea.value; ...