1 判断回滚段竞争的sql

--当Ratio大于2时存在回滚段竞争,需要增加更多的回滚段)
select rn.name, rs.GETS, rs.WAITS, (rs.WAITS / rs.GETS) * 100 ratio
from v$rollstat rs, v$rollname rn
where rs.USN = rn.usn;

2 判断恢复日志竞争的sql

--immediate_contention或wait_contention的值大于1时存在竞争)
select name,
(t.IMMEDIATE_MISSES /
decode((t.IMMEDIATE_GETS t.IMMEDIATE_MISSES),0,-1,(t.IMMEDIATE_GETS t.IMMEDIATE_MISSES))) * 100 immediate_contention,
(t.MISSES / decode((t.GETS t.MISSES), 0, -1, (t.GETS t.MISSES))) * 100 wait_contention
from v$latch t
where name in ('redo copy', 'redo allocation');

3 判断表空间碎片

--(如果最大空闲空间占总空间很大比例则可能不存在碎片,如果比例较小,且有许多空闲空间,则可能碎片很多)
select t.tablespace_name,sum(t.bytes),max(t.bytes),count(*),
max(t.bytes) / sum(t.bytes) radio
from dba_free_space t
group by t.tablespace_name
order by t.tablespace_name;

4 确定命中排序域的次数

select t.NAME, t.VALUE from v$sysstat t where t.NAME like 'sort%';

5 确定当前sga的值

select * from v$sga;
select name,value/1024/1024 from v$sga;

6 查看高速缓冲区命中率

--(如果命中率低于70%,则应该加大init.ora参数中的DB_BLOCK_BUFFER的值)
select 1 - sum(decode(name, 'physical reads', value, 0)) /
(sum(decode(name, 'db block gets', value, 0)) *sum(decode(name, 'consistent gets', value, 0))) hit_ratio
from v$sysstat t
where name in ('physical reads', 'db block gets', 'consistent gets');--0.999999966992287

7 查看共享池命中率

--(如果ratio1大于1时,需要加大共享池,如果ratio2大于10%时,需要加大共享池SHARED_POOL_SIZE)
select sum(pins) pins,
sum(reloads) reloads,
(sum(reloads) / sum(pins)) * 100 ratio1
from v$librarycache; select sum(gets) gets,
sum(getmisses) getmisses,
(sum(getmisses) / sum(gets)) * 100 ratio2
from v$rowcache;

8 查看参数文件

select * from v$parameter;

9 查看数据库属性

select * from database_properties;
select * from v$version;

10 查看当前会话的sid,serial#

SELECT Sid, Serial# FROM V$session
WHERE Audsid = Sys_Context('USERENV', 'SESSIONID');

11 根据sid查询os的进程id

SELECT p.Spid "OS Thread", b.NAME "Name-User", s.Program, s.Sid, s.Serial#,s.Osuser, s.Machine
FROM V$process p, V$session s, V$bgprocess b
WHERE p.Addr = s.Paddr
AND p.Addr = b.Paddr And (s.sid=210 or p.spid=3)
UNION ALL
SELECT p.Spid "OS Thread", s.Username "Name-User", s.Program, s.Sid,s.Serial#, s.Osuser, s.Machine
FROM V$process p, V$session s
WHERE p.Addr = s.Paddr
And (s.sid=210 or p.spid=3)
AND s.Username IS NOT NULL;

12 根据sid查看正在运行的sql

SELECT /* PUSH_SUBQ */ Command_Type, Sql_Text, Sharable_Mem, Persistent_Mem, Runtime_Mem, Sorts,
Version_Count, Loaded_Versions, Open_Versions, Users_Opening, Executions,
Users_Executing, Loads, First_Load_Time, Invalidations, Parse_Calls,
Disk_Reads, Buffer_Gets, Rows_Processed, SYSDATE Start_Time,
SYSDATE Finish_Time, '>' || Address Sql_Address, 'N' Status
FROM V$sqlarea WHERE Address = (SELECT Sql_Address
FROM V$session WHERE Sid = 210 );

13 查看object为哪些进程所用

SELECT p.Spid, s.Sid, s.Serial# Serial_Num, s.Username User_Name,
a.TYPE Object_Type, s.Osuser Os_User_Name, a.Owner,a.OBJECT Object_Name,
Decode(Sign(48 - Command), 1, To_Char(Command), 'Action Code #' || To_Char(Command)) Action,
p.Program Oracle_Process, s.Terminal Terminal, s.Program Program,
s.Status Session_Status
FROM V$session s, V$access a, V$process p
WHERE s.Paddr = p.Addr
AND s.TYPE = 'USER'
AND a.Sid = s.Sid
AND a.OBJECT = '&obj'
ORDER BY s.Username, s.Osuser;

