我是靠谱客的博主 怡然世界,最近开发中收集的这篇文章主要介绍oracle查询耗资源的进程,常用Oracle进程资源查询语句(运维必看),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

(一)根据程序名称查找相关信息

select A.process,B.spid,A.sid,A.serial#,A.sql_address,A.username,A.program,A.status,A.machine,A.terminal,A.osuser

from v$session A, v$process B

--where A.program like '%'||UPPER('&&sBossServiceName')||'%'

where A.program like '%qam%'

-- and A.machine='e6900f1'

and A.paddr = B.addr

order by A.machine,A.sid;

(二)根据程序名称查找当前sql

select * from v$sqltext

where address in (

select A.sql_address

from v$session A, v$process B

--where A.program like '%'||UPPER('&&sBossServiceName')||'%'

where A.program like '%qam%'

-- and A.machine='e6900f1'

and A.paddr = B.addr)

order by address,piece;

--getsql.sql

--通过sid,获取session正在执行的sql语句

SELECT sql_text FROM v$sqltext

WHERE address = (select sql_address from v$session where sid = &sid)

ORDER BY piece;

-----------------------------------------

--pid2sid.sql

(三)通过操作系统的pid查找sid

select * from v$session

where paddr=(select addr from v$process where spid=&spid);

-----------------------------------------

select spid, osuser, s.program

from v$session s,v$process p

where s.paddr=p.addr and s.sid=1057

--sid2pid.sql

(四)通过sid查找spid

select * from v$process

where addr = (select paddr from v$session where sid = &sid);

--killedsessionaddr2pid.sql

--通过招出被kill的session的地址,查找出其对应的操作系统进程ID(spid)

select * from v$process

where addr in (

select p.addr from v$process p where pid <> 1

minus

select s.paddr from v$session s

);

(五)查看锁(lock)情况

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;

(六)查看等待(wait)情况

SELECT v$waitstat.class, v$waitstat.count count, SUM(v$sysstat.value) sum_value

FROM v$waitstat, v$sysstat WHERE v$sysstat.name IN ('db block gets',

'consistent gets') group by v$waitstat.class, v$waitstat.count

(七)查看表空间的名称及大小

select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size

from dba_tablespaces t, dba_data_files d

where t.tablespace_name = d.tablespace_name

group by t.tablespace_name;

(八)查看表空间物理文件的名称及大小

select tablespace_name, file_id, file_name,

round(bytes/(1024*1024),0) total_space

from dba_data_files

order by tablespace_name;

(九)查看回滚段名称及大小

select segment_name, tablespace_name, r.status,

(initial_extent/1024) InitialExtent,(next_extent/1024) NextExtent,

max_extents, v.curext CurExtent

From dba_rollback_segs r, v$rollstat v

Where r.segment_id = v.usn(+)

order by segment_name ;

(十)回滚段暂用进程

SELECT r.name 回滚段名,

s.sid,

s.serial#,

s.username 用户名,

s.status,

t.cr_get,

t.phy_io,

t.used_ublk,

t.noundo,

substr(s.program, 1, 78) 操作程序

FROM sys.v_$session s,sys.v_$transaction t,sys.v_$rollname r

WHERE t.addr = s.taddr and t.xidusn = r.usn

AND r.NAME ='UNDOTBS1'

ORDER BY used_ublk DESC

(十一)捕捉运行很久的SQL

select username,sid,opname,

round(sofar*100 / totalwork,0) || '%' as progress,

time_remaining,sql_text

from v$session_longops , v$sql

where time_remaining <> 0

and sql_address = address

and sql_hash_value = hash_value

(十二)耗资源的进程(top session)

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# = to_number('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

(十三)查看有哪些用户连接

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

最后

以上就是怡然世界为你收集整理的oracle查询耗资源的进程,常用Oracle进程资源查询语句(运维必看)的全部内容,希望文章能够帮你解决oracle查询耗资源的进程,常用Oracle进程资源查询语句(运维必看)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部