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 输入一串数字,去掉当中含7的和能被7整除的数

    C 输入一串数字,去掉当中含7的和能被7整除的数,每一个数小于10000,数字个数小于100 输入样例:1,7,56,77,87,2,45,42,97,9977 输出:1,2,45 注意:输入个数不确 ...

  2. 网络编程入坑基础-BIO总结

    IO总结 前提 参考资料: <Java I/O> -- 这本书没有翻译版,需要自己啃一下. <Java I/O>这本书主要介绍了IO和NIO的相关API使用,但是NIO部分并不 ...

  3. php读取ini(init)文件

    <?php header('content-type:text/html;charset=utf-8'); //读取.init文件 $config_file_path = './config/d ...

  4. ubuntu下运行第一个.net core web程序

    前置条件 ubuntu系统 且已经安装dotnetcore运行环境 mkdir  testMVC 创建一个文件夹 cd testMVC    进入文件夹 dotnet new -t web 创建程序( ...

  5. MQTT 学习笔记

    MQTT特点 MQTT协议是为大量计算能力有限,且工作在低带宽.不可靠的网络的远程传感器和控制设备通讯而设计的协议. 1.使用发布/订阅消息模式,提供一对多的消息发布,解除应用程序耦合 2.对负载内容 ...

  6. 使用intelliJ IDE开发java web项目

    <!-- spring版本号 --> <spring.version>4.3.0.RELEASE</spring.version> <!-- mybatis版 ...

  7. atitit.词法分析原理 词法分析器 (Lexer)

    atitit.词法分析原理 词法分析器 (Lexer) 1. 词法分析(英语:lexical analysis)1 2. :实现词法分析程序的常用途径:自动生成,手工生成.[1] 2 2.1. 词法分 ...

  8. atitit.提升研发效率的利器---重型框架与类库的区别与设计原则

    atitit.提升研发效率的利器---重型框架与类库的区别与设计原则 1. 框架的意义---设计的复用 1 1.1. 重型框架就是it界的重武器. 1 2. 框架 VS. 库 可视化图形化 1 2.1 ...

  9. Vivado Logic Analyzer的使用(一)

    本文基于Vivado 2014.2,通过一个简单的设计来讨论Vivado Logic Analyzer的功能. 在上一篇http://blog.chinaaet.com/detail/37242中,设 ...

  10. Objective-C中的类型转换

    转自:http://blog.csdn.net/lonelyroamer/article/details/7711920 类型转换 表2-3列出了简单数据类型.示例和格式符. 表2-3 简单数据类型. ...