14 查看有那些用户连接

SELECT s.Osuser Os_User_Name,Decode(Sign(48 - Command),1,To_Char(Command),
'Action Code #' || To_Char(Command)) Action,
p.Program Oracle_Process, Status Session_Status, s.Terminal Terminal,
s.Program Program, s.Username User_Name,
s.Fixed_Table_Sequence Activity_Meter, '' Query, 0 Memory,
0 Max_Memory, 0 Cpu_Usage, s.Sid, s.Serial# Serial_Num
FROM V$session s, V$process p
WHERE s.Paddr = p.Addr
AND s.TYPE = 'USER'
ORDER BY s.Username, s.Osuser;

15 根据sid查看对应连接资源占用情况

SELECT n.NAME, v.VALUE, n.CLASS, n.Statistic# FROM V$statname n, V$sesstat v
WHERE v.Sid = 210
AND v.Statistic# = n.Statistic#
ORDER BY n.CLASS, n.Statistic#;

16 查看消耗资源的进程

SELECT s.Schemaname Schema_Name,Decode(Sign(48 - Command),
1, To_Char(Command), 'Action Code #' || To_Char(Command)) Action,Status Session_Status, s.Osuser Os_User_Name, s.Sid, p.Spid,s.Serial# Serial_Num, Nvl(s.Username, '[Oracle process]') User_Name,
s.Terminal Terminal, s.Program Program, St.VALUE Criteria_Value
FROM V$sesstat St, V$session s, V$process p
WHERE St.Sid = s.Sid
AND St.Statistic# = 38
AND ('ALL' = 'ALL' OR s.Status = 'ALL')
AND p.Addr = s.Paddr
ORDER BY St.VALUE DESC, p.Spid ASC, s.Username ASC, s.Osuser ASC;

17 查看锁情况

SELECT /* RULE */ Ls.Osuser Os_User_Name, Ls.Username User_Name,Decode(Ls.TYPE,
'RW', 'Row wait enqueue lock', 'TM', 'DML enqueue lock','TX', 'Transaction enqueue lock', 'UL', 'User supplied lock') Lock_Type,o.Object_Name OBJECT,Decode(Ls.Lmode,1, NULL, 2, 'Row Share', 3, 'Row Exclusive',
4, 'Share', 5, 'Share Row Exclusive', 6, 'Exclusive',NULL) Lock_Mode,o.Owner, Ls.Sid, Ls.Serial# Serial_Num, Ls.Id1, Ls.Id2 FROM Sys.Dba_Objects o,
(SELECT s.Osuser, s.Username, l.TYPE, l.Lmode, s.Sid, s.Serial#, l.Id1,l.Id2 FROM V$session s, V$lock l
WHERE s.Sid = l.Sid) Ls
WHERE o.Object_Id = Ls.Id1
AND o.Owner <> 'SYS'
ORDER BY o.Owner, o.Object_Name;

18 查看wait情况

SELECT Ws.CLASS, Ws.COUNT COUNT, SUM(Ss.VALUE) Sum_Value
FROM V$waitstat Ws, V$sysstat Ss
WHERE Ss.NAME IN ('db block gets', 'consistent gets')
GROUP BY Ws.CLASS, Ws.COUNT;

19 查看process/session状态

SELECT p.Pid, p.Spid, s.Program, s.Sid, s.Serial#
FROM V$process p, V$session s
WHERE s.Paddr = p.Addr;

20 谁阻塞了某个sesion(10g)

SELECT Sid, Username, Event, Blocking_Session, Seconds_In_Wait, Wait_Time
FROM V$session
WHERE State IN ('WAITING')
AND Wait_Class != 'Idle';

21 查看会话的阻塞

SELECT /* rule */ Lpad(' ', Decode(l.Xidusn, 0, 3, 0)) || l.Oracle_Username User_Name,
o.Owner, o.Object_Name, s.Sid, s.Serial#
FROM V$locked_Object l, Dba_Objects o, V$session s
WHERE l.Object_Id = o.Object_Id
AND l.Session_Id = s.Sid
ORDER BY o.Object_Id, Xidusn DESC; SELECT /* rule */ s.Username,Decode(l.TYPE, 'tm', 'table lock', 'tx', 'row lock', NULL) Lock_Level,
o.Owner, o.Object_Name, s.Sid, s.Serial#
FROM V$session s, V$lock l, Dba_Objects o
WHERE l.Sid = s.Sid
AND l.Id1 = o.Object_Id
AND s.Username IS NOT NULL;

22 查等待的事件及会话信息,求会话的等待及会话信息

