首页 / ORACLE / oracle日常监控语句
oracle日常监控语句
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了oracle日常监控语句,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含10937字,纯文字阅读大概需要16分钟。
内容图文
![oracle日常监控语句](/upload/InfoBanner/zyjiaocheng/490/9451d69410814e3ab9deffdd3a499990.jpg)
oracle常用的性能监控SQL语句
一、查询历史SQL:
---正在执行的SQL语句:
select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT
from v$session a, v$sqlarea b where a.sql_address = b.address;
---查询Oracle正在执行的sql语句及执行该语句的用户:
SELECT b.sid oracleID, b.username 登录Oracle用户名, b.serial#,
spid 操作系统ID, paddr, sql_text 正在执行的SQL, b.machine 计算机名
FROM v$process a, v$session b, v$sqlarea c
WHERE a.addr = b.paddr AND b.sql_hash_value = c.hash_value;
---查看正在执行sql的发起者的发放程序
SELECT OSUSER 电脑登录身份, PROGRAM 发起请求的程序, USERNAME 登录系统的用户名,
SCHEMANAME, B.Cpu_Time 花费cpu的时间, STATUS, B.SQL_TEXT 执行的sql
FROM V$SESSION A LEFT JOIN V$SQL B ON A.SQL_ADDRESS = B.ADDRESS AND A.SQL_HASH_VALUE = B.HASH_VALUE
ORDER BY b.cpu_time DESC;
****---执行过的SQL语句:
select b.SQL_TEXT,b.FIRST_LOAD_TIME,b.SQL_FULLTEXT
from v$sqlarea b where b.FIRST_LOAD_TIME between ‘2017-06-06/18:00:47‘ and ‘2017-06-06/20:00:47‘
order by b.FIRST_LOAD_TIME;
---查询最近执行过的 SQL语句:
select sql_text,last_load_time from v$sql order by last_load_time desc;
SELECT sql_text, last_load_time FROM v$sql WHERE last_load_time IS NOT NULL and sql_text like ‘select%‘ ORDER BY last_load_time DESC;
SELECT sql_text, last_load_time FROM v$sql WHERE last_load_time IS NOT NULL and sql_text like ‘update%‘ ORDER BY last_load_time DESC;
SELECT sql_text, last_load_time FROM v$sql WHERE last_load_time IS NOT NULL and last_load_time like‘ 14-06-09%‘ ORDER BY last_load_time DESC;
---查找前十条性能差的sql语句:
SELECT * FROM (select PARSING_USER_ID,EXECUTIONS,SORTS, COMMAND_TYPE,DISK_READS,sql_text
FROM v$sqlarea order BY disk_reads DESC )where ROWNUM<10 ;
---查看占io较大的正在运行的session:
SELECT se.sid,se.serial#,pr.SPID,se.username,se.status,
se.terminal,se.program,se.MODULE,se.sql_address,st.event,st.
p1text,si.physical_reads,
si.block_changes FROM v$session se,v$session_wait st,
v$sess_io si,v$process pr WHERE st.sid=se.sid AND st.
sid=si.sid AND se.PADDR=pr.ADDR AND se.sid>6 AND st.
wait_time=0 AND st.event NOT LIKE ‘%SQL%‘ ORDER BY physical_reads DESC;
――查看当前会话连接数
select count(*) from v$session;
--查看会话的详细信息
select sid,serial#,username,program,machine,status from v$session;
锁表查询SQL
SELECT object_name, machine, s.sid, s.serial#
FROM gv$locked_object l, dba_objects o, gv$session s
WHERE l.object_id = o.object_id
AND l.session_id = s.sid;
--释放SESSION SQL:
--alter system kill session ‘sid, serial#‘;
ALTER system kill session ‘23, 1647‘;
--查出oracle当前的被锁对象
SELECT l.session_id sid, s.serial#, l.locked_mode 锁模式, l.oracle_username 登录用户,
l.os_user_name 登录机器用户名, s.machine 机器名, s.terminal 终端用户名, o.object_name 被锁对象名,s.logon_time 登录数据库时间
FROM v$locked_object l, all_objects o, v$session s
WHERE l.object_id = o.object_id AND l.session_id = s.sid
ORDER BY sid, s.serial#;
--kill掉当前的锁对象可以为
alter system kill session ‘sid, s.serial#‘;
二、日常性能监控语句:
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;
18.监控USER
select distinct
p.spid unix_process,
s.terminal,
to_char(s.logon_time,‘YYYY/MON/DD HH24:MI‘) Logon_Time,
s.username
from v$process p, v$session s
where p.addr=s.paddr order by 2
19.生成tablespace使用状况的报表
select t.tablespace_name tb_name, d.tot_size/1024/1024 tot,
(d.tot_size - f.free_size)/1024/1024 used,
free_size/1024/1024 free,
f.max_free_extent/1024/1024 max_free_extent,
n.max_next_extent/1024/1024 max_next_extent,
round(free_size/tot_size * 100,0) pct
from dba_tablespaces t,
(select tablespace_name, sum(bytes) tot_size from dba_data_files
where status = ‘AVAILABLE‘
group by tablespace_name) d,
(select tablespace_name, sum(bytes) free_size, max(bytes) max_free_extent
from dba_free_space
group by tablespace_name ) f,
(select tablespace_name, max(next_extent) max_next_extent --assume pcs_increase=0
from dba_segments
group by tablespace_name ) n
where t.tablespace_name = d.tablespace_name
and d.tablespace_name = f.tablespace_name
and f.tablespace_name = n.tablespace_name
and status = ‘ONLINE‘
-- and d.tablespace_name like upper(‘1%‘)
order by 7,1
三、CPU及内存使用情况监控语句:
1.查看机器性能top 查出占用内存或CPU最多的几个PID号。 然后使用sys/oracle登陆数据库进行查看: 【检查占用内存SGA最高的SQL相关信息】
检查内存:
Select Server, Osuser, Name, Value / 1024 / 1024 Mb, s.Sql_Id, Spid, s.*
From V$session s, V$sesstat St, V$statname Sn, V$process p
Where St.Sid = s.Sid
And St.Statistic# = Sn.Statistic#
And Sn.Name Like ‘session pga memory‘
And p.Addr = s.Paddr
---下面spid就是服务器上的PID号,如果不添加下面这个and条件,查出所有的。
and p.spid=‘18988‘
Order By Value Desc;
检查CPU:
select p.pid pid,s.sid sid,p.spid spid,s.username username,s.osuser osname,p.serial# s_#,p.terminal,p.program program,
p.background,s.status,rtrim(substr(a.sql_text,1,80)) sql from v$process p,v$session s,v$sqlarea a where
p.addr=s.paddr and s.sql_address=a.address(+)
and p.spid like ‘3148‘;
2. 查看占用CPU最多的前10个SQL:
select * from (select sql_text,sql_id,cpu_time from v$sql order by cpu_time desc) where rownum<=10 order by rownum asc ;
select * from (select sql_text,sql_id,cpu_time from v$sqlarea order by cpu_time desc) where rownum<=10 order by rownum asc ;
这2个语句效果基本一样,一个从v$sql视图查询一个从v$sqlarea视图查询。
3.列出使用频率最高的5个查询:
select sql_text,executions
from (select sql_text,executions,
rank() over
(order by executions desc) exec_rank
from v$sql)
where exec_rank <=5;
4.消耗磁盘读取最多的sql top5:
select disk_reads,sql_text
from (select sql_text,disk_reads,
dense_rank() over
(order by disk_reads desc) disk_reads_rank
from v$sql)
where disk_reads_rank <=5;
5. 找出需要大量缓冲读取(逻辑读)操作的查询:
select buffer_gets,sql_text
from (select sql_text,buffer_gets,
dense_rank() over
(order by buffer_gets desc) buffer_gets_rank
from v$sql)
where buffer_gets_rank<=5;
oracle日常监控语句
标签:available union all ast decode reload code pre 文件系统 sql语句
本文系统来源:http://www.cnblogs.com/lxplwh/p/7406017.html
内容总结
以上是互联网集市为您收集整理的oracle日常监控语句全部内容,希望文章能够帮你解决oracle日常监控语句所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。