您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Oracle操作Session的方法

2025/10/26 9:18:11发布16次查看
1.如何查看session级的等待事件? 当我们对数据库的性能进行调整时,一个最重要的参考指标就是系统等待事 件。$system_event,v$session_event,v$session_wait这三个视图里记录的就是系统级和session级的等待 事件,通过查询这些视图你可以发现数据库的一些操
1.如何查看session级的等待事件?当我们对数据库的性能进行调整时,一个最重要的参考指标就是系统等待事 件。$system_event,v$session_event,v$session_wait这三个视图里记录的就是系统级和session级的等待 事件,通过查询这些视图你可以发现数据库的一些操作到底在等待什么?是磁盘i/o,缓冲区忙,还是插锁等等。
通过如下sql你可以查询你的每个应用程序到底在等待什么,从而针对这些信息对数据库的性能进行调整。
select s.username,s.program,s.status,se.event,se.total_waits,se.total_timeouts,se.time_waited,se.average_wait
from v$session s, v$session_event se
where s.sid=se.sid and se.event not like 'sql*net%' and s.status ='active'and s.username is not null
2.oracle中查询被锁的表并释放session
select a.owner,a.object_name,b.xidusn,b.xidslot,b.xidsqn,b.session_id,b.oracle_username, b.os_user_name,b.process, b.locked_mode, c.machine,c.status,c.server,c.sid,c.serial#,c.program
from all_objects a,v$locked_object b,sys.gv_$session c
where ( a.object_id = b.object_id ) and (b.process = c.process ) order by 1,2
释放session sql:
alter system killsession 'sid,serial#'
alter system killsession '379,21132'
alter system killsession '374,6938'
3.查看占用系统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
4.找出耗cpu较多的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
5.查询session被锁的sql可以用一下语句
select sys.v_$session.osuser,sys.v_$session.machine,v$lock.sid,
sys.v_$session.serial#,
decode(v$lock.type,
'mr', 'media recovery',
'rt','redo thread',
'un','user name',
'tx', 'transaction',
'tm', 'dml',
'ul', 'pl/sql user lock',
'dx', 'distributed xaction',
'cf', 'control file',
'is', 'instance state',
'fs', 'file set',
'ir', 'instance recovery',
'st', 'disk space transaction',
'ts', 'temp segment',
'iv', 'library cache invalida-tion',
'ls', 'log start or switch',
'rw', 'row wait',
'sq', 'sequence number',
'te', 'extend table',
'tt', 'temp table',
'unknown') locktype,
rtrim(object_type) || ' ' || rtrim(owner) || '.' || object_name object_name,
decode(lmode, 0, 'none',
1, 'null',
2, 'row-s',
3, 'row-x',
4, 'share',
5, 's/row-x',
6, 'exclusive', 'unknown') lockmode,
decode(request, 0, 'none',
1, 'null',
2, 'row-s',
3, 'row-x',
4, 'share',
5, 's/row-x',
6, 'exclusive', 'unknown') requestmode,
ctime, block b
from v$lock, all_objects, sys.v_$session
where v$lock.sid > 6
and sys.v_$session.sid = v$lock.sid
and v$lock.id1 = all_objects.object_id;
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product