SELECT Se.Sid, s.Username, Se.Event, Se.Total_Waits, Se.Time_Waited,Se.Average_Wait
FROM V$session s, V$session_Event Se
WHERE s.Username IS NOT NULL
AND Se.Sid = s.Sid
AND s.Status = 'ACTIVE'
AND Se.Event NOT LIKE '%SQL*Net%'
ORDER BY s.Username; SELECT s.Sid, s.Username, Sw.Event, Sw.Wait_Time, Sw.State,Sw.Seconds_In_Wait
FROM V$session s, V$session_Wait Sw
WHERE s.Username IS NOT NULL
AND Sw.Sid = s.Sid
AND Sw.Event NOT LIKE '%SQL*Net%'
ORDER BY s.Username;

23 查看会话等待的file_id/block_id

SELECT Sid, Event, P1text, P1, P2text, P2, P3text, P3
FROM V$session_Wait
WHERE Event NOT LIKE '%SQL%'
AND Event NOT LIKE '%rdbms%'
AND Event NOT LIKE '%mon%'
ORDER BY Event; SELECT NAME, Wait_Time
FROM V$latch l
WHERE EXISTS (SELECT 1
FROM (SELECT Sid, Event, P1text, P1, P2text, P2, P3text, P3
FROM V$session_Wait
WHERE Event NOT LIKE '%SQL%'
AND Event NOT LIKE '%rdbms%'
AND Event NOT LIKE '%mon%') x
WHERE x.P1 = l.Latch#);

24 查看会话等待的对象

SELECT Owner, Segment_Name, Segment_Type
FROM Dba_Extents
WHERE File_Id = &File_Id
AND &Block_Id BETWEEN Block_Id AND Block_Id Blocks - 1;

25 求出某个进程,并进行跟踪

SELECT s.Sid, s.Serial#
FROM V$session s, V$process p
WHERE s.Paddr = p.Addr
AND p.Spid = &1; Exec Dbms_System.Set_Sql_Trace_In_Session(&1, &2, TRUE);
Exec Dbms_System.Set_Sql_Trace_In_Session(&1, &2, FALSE);

26 求当前session的跟踪文件

SELECT P1.VALUE || '/' || P2.VALUE || '_ora_' || p.Spid || '.ora' Filename
FROM V$process p, V$session s, V$parameter P1, V$parameter P2
WHERE P1.NAME = 'user_dump_dest'
AND P2.NAME = 'instance_name'
AND p.Addr = s.Paddr
AND s.Audsid = Userenv('SESSIONID')
AND p.Background IS NULL
AND Instr(p.Program, 'CJQ') = 0;

求出锁定的对象

SELECT Do.Object_Name, Session_Id, Process, Locked_Mode
FROM V$locked_Object Lo, Dba_Objects Do
WHERE Lo.Object_Id = Do.Object_Id;

db_cache的建议

SELECT size_for_estimate, buffers_for_estimate, estd_physical_read_factor, estd_physical_reads
FROM V$DB_CACHE_ADVICE
WHERE name = 'DEFAULT'
AND block_size = (SELECT value FROM V$PARAMETER WHERE name = 'db_block_size')
AND advice_status = 'ON';

查看各项sga相关

select substr(name,1,10) name,substr(value,1,10) value
from v$parameter where name = 'log_buffer';
select * from v$sgastat ;
select * from v$sga;
show parameters area_size   #查看 各项区域内存参数, 其中sort_area为排序参数用

内存参数调整

数据缓冲区命中率
select value from v$sysstat where name ='physical reads';
select value from v$sysstat where name ='physical reads direct';
select value from v$sysstat where name ='physical reads direct (lob)';
select value from v$sysstat where name ='consistent gets';
select value from v$sysstat where name = 'db block gets';
这里命中率的计算应该是
令 x = physical reads direct physical reads direct (lob)
命中率 =100 - ( physical reads - x) / (consistent gets db block gets - x)*100
通常如果发现命中率低于90%,则应该调整应用可可以考虑是否增大数据缓冲区;
共享池的命中率
select sum(pinhits)/sum(pins)*100 "hit radio" from v$librarycache;
假如共享池的命中率低于95%,就要考虑调整应用(通常是没使用bind var )或者增加内存;
关于排序部分
select name,value from v$sysstat where name like '%sort%';
假如我们发现sorts (disk)/ (sorts (memory) sorts (disk))的比例过高,则通常意味着
sort_area_size 部分内存较小,可考虑调整相应的参数。
关于log_buffer
select name,value from v$sysstat
where name in('redo entries','redo buffer allocation retries');
假如 redo buffer allocation retries/ redo entries 的比例超过1%我们就可以考虑增大log_buffer

Oracle日常性能问题查看的更多相关文章

  1. Oracle日常性能查看

    判断回滚段竞争的SQL语句:(当Ratio大于2时存在回滚段竞争,需要增加更多的回滚段)select rn.name, rs.GETS, rs.WAITS, (rs.WAITS / rs.GETS) ...

  2. ORACLE日常操作手册

    转发自:http://blog.csdn.net/lichangzai/article/details/7955766 以前为开发人员编写的oracle基础操作手册,都基本的oracle操作和SQL语 ...

  3. oracle日常监控语句

    oracle常用的性能监控SQL语句 一.查询历史SQL: ---正在执行的SQL语句: select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT fro ...

  4. 关于Oracle的性能调整(一)

    Oracle Tuning的一些总结 关于Oracle的性能调整,一般包括两个方面,一是指Oracle数据库本身的调整,比如SGA.PGA的优化设置,二是连接Oracle的应用程序以及SQL语句的优化 ...

  5. Oracle 日常应用和操作笔记

    简单整理oracle日常应用笔记. 1.采用excel表格中的数据直接粘贴数据库记录中,默认会在后面加一个空格“”,操作完成后一定要记得对空格匹配然后修改一下. 2.查询数据库里的所有表结构, 采用s ...

  6. Oracle日志文件管理与查看

    Oracle日志文件管理与查看 from:http://hi.baidu.com/shuker/item/25ee611ee960c7426826bb1f 1.查询系统使用的是哪一组日志文件: sel ...

  7. SQLServer访问Oracle查询性能问题解决

    原文:SQLServer访问Oracle查询性能问题解决 1. 问题 系统有个模块,需要查询Oracle数据库中的数据.目前是通过建立链接服务器实现的. SQLServer访问Oracle实现 可参考 ...

  8. Oracle日常运维操作总结-数据库的启动和关闭

    下面是工作中对Oracle日常管理操作的一些总结,都是一些基本的oracle操作和SQL语句写法,在此梳理成手册,希望能帮助到初学者(如有梳理不准确之处,希望指出). 一.数据库的启动和关闭 1.1 ...

  9. Oracle ADDM性能诊断利器及报告解读

    性能优化是一个永恒的话题,性能优化也是最具有价值,最值得花费精力深入研究的一个课题,因为资源是有限的,时间是有限的.在Oracle数据库中,随着Oracle功能的不断强大和完善,Oralce数据库在性 ...

随机推荐

  1. .Net Core使用jexus配置https

    今天搞了一下怎么从http换成https,写一篇博客记录该过程.关于jexus的安装和使用请看我之前的一篇博客<Jexus部署Asp.Net Core项目>,唯一的不同是,将jexus升级 ...

  2. LightOJ - 1265 概率

    题意:有t头老虎,d头鹿,每天五种情况,虎虎,虎鹿,鹿鹿,鹿人,人虎,求生存的概率 题意:鹿就是来迷惑你的(结果我就陷进坑了),无论怎么选最后一定只剩下虎虎,虎人两种情况对结果有影响,那么如果有n只虎 ...

  3. JavaScript中的两个“0” -0和+0

    JavaScript中的两个“0”(翻译)   本文翻译自JavaScript’s two zeros JavaScript has two zeros: −0 and +0. This post e ...

  4. iOS自动化探索(二)WDA API的使用

    前面我们已经安装好了WebdriverAgent, 现在可以用Facebook官方提供的API来进行一些操作 WDA API官方页面: https://github.com/facebook/WebD ...

  5. SQLSERVER store procedure 临时表

    有些时候显示重复数据时,使用: ) 但有些时候表A过大或者逻辑复杂.显示数据时,会造成性能的影响,这时你就可以使用临时表:   ) create table #temp( XXX , XXX) )in ...

  6. python面向对象总结

    一 面向对象的程序设计的由来 见概述:http://www.cnblogs.com/linhaifeng/articles/6428835.html 二 什么是面向对象的程序设计及为什么要有它 面向过 ...

  7. L138

    Research indicates that lifestyles are changing fast.The essay isn't even remotely relevant to the t ...

  8. 第一次使用stackoverflow的寻求帮助

    最近在研究一项资料很少的技术--Drools,遇到一个很棘手的问题,搜遍所有网站,百度.谷歌都找不到解决方案.无奈之下,想起了stackoverflow这个技术问答网站.于是鼓足勇气,用蹩脚的英文在上 ...

  9. 你真的对java static了解吗,代码优化可能更加简单

    static修饰的成员变量和成员方法独立于该类的任何对象.也就是说,它不依赖类特定的实例,被类的所有实例共享. 只要这个类被加载,Java虚拟机就能根据类名在运行时数据区的方法区内定找到他们.因此,s ...

  10. LeNet-5网络结构及训练参数计算

    经典神经网络诞生记: 1.LeNet,1998年 2.AlexNet,2012年 3.ZF-net,2013年 4.GoogleNet,2014年 5.VGG,2014年 6.ResNet,201 